Saving Payment Information with the Hosted Page

Our Hosted Page is not limited to just creating payments. You can also use it to store payment information, either for a subscription, or for freely withdrawing money.

How to do it

There are 3 steps. 1. Make session, 2. Wait for webhook, then 3. Make payments.

For step 3, you can create subscriptions instead of payments if you'd like!

Step 1. Make session

Example request


curl -X POST https://komoju.com/api/v1/sessions \
  -u sk_12345: \
  -d "mode=customer" \
  -d "return_url=https://example.com" \
  -d "amount=1000" \ # This amount is not actually charged! Only displayed.
  -d "currency=JPY" \
  -d "line_items[][description]=Monthly Subscription" # description is recommended.

Response (abridged - a real session will have more fields)

{
  "id": "boc2hxvmyl497eekihyrwmmgm",
  "resource": "session",
  "mode": "customer",
  "session_url": "https://komoju.com/sessions/boc2hxvmyl497eekihyrwmmgm",
  "customer_id": "0k27xq9ld84yxu7swl3jmyr7k"
}

Similar to regular payment-mode sessions, please direct your customer to the session_url when you're ready to collect payment information.

Additionally, please save the customer_id in your database for later use.

Step 2. Wait for webhook

Listen for the customer.updated event.

Once you receive this webhook, it means you are ready to create payments!

Step 3. Make payments

The customer_id you saved in Step 1 can be used with the Create Payments API to pull money.


curl -X POST https://komoju.com/api/v1/payments \
  -u sk_12345: \
  -d "amount=1000" \
  -d "currency=JPY" \
  -d "customer=0k27xq9ld84yxu7swl3jmyr7k" \

As previously mentioned, you can use that customer_id to create subscriptions as well.