Hosted Page Quick Reference

This page showcases some of the many ways you can use our Sessions API to create a secure and customized checkout page for your online store.

  1. Return URL and specific locale
  2. Simplest possible session
  3. Simple line item to describe product
  4. Many line items
  5. Specific payment type

Return URL and specific locale

In most real cases, you will want users to be navigated back to your website after completing their purchase. Additionally, you may also want to specify a locale. Please use return_url and default_locale for these cases.

  • cURL
  • Node.js
  • Ruby
curl -X POST https://komoju.com/api/v1/sessions \
  -u sk_123456: \
  -d "amount=1000" \
  -d "currency=JPY" \
  -d "return_url=https%3A%2F%2Fen.komoju.com" \
  -d "default_locale=ja" 
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': '1000',
  'currency': 'JPY',
  'return_url': 'https://en.komoju.com',
  'default_locale': 'ja'
});

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: "1000",
  currency: "JPY",
  return_url: "https://en.komoju.com",
  default_locale: "ja"
}

res = https.post(
  uri.path,
  body.to_json,
  headers
)

puts res.body
Screenshot Screenshot dark

Simplest possible session

If all you want is a simple invoice, the only fields you need are amount and currency.

  • cURL
  • Node.js
  • Ruby
curl -X POST https://komoju.com/api/v1/sessions \
  -u sk_123456: \
  -d "amount=1000" \
  -d "currency=JPY" 
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': '1000',
  'currency': 'JPY'
});

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: "1000",
  currency: "JPY"
}

res = https.post(
  uri.path,
  body.to_json,
  headers
)

puts res.body
Screenshot Screenshot dark

Simple line item to describe product

If you want to display some information on your session page, you can do so with a line_item. At a minimum, a line_item must have a description.

  • cURL
  • Node.js
  • Ruby
curl -X POST https://komoju.com/api/v1/sessions \
  -u sk_123456: \
  -d "amount=1000" \
  -d "currency=JPY" \
  -d "line_items[][description]=Product+from+my+store" 
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': '1000',
  'currency': 'JPY',
  'line_items[][description]': 'Product from my store'
});

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: "1000",
  currency: "JPY",
  line_items: [
    {
      description: "Product from my store"
    }
  ]
}

res = https.post(
  uri.path,
  body.to_json,
  headers
)

puts res.body
Screenshot Screenshot dark

Many line items

Here's a full example with many line items, including images. This style of session provides the most information to your customers, at the cost of a rather large session object. Note that we can omit the amount field and instead put amount values on each line item. KOMOJU will compute the total amount for you.

  • cURL
  • Node.js
  • Ruby
curl -X POST https://komoju.com/api/v1/sessions \
  -u sk_123456: \
  -d "currency=JPY" \
  -d "line_items[][description]=KOMOJU+Sticker" \
  -d "line_items[][amount]=100" \
  -d "line_items[][quantity]=20" \
  -d "line_items[][image]=https%3A%2F%2Fdegica-gateway.s3.ap-northeast-1.amazonaws.com%2Fshrine%2Fproduct%2F683e357403f8153ae21446bc952272ae.png" \
  -d "line_items[][description]=Paper+house" \
  -d "line_items[][amount]=5500" \
  -d "line_items[][quantity]=1" \
  -d "line_items[][image]=https%3A%2F%2Fassets-global.website-files.com%2F5f6150f33b59252524b800ff%2F5f7ebbe0326ff3092e08178a_Group%25202622.svg" \
  -d "line_items[][description]=Special+discount" \
  -d "line_items[][amount]=-2000" \
  -d "line_items[][quantity]=1" \
  -d "line_items[][image]=https%3A%2F%2Fwww.freeimages.com%2Fdownload%2Ffile%2F8a743b65b8796e536c5ca7b911f3d5f8%2F640x640" 
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({
  'currency': 'JPY',
  'line_items[][description]': 'KOMOJU Sticker',
  'line_items[][amount]': '100',
  'line_items[][quantity]': '20',
  'line_items[][image]': 'https://degica-gateway.s3.ap-northeast-1.amazonaws.com/shrine/product/683e357403f8153ae21446bc952272ae.png',
  'line_items[][description]': 'Paper house',
  'line_items[][amount]': '5500',
  'line_items[][quantity]': '1',
  'line_items[][image]': 'https://assets-global.website-files.com/5f6150f33b59252524b800ff/5f7ebbe0326ff3092e08178a_Group%202622.svg',
  'line_items[][description]': 'Special discount',
  'line_items[][amount]': '-2000',
  'line_items[][quantity]': '1',
  'line_items[][image]': 'https://www.freeimages.com/download/file/8a743b65b8796e536c5ca7b911f3d5f8/640x640'
});

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 = {
  currency: "JPY",
  line_items: [
    {
      description: "KOMOJU Sticker",
      amount: "100",
      quantity: "20",
      image: "https://degica-gateway.s3.ap-northeast-1.amazonaws.com/shrine/product/683e357403f8153ae21446bc952272ae.png"
    },
    {
      description: "Paper house",
      amount: "5500",
      quantity: "1",
      image: "https://assets-global.website-files.com/5f6150f33b59252524b800ff/5f7ebbe0326ff3092e08178a_Group%202622.svg"
    },
    {
      description: "Special discount",
      amount: "-2000",
      quantity: "1",
      image: "https://www.freeimages.com/download/file/8a743b65b8796e536c5ca7b911f3d5f8/640x640"
    }
  ]
}

res = https.post(
  uri.path,
  body.to_json,
  headers
)

puts res.body
Screenshot Screenshot dark

Specific payment type

If you specify a payment_types array with only one item, the SELECT PAYMENT METHOD screen will not be shown.

  • cURL
  • Node.js
  • Ruby
curl -X POST https://komoju.com/api/v1/sessions \
  -u sk_123456: \
  -d "amount=1000" \
  -d "currency=JPY" \
  -d "payment_types[]=credit_card" 
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': '1000',
  'currency': 'JPY',
  'payment_types[]': 'credit_card'
});

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: "1000",
  currency: "JPY",
  payment_types: [
    "credit_card"
  ]
}

res = https.post(
  uri.path,
  body.to_json,
  headers
)

puts res.body
Screenshot Screenshot dark