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

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

puts res.body
{
  "id": "1bv1aplpol3igsp9u9te9sgzu",
  "resource": "subscription",
  "status": "active",
  "amount": 2000,
  "currency": "JPY",
  "customer": {
    "id": 314,
    "uuid": "4vcs9yqq93fb5s611ebhyulaw",
    "merchant_id": 2696,
    "created_at": "2020-06-09T16:41:52.813+09:00",
    "updated_at": "2020-06-09T16:41:52.813+09:00",
    "email": "walkerward@gutkowski.info",
    "currency": null,
    "metadata": {
      "order_id": "abcdefg"
    }
  },
  "period": "monthly",
  "day": 9,
  "payment_details": {
    "type": "credit_card",
    "month": "01",
    "year": "2025",
    "email": "test@example.com"
  },
  "retry_count": 0,
  "retry_at": null,
  "next_capture_at": "2020-07-09T07:41:52Z",
  "created_at": "2020-06-09T07:41:52Z",
  "ended_at": null,
  "metadata": {
  },
  "payments": [
    "9sfa45byqsjswsbq0e6l24r73"
  ]
}

パラメータ

名前 説明
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.