Sessions

>>>

Retrieves a Session given its ID.

Useful for checking on a session's status, or to inspect the resulting payment.

サンプル

  • cURL
  • Node.js
  • Ruby
curl -X GET https://komoju.com/api/v1/sessions/1kv31jmdp5zweqlr2l2odr8wv \
  -u sk_123456:
var https = require('https');
var secret_key = 'sk_123456'
var auth = 'Basic ' + Buffer.from(secret_key + ':').toString('base64');
var get_options = {
  host: 'komoju.com',
  port: '443',
  path: '/api/v1/sessions/1kv31jmdp5zweqlr2l2odr8wv',
  method: 'GET',
  headers: {
    'Authorization': auth
  }
};

var get_req = https.request(get_options, function(res) {
    res.setEncoding('utf8');
    res.on('data', function (chunk) {
        console.log(chunk);
    });
});

get_req.end();
require 'uri'
require 'net/https'
require 'json'
require 'base64'
require 'pp'
uri = URI.parse('https://komoju.com/api/v1/sessions/1kv31jmdp5zweqlr2l2odr8wv')
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}"
}

res = https.get(uri.path, headers)
puts res.body
{
  "id": "1kv31jmdp5zweqlr2l2odr8wv",
  "resource": "session",
  "mode": "payment",
  "payment": null,
  "session_url": "https://komoju.com/sessions/1kv31jmdp5zweqlr2l2odr8wv",
  "return_url": "https://example.com/done",
  "default_locale": "en",
  "payment_methods": [
    {
      "type": "bank_transfer"
    }
  ],
  "created_at": "2020-08-17T18:03:53.000+09:00",
  "cancelled_at": null,
  "completed_at": null,
  "status": "pending"
}
>>>

POST /api/v1/sessions
Create Sessions

Creates a session. Send your customers to the session_url to allow them to enter their payment information.

サンプル

  • cURL
  • Node.js
  • Ruby
curl -X POST https://komoju.com/api/v1/sessions \
  -u sk_123456: \
  -d "default_locale=ja" \
  -d "email=test@example.com" \
  -d "metadata[test]=value" \
  -d "amount=8888" \
  -d "currency=JPY" \
  -d "payment_data[external_order_num]=my_custom_order" \
  -d "payment_data[name]=John" \
  -d "payment_data[name_kana]=ジョン" \
  -d "payment_types[]=credit_card" \
  -d "payment_types[]=konbini" \
  -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({
  'default_locale': 'ja',
  'email': 'test@example.com',
  'metadata[test]': 'value',
  'amount': '8888',
  'currency': 'JPY',
  'payment_data[external_order_num]': 'my_custom_order',
  'payment_data[name]': 'John',
  'payment_data[name_kana]': 'ジョン',
  'payment_types[]': 'credit_card',
  'payment_types[]': 'konbini',
  '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 = {
  default_locale: "ja",
  email: "test@example.com",
  metadata: {
    test: "value"
  },
  amount: "8888",
  currency: "JPY",
  payment_data: {
    external_order_num: "my_custom_order",
    name: "John",
    name_kana: "ジョン"
  },
  payment_types: [
    "credit_card",
    "konbini"
  ],
  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"
}

パラメータ

名前 説明
return_url
必須
external_customer_id
必須

Your unique identifier for the customer. Required when mode is equal to 'customer'.

payment_data
必須*

An object with payment-specific fields, such as externalordernum, shippingaddress, and billingaddress.

mode
任意

Specifies what to do with the payment details. Can create a 'payment', or a 'customer' resource.

email
任意

The e-mail address of the customer.

expires_in_seconds
任意

Time in seconds until the session expires after being created. The default value and upper limit are 86,400 seconds (24 hours).

metadata
任意

Store arbitrary key-value pairs on the session object.

payment_types
任意

List of payment types the user can select from. If you leave this blank, it defaults to every supported payment type.

default_locale
任意

Sets language of instruction page for supported payment methods. Valid options are 'en', 'ja', and 'ko'.