POST /api/v1/customers
Create Customers

Creates a new customer with the specified payment_details. Customer payment details are stored in a secure, PCI DSS-compliant way.

Once you have a customer, you may specify the customer's id instead of payment_details when creating a payment.

サンプル

  • cURL
  • Node.js
  • Ruby
curl -X POST https://komoju.com/api/v1/customers \
  -u sk_123456: \
  -d "email=test@example.com" \
  -d "metadata[order_id]=abcdefg" \
  -d "payment_details=tok_2igg25moy54uv0hubhauo1dhs" 
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({
  'email': 'test@example.com',
  'metadata[order_id]': 'abcdefg',
  'payment_details': 'tok_2igg25moy54uv0hubhauo1dhs'
});

var post_options = {
  host: 'komoju.com',
  port: '443',
  path: '/api/v1/customers',
  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/customers')
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 = {
  email: "test@example.com",
  metadata: {
    order_id: "abcdefg"
  },
  payment_details: "tok_2igg25moy54uv0hubhauo1dhs"
}

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

puts res.body
{
  "id": "3ia9knmuqcdvz0eu3tsx3op21",
  "resource": "customer",
  "email": "test@example.com",
  "source": {
    "type": "credit_card",
    "brand": "visa",
    "last_four_digits": "1111",
    "month": 1,
    "year": 2025
  },
  "metadata": {
    "order_id": "abcdefg"
  },
  "created_at": "2020-06-09T07:41:51Z"
}

パラメータ

名前 説明
payment_details
必須

A hash or token describing the payment method used to make the payment. This or customer must be present when creating a payment.

currency
任意

3 letter ISO currency code used to pay.

email
任意

Customer's email address.

metadata
任意

A set of key-value pairs.