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=8gq87e7uq52dm7mqio05bqqr1" \
  -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': '8gq87e7uq52dm7mqio05bqqr1',
  '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: "8gq87e7uq52dm7mqio05bqqr1",
  period: "monthly"
}

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

puts res.body
{
  "id": "4ska3xl8ny05m5m5dgqvgi69b",
  "resource": "subscription",
  "status": "active",
  "amount": 2000,
  "currency": "JPY",
  "customer": {
    "id": 11,
    "uuid": "8gq87e7uq52dm7mqio05bqqr1",
    "merchant_id": 115,
    "created_at": "2019-12-17T14:14:08.989+09:00",
    "updated_at": "2019-12-17T14:14:08.989+09:00",
    "email": "vernon@runolfoncorwin.name",
    "currency": null,
    "metadata": {
      "order_id": "abcdefg"
    }
  },
  "period": "monthly",
  "day": 17,
  "payment_details": {
    "type": "credit_card",
    "month": "01",
    "year": "2024",
    "email": "test@example.com"
  },
  "retry_count": 0,
  "retry_at": null,
  "next_capture_at": "2020-01-17T05:14:09Z",
  "created_at": "2019-12-17T05:14:09Z",
  "ended_at": null,
  "metadata": {
  },
  "payments": [
    "c99vnt5jrw01k39e8cnrxdwtp"
  ]
}

パラメータ

名前 説明
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": "0yyieo7jssb7qusxrbitb64lb",
      "resource": "subscription",
      "status": "pending",
      "amount": 1000,
      "currency": "JPY",
      "customer": {
        "id": 12,
        "uuid": "466k737mfyfsq0iyv4xe9f8cd",
        "merchant_id": 116,
        "created_at": "2019-12-17T14:14:09.267+09:00",
        "updated_at": "2019-12-17T14:14:09.267+09:00",
        "email": "clydecasper@brown.name",
        "currency": null,
        "metadata": {
          "order_id": "abcdefg"
        }
      },
      "period": "monthly",
      "day": 17,
      "payment_details": {
        "type": "credit_card",
        "month": "01",
        "year": "2024",
        "email": "test@example.com"
      },
      "retry_count": 0,
      "retry_at": null,
      "next_capture_at": null,
      "created_at": "2019-12-17T05:14:09Z",
      "ended_at": null,
      "metadata": {
      },
      "payments": [

      ]
    },
    {
      "id": "bjd39r9mlcyu3vpbj704p6ubu",
      "resource": "subscription",
      "status": "pending",
      "amount": 1000,
      "currency": "JPY",
      "customer": {
        "id": 12,
        "uuid": "466k737mfyfsq0iyv4xe9f8cd",
        "merchant_id": 116,
        "created_at": "2019-12-17T14:14:09.267+09:00",
        "updated_at": "2019-12-17T14:14:09.267+09:00",
        "email": "clydecasper@brown.name",
        "currency": null,
        "metadata": {
          "order_id": "abcdefg"
        }
      },
      "period": "monthly",
      "day": 17,
      "payment_details": {
        "type": "credit_card",
        "month": "01",
        "year": "2024",
        "email": "test@example.com"
      },
      "retry_count": 0,
      "retry_at": null,
      "next_capture_at": null,
      "created_at": "2019-12-17T05:14:09Z",
      "ended_at": null,
      "metadata": {
      },
      "payments": [

      ]
    },
    {
      "id": "3ac0sgpu78sihxqirmfjehn5j",
      "resource": "subscription",
      "status": "pending",
      "amount": 1000,
      "currency": "JPY",
      "customer": {
        "id": 12,
        "uuid": "466k737mfyfsq0iyv4xe9f8cd",
        "merchant_id": 116,
        "created_at": "2019-12-17T14:14:09.267+09:00",
        "updated_at": "2019-12-17T14:14:09.267+09:00",
        "email": "clydecasper@brown.name",
        "currency": null,
        "metadata": {
          "order_id": "abcdefg"
        }
      },
      "period": "monthly",
      "day": 17,
      "payment_details": {
        "type": "credit_card",
        "month": "01",
        "year": "2024",
        "email": "test@example.com"
      },
      "retry_count": 0,
      "retry_at": null,
      "next_capture_at": null,
      "created_at": "2019-12-17T05:14:09Z",
      "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/5cb76z7pvbmfzsxl8889z4neh \
  -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/5cb76z7pvbmfzsxl8889z4neh',
  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/5cb76z7pvbmfzsxl8889z4neh')
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": "5cb76z7pvbmfzsxl8889z4neh",
  "resource": "subscription",
  "status": "pending",
  "amount": 1000,
  "currency": "JPY",
  "customer": {
    "id": 10,
    "uuid": "f2c8w3nzqy6ec7ckykxu3l6ef",
    "merchant_id": 114,
    "created_at": "2019-12-17T14:14:08.818+09:00",
    "updated_at": "2019-12-17T14:14:08.818+09:00",
    "email": "dustinjaskolski@veumschaefer.info",
    "currency": null,
    "metadata": {
      "order_id": "abcdefg"
    }
  },
  "period": "monthly",
  "day": 17,
  "payment_details": {
    "type": "credit_card",
    "month": "01",
    "year": "2024",
    "email": "test@example.com"
  },
  "retry_count": 0,
  "retry_at": null,
  "next_capture_at": null,
  "created_at": "2019-12-17T05:14:08Z",
  "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/4ckrzo0q9uihancuc489yvzza \
  -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/4ckrzo0q9uihancuc489yvzza',
  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/4ckrzo0q9uihancuc489yvzza')
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": "4ckrzo0q9uihancuc489yvzza",
  "resource": "subscription",
  "status": "deleted",
  "amount": 1000,
  "currency": "JPY",
  "customer": {
    "id": 9,
    "uuid": "7u1b0pwgw5dffkpbo2nt1xtso",
    "merchant_id": 113,
    "created_at": "2019-12-17T14:14:08.695+09:00",
    "updated_at": "2019-12-17T14:14:08.695+09:00",
    "email": "candidaleannon@kovacektoy.com",
    "currency": null,
    "metadata": {
      "order_id": "abcdefg"
    }
  },
  "period": "monthly",
  "day": 17,
  "payment_details": {
    "type": "credit_card",
    "month": "01",
    "year": "2024",
    "email": "test@example.com"
  },
  "retry_count": 0,
  "retry_at": null,
  "next_capture_at": null,
  "created_at": "2019-12-17T05:14:08Z",
  "ended_at": "2019-12-17T05:14:08Z",
  "metadata": {
  },
  "payments": [

  ]
}