Subscriptions

>>>

POST /api/v1/subscriptions
Create Subscriptions

Create a new subscription. A subscription represents a recurring payment. Recurring payments may be on a weekly, monthly, or yearly basis, specified by the period parameter.

In order to create a subscription, a customer ID must be supplied. The customer object contains saved payment info, which is regularly charged by the subscription.

A subscription can't be modified once it's created. To change a subscription, you must delete it, and create a new one.

サンプル

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

var post_options = {
  host: 'komoju.com',
  port: '443',
  path: '/api/v1/subscriptions',
  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/subscriptions')
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: "2000",
  currency: "JPY",
  customer: "38erd3xrn2kfr61649jwmv772",
  period: "monthly"
}

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

puts res.body
{
  "id": "bsxz89dcnests5b4y7tb2gs63",
  "resource": "subscription",
  "status": "active",
  "amount": 2000,
  "currency": "JPY",
  "customer": {
    "id": 1,
    "uuid": "38erd3xrn2kfr61649jwmv772",
    "merchant_id": 35,
    "created_at": "2018-11-13T15:20:21.291+09:00",
    "updated_at": "2018-11-13T15:20:21.291+09:00",
    "email": "terica@erdman.co",
    "currency": null,
    "metadata": {
      "order_id": "abcdefg"
    }
  },
  "period": "monthly",
  "day": 13,
  "payment_details": {
    "type": "credit_card",
    "month": "01",
    "year": "2023",
    "given_name": "Taro",
    "family_name": "Yamada",
    "email": "test@example.com"
  },
  "retry_count": 0,
  "retry_at": null,
  "next_capture_at": "2018-12-13T06:20:21Z",
  "created_at": "2018-11-13T06:20:21Z",
  "ended_at": null,
  "metadata": {
  },
  "payments": [
    "duca3fk7v7b5tyroqcpbs460b"
  ]
}

パラメータ

名前 説明
customer
必須

The ID of an existing customer in which to provide payment details for the payment. This or payment_details must be present.

amount
必須

The amount to be charged before tax. Must be equal or greater than 0. Use a ‘.’ as a decimal separator, and no thousands separator.

currency
必須

3 letter ISO currency code used to pay.

period
必須

Interval for subscription payments: weekly, monthly, or yearly

metadata
任意

A set of key-value pairs.

>>>

GET /api/v1/subscriptions
List Subscriptions

List existing subscriptions. Paginates with the usual page, per_page, start_time, and end_time parameters.

サンプル

  • cURL
  • Node.js
  • Ruby
curl -X GET https://komoju.com/api/v1/subscriptions \
  -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/subscriptions',
  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/subscriptions')
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": "ddg9o4e0j9uqjtxmphaxgdqm8",
      "resource": "subscription",
      "status": "pending",
      "amount": 1000,
      "currency": "JPY",
      "customer": {
        "id": 4,
        "uuid": "20hk4iklgxrsief0yb9emahwc",
        "merchant_id": 38,
        "created_at": "2018-11-13T15:20:21.291+09:00",
        "updated_at": "2018-11-13T15:20:21.291+09:00",
        "email": "adrianbauch@gorczany.biz",
        "currency": null,
        "metadata": {
          "order_id": "abcdefg"
        }
      },
      "period": "monthly",
      "day": 13,
      "payment_details": {
        "type": "credit_card",
        "month": "01",
        "year": "2023",
        "given_name": "Taro",
        "family_name": "Yamada",
        "email": "test@example.com"
      },
      "retry_count": 0,
      "retry_at": null,
      "next_capture_at": null,
      "created_at": "2018-11-13T06:20:21Z",
      "ended_at": null,
      "metadata": {
      },
      "payments": [

      ]
    },
    {
      "id": "5jd5hf1hjvhu1qijdqwwwsy3f",
      "resource": "subscription",
      "status": "pending",
      "amount": 1000,
      "currency": "JPY",
      "customer": {
        "id": 4,
        "uuid": "20hk4iklgxrsief0yb9emahwc",
        "merchant_id": 38,
        "created_at": "2018-11-13T15:20:21.291+09:00",
        "updated_at": "2018-11-13T15:20:21.291+09:00",
        "email": "adrianbauch@gorczany.biz",
        "currency": null,
        "metadata": {
          "order_id": "abcdefg"
        }
      },
      "period": "monthly",
      "day": 13,
      "payment_details": {
        "type": "credit_card",
        "month": "01",
        "year": "2023",
        "given_name": "Taro",
        "family_name": "Yamada",
        "email": "test@example.com"
      },
      "retry_count": 0,
      "retry_at": null,
      "next_capture_at": null,
      "created_at": "2018-11-13T06:20:21Z",
      "ended_at": null,
      "metadata": {
      },
      "payments": [

      ]
    },
    {
      "id": "0t3c5o2q3u4bprt1fapnr4vab",
      "resource": "subscription",
      "status": "pending",
      "amount": 1000,
      "currency": "JPY",
      "customer": {
        "id": 4,
        "uuid": "20hk4iklgxrsief0yb9emahwc",
        "merchant_id": 38,
        "created_at": "2018-11-13T15:20:21.291+09:00",
        "updated_at": "2018-11-13T15:20:21.291+09:00",
        "email": "adrianbauch@gorczany.biz",
        "currency": null,
        "metadata": {
          "order_id": "abcdefg"
        }
      },
      "period": "monthly",
      "day": 13,
      "payment_details": {
        "type": "credit_card",
        "month": "01",
        "year": "2023",
        "given_name": "Taro",
        "family_name": "Yamada",
        "email": "test@example.com"
      },
      "retry_count": 0,
      "retry_at": null,
      "next_capture_at": null,
      "created_at": "2018-11-13T06:20:21Z",
      "ended_at": null,
      "metadata": {
      },
      "payments": [

      ]
    }
  ]
}

