Sessions
A session represents a single transaction that a customer can complete using a payment method of their choosing.
To create a Session, there are only 3 required parameters:
amount
How much you are charging your customercurrency
Currency in which you are charging your customerreturn_url
URL to send the customer when they are done with the session- When the customer completes their session,
?action=complete
is appended - When the customer cancels their session,
?action=cancel
is appended
- When the customer completes their session,
- cURL
- Node.js
- Ruby
curl -X POST https://komoju.com/api/v1/sessions \
-u sk_123456: \
-d "amount=8888" \
-d "currency=JPY" \
-d "return_url=https://example.com"
var querystring = require('querystring');
var https = require('https');
var secret_key = 'sk_123456'
var auth = 'Basic ' + Buffer.from(secret_key + ':').toString('base64');
var post_data = querystring.stringify({
'amount': '8888',
'currency': 'JPY',
'return_url': 'https://example.com'
});
var post_options = {
host: 'komoju.com',
port: '443',
path: '/api/v1/sessions',
method: 'POST',
headers: {
'Authorization': auth,
'Content-Length': Buffer.byteLength(post_data)
}
};
var post_req = https.request(post_options, function(res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
console.log(chunk);
});
});
post_req.write(post_data);
post_req.end();
require 'uri'
require 'net/https'
require 'json'
require 'base64'
require 'pp'
uri = URI.parse('https://komoju.com/api/v1/sessions')
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
secret_key = 'sk_123456'
auth = Base64.encode64("#{secret_key}:")
headers = {
'Content-Type' => 'application/json',
'Authorization' => "Basic #{auth}"
}
body = {
amount: "8888",
currency: "JPY",
return_url: "https://example.com"
}
res = https.post(
uri.path,
body.to_json,
headers
)
puts res.body
{
"id": "e9x5mvx3jkpkofzcg7umfael6",
"resource": "session",
"mode": "payment",
"amount": 8888,
"currency": "JPY",
"payment": null,
"session_url": "https://komoju.com/sessions/e9x5mvx3jkpkofzcg7umfael6",
"return_url": "https://example.com",
"default_locale": "ja",
"payment_methods": [
{
"type": "credit_card"
},
{
"type": "konbini",
"brands": {
"seven-eleven": "/images/konbini/seven-eleven.svg",
"lawson": "/images/konbini/lawson.svg",
"family-mart": "/images/konbini/family-mart.svg",
"ministop": "/images/konbini/ministop.svg",
"daily-yamazaki": "/images/konbini/daily-yamazaki.svg",
"seicomart": "/images/konbini/seicomart.svg"
}
}
],
"created_at": "2020-08-17T18:03:53.000+09:00",
"cancelled_at": null,
"completed_at": null,
"status": "pending"
}
There's a lot going on in that session object, but for most cases you only need to worry about the session_url
attribute. Send your customer to the session_url
, and they'll be provided a secure form for entering their preferred payment details.
Sessions are very flexible. For example, you can limit the number of payment methods available for a session by passing payment_types
, and you can retrieve information about a completed or abandoned session's progress by inspecting the status
and payment
attributes. See the sessions API reference for more.
Session Resource
Field | Description |
---|---|
id |
string |
resource |
string Value of session . |
mode |
string Value of payment or customer . |
amount |
translation missing: en.serializers.sessions.amount |
currency |
translation missing: en.serializers.sessions.currency |
payment |
hash The Payment object created by this Session. A completed session of type payment will always have an authorized or captured payment. |
session_url |
string URL that the customer must visit in order to securely input payment information. |
return_url |
string URL that the customer will be sent after filling out the form in session_url - will be appended with ?action=complete or ?action=cancel depending on the outcome. |
default_locale |
string Sets the default locale of the webpage pointed to by session_url . |
payment_methods |
array Payment methods the customer may choose from. |
created_at |
timestamp An ISO 8601 formatted timestamp of when the session was created. |
cancelled_at |
timestamp An ISO 8601 formatted timestamp of when the session was cancelled (or nil if it has not been cancelled). |
completed_at |
timestamp An ISO 8601 formatted timestamp of when the session was completed (or nil if it has not been completed). |
status |
string The session's status - can be used to gauge the customer's progress (pending , cancelled , or completed ). |
Payment Resource
The Payment is the heart of KOMOJU. A payment represents a transfer of funds from a customer to you, the merchant. This object will appear on your session when it transfers to 'complete'.
Field | Description |
---|---|
id |
string |
resource |
string Value of payment |
status |
string The status of the payment |
amount |
integer The amount to be charged before tax. Must be equal or greater than 0, without thousands separator. The amount cannot be a decimal value. For example, for an amount of 10 and currency of EUR, the payment will be 0.10 EUR. |
customer |
string The ID of the customer the payment was created with. |
payment_deadline |
timestamp Time when the payment will expire. This is a timestamp in ISO 8601 format: YYYY-MM-DDTHH:MM:SSZ. |
payment_details |
hash or token Describes the payment method used to make the payment |
payment_method_fee |
integer An additional fee added to specific payment types |
total |
integer The payment total, this is the amount + tax + paymentmethodfee |
currency |
string 3 letter ISO currency code of the transaction |
description |
string Description of the payment (used in e-mail receipts if enabled). |
captured_at |
timestamp An ISO 8601 formatted timestamp of when a payment was captured |
external_order_num |
string This is the merchant unique ID for the transaction. It will be included in all callbacks to identify the transaction. |
metadata |
hash A set of key-value pairs |
created_at |
timestamp An ISO 8601 formatted timestamp of when a payment was created |
amount_refunded |
integer The amount in cents refunded |
locale |
string Sets the language to use for e-mail receipts and payment instructions |
refunds |
hash Refund information |
refund_requests |
hash Refund request information |