Integration Guide: Payment
How to accept payments with the KOMOJU Hosted Page
Creating payments with our hosted page is simple and never requires PCI-DSS compliance on your part.
The flow goes something like this:
- Your server creates a Session, specifying a
return_url
- Your app redirects your customer to the Session's
session_url
- Once payment is completed or aborted, customer is sent to your
return_url
with asession_id
query param appended - Your server uses the
session_id
query param to determine payment status
💴
Create payment session (minimal)
Open Recipe
Code example
Here is example server code for using the KOMOJU Hosted Page to accept payments.
import fetch from 'node-fetch'
import express from 'express'
const app = express()
const secretKey = 'PASTE YOUR SECRET KEY HERE'
/*
* When your customer is ready to pay, create a session and redirect to the session URL.
*/
app.get('/', async (req, res) => {
const session = await fetch('https://komoju.com/api/v1/sessions', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Basic ${btoa(secretKey + ':')}`,
},
body: JSON.stringify({
amount: 1000,
currency: 'JPY',
return_url: req.protocol + '://' + req.get('host') + '/return',
})
}).then(r => r.json())
console.log(session)
res.redirect(session.session_url)
})
/*
* When the customer is done, they will be redirected to the return URL you specified above.
*/
app.get('/return', async (req, res) => {
const sessionID = req.query['session_id']
const session = await fetch(`https://komoju.com/api/v1/sessions/${sessionID}`, {
method: 'GET',
headers: {
'Authorization': `Basic ${btoa(secretKey + ':')}`,
},
}).then(r => r.json())
console.log(session)
if (session.status === 'completed') {
res.send('Thanks! Your payment is ' + session.payment.status)
} else {
res.send("Sorry! You must've had trouble paying.")
}
})
app.listen(3000, () => console.log('Listening on port 3000'))
One-Click Payment for Returning Customers
If your website or app has a user login feature, you can allow your users to save payment information for later with minimal integration effort.
If you want to use this feature, all you have to do is add an external_customer_id
to your Session creation request:
🙋♂️
Create payment session with One-Click
Open Recipe
Updated 5 months ago
What’s Next