Customers

>>>
List customers

サンプル

  • cURL
  • Node.js
  • Ruby
curl -X GET https://komoju.com/api/v1/customers \
  -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/customers',
  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/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}"
}

res = https.get(uri.path, headers)
puts res.body
{
  "resource": "list",
  "total": 3,
  "page": 1,
  "per_page": 10,
  "last_page": 1,
  "data": [
    {
      "id": "dejj1yw8sg9zim5lme67bfzoc",
      "resource": "customer",
      "email": "kallie@beatty.net",
      "source": null,
      "metadata": {
        "order_id": "abcdefg"
      },
      "created_at": "2018-11-13T06:20:21Z"
    },
    {
      "id": "9muf0fdpzkmtk8f5zxrgy84j7",
      "resource": "customer",
      "email": "francebarton@lemkeprohaska.net",
      "source": null,
      "metadata": {
        "order_id": "abcdefg"
      },
      "created_at": "2018-11-13T06:20:21Z"
    },
    {
      "id": "65ba4ibdjw8wzmj4iyyhlvfqu",
      "resource": "customer",
      "email": "jesusahackett@ritchie.name",
      "source": null,
      "metadata": {
        "order_id": "abcdefg"
      },
      "created_at": "2018-11-13T06:20:21Z"
    }
  ]
}
>>>
Show a customer

サンプル

  • cURL
  • Node.js
  • Ruby
curl -X GET https://komoju.com/api/v1/customers/a790tjviahrpcsz561912k7az \
  -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/customers/a790tjviahrpcsz561912k7az',
  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/customers/a790tjviahrpcsz561912k7az')
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": "a790tjviahrpcsz561912k7az",
  "resource": "customer",
  "email": "eldon@dare.co",
  "source": null,
  "metadata": {
    "order_id": "abcdefg"
  },
  "created_at": "2018-11-13T06:20:21Z"
}
>>>

POST /api/v1/customers
Create a customer

Create a customer

サンプル

  • 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_38e6c5838b91e5d4e3771431b275f6de29fb3822e3471db31d682fb09d27b398cbvlxyj1jhhmcso2e3xytrmkr" 
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_38e6c5838b91e5d4e3771431b275f6de29fb3822e3471db31d682fb09d27b398cbvlxyj1jhhmcso2e3xytrmkr'
});

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_38e6c5838b91e5d4e3771431b275f6de29fb3822e3471db31d682fb09d27b398cbvlxyj1jhhmcso2e3xytrmkr"
}

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

puts res.body
{
  "id": "82xjd1dmxmwp775ddfjzqww04",
  "resource": "customer",
  "email": "test@example.com",
  "source": {
    "type": "credit_card",
    "brand": "visa",
    "last_four_digits": "1111",
    "month": 1,
    "year": 2023
  },
  "metadata": {
    "order_id": "abcdefg"
  },
  "created_at": "2018-11-13T06:20:21Z"
}

パラメータ

名前 説明
payment_details
必須
A hash or token describing the payment method used to make the payment.
currency
任意
3 letter ISO currency code of the transaction
email
任意
Customer's email address.
metadata
任意
A set of key-value pairs
>>>
Update customers

サンプル

  • cURL
  • Node.js
  • Ruby
curl -X PATCH https://komoju.com/api/v1/customers/6yk4lnmluxa1qt6bkdgojeunz \
  -u sk_123456: \
  -d "payment_details=tok_840321a7a54204f7ddf2f11325f75fc82d7fe5d34febd8c43b915e3de1717f799uqdec0fhs2hp1y9jijetqe2m" 
var querystring = require('querystring');
var https = require('https');
var secret_key = 'sk_123456'
var auth = 'Basic ' + Buffer.from(secret_key + ':').toString('base64');
var patch_data = querystring.stringify({
  'payment_details': 'tok_840321a7a54204f7ddf2f11325f75fc82d7fe5d34febd8c43b915e3de1717f799uqdec0fhs2hp1y9jijetqe2m'
});

var patch_options = {
  host: 'komoju.com',
  port: '443',
  path: '/api/v1/customers/6yk4lnmluxa1qt6bkdgojeunz',
  method: 'PATCH',
  headers: {
    'Authorization': auth,
    'Content-Length': Buffer.byteLength(patch_data)
  }
};

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

patch_req.write(patch_data);
patch_req.end();
require 'uri'
require 'net/https'
require 'json'
require 'base64'
require 'pp'
uri = URI.parse('https://komoju.com/api/v1/customers/6yk4lnmluxa1qt6bkdgojeunz')
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 = {
  payment_details: "tok_840321a7a54204f7ddf2f11325f75fc82d7fe5d34febd8c43b915e3de1717f799uqdec0fhs2hp1y9jijetqe2m"
}

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

puts res.body
{
  "id": "6yk4lnmluxa1qt6bkdgojeunz",
  "resource": "customer",
  "email": "valentine@pfeffer.net",
  "source": {
    "type": "credit_card",
    "brand": "visa",
    "last_four_digits": "1111",
    "month": 1,
    "year": 2023
  },
  "metadata": {
    "order_id": "abcdefg"
  },
  "created_at": "2018-11-13T06:20:21Z"
}

パラメータ

名前 説明
currency
任意
3 letter ISO currency code of the transaction
payment_details
任意
A hash or token describing the payment method used to make the payment.
email
任意
Customer's email address.
metadata
任意
A set of key-value pairs
>>>
Destroy a customer

サンプル

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

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

delete_req.end();
require 'uri'
require 'net/https'
require 'json'
require 'base64'
require 'pp'
uri = URI.parse('https://komoju.com/api/v1/customers/539haasgxj1dztcfn8j1c1lf4')
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.delete(uri.path, '{}', headers)
puts res.body
{
  "id": "539haasgxj1dztcfn8j1c1lf4",
  "resource": "customer",
  "email": "chadsporer@kuhnledner.com",
  "source": null,
  "metadata": {
    "order_id": "abcdefg"
  },
  "created_at": "2018-11-13T06:20:21Z"
}