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 "external_customer_id=my custom customer" \
  -d "metadata[test]=value" \
  -d "payment_data[amount]=8888.0" \
  -d "payment_data[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',
  'external_customer_id': 'my custom customer',
  'metadata[test]': 'value',
  'payment_data[amount]': '8888.0',
  'payment_data[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",
  external_customer_id: "my custom customer",
  metadata: {
    test: "value"
  },
  payment_data: {
    amount: "8888.0",
    currency: "JPY",
    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",
  "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 at least the keys amount and currency. Required when mode is equal to 'payment'.

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.

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'.