パラメータ

名前 説明
start_time
任意

Query for records created after this time.

end_time
任意

Query for records created before this time.

per_page
任意

How many complete objects per page.

page
任意

Page number to query for.

>>>

Show an existing subscription, including its customer and scrubbed payment details.

サンプル

  • cURL
  • Node.js
  • Ruby
curl -X GET https://komoju.com/api/v1/subscriptions/77sudjgv2f82b5pclgtg2c7i7 \
  -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/subscriptions/77sudjgv2f82b5pclgtg2c7i7',
  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/subscriptions/77sudjgv2f82b5pclgtg2c7i7')
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": "77sudjgv2f82b5pclgtg2c7i7",
  "resource": "subscription",
  "status": "pending",
  "amount": 1000,
  "currency": "JPY",
  "customer": {
    "id": 3,
    "uuid": "chpky09wc7gt4vqqhyel7vm62",
    "merchant_id": 37,
    "created_at": "2018-11-13T15:20:21.291+09:00",
    "updated_at": "2018-11-13T15:20:21.291+09:00",
    "email": "eilenejast@bruen.io",
    "currency": null,
    "metadata": {
      "order_id": "abcdefg"
    }
  },
  "period": "monthly",
  "day": 13,
  "payment_details": {
    "type": "credit_card",
    "month": "01",
    "year": "2023",
    "given_name": "Taro",
    "family_name": "Yamada",
    "email": "test@example.com"
  },
  "retry_count": 0,
  "retry_at": null,
  "next_capture_at": null,
  "created_at": "2018-11-13T06:20:21Z",
  "ended_at": null,
  "metadata": {
  },
  "payments": [

  ]
}
>>>

Delete a subscription. Once deleted, the subscription's regular payments will stop.

サンプル

  • cURL
  • Node.js
  • Ruby
curl -X DELETE https://komoju.com/api/v1/subscriptions/8rf6wsqdpbaau7c079888t6c8 \
  -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/subscriptions/8rf6wsqdpbaau7c079888t6c8',
  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/subscriptions/8rf6wsqdpbaau7c079888t6c8')
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": "8rf6wsqdpbaau7c079888t6c8",
  "resource": "subscription",
  "status": "deleted",
  "amount": 1000,
  "currency": "JPY",
  "customer": {
    "id": 2,
    "uuid": "daxd1p28f6lqwvhn44vjx48m7",
    "merchant_id": 36,
    "created_at": "2018-11-13T15:20:21.291+09:00",
    "updated_at": "2018-11-13T15:20:21.291+09:00",
    "email": "leannmacejkovic@hilpert.io",
    "currency": null,
    "metadata": {
      "order_id": "abcdefg"
    }
  },
  "period": "monthly",
  "day": 13,
  "payment_details": {
    "type": "credit_card",
    "month": "01",
    "year": "2023",
    "given_name": "Taro",
    "family_name": "Yamada",
    "email": "test@example.com"
  },
  "retry_count": 0,
  "retry_at": null,
  "next_capture_at": null,
  "created_at": "2018-11-13T06:20:21Z",
  "ended_at": "2018-11-13T06:20:21Z",
  "metadata": {
  },
  "payments": [

  ]
}