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:

  1. Your server creates a Session, specifying a return_url
  2. Your app redirects your customer to the Session's session_url
  3. Once payment is completed or aborted, customer is sent to your return_url with a session_id query param appended
  4. Your server uses the session_id query param to determine payment status

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.

Screenshot of KOMOJU Hosted Page with One-Click enabled. There is a stylized image of a credit card representing the customer's previously used card.

If you want to use this feature, all you have to do is add an external_customer_id to your Session creation request: