A subscription object is always tied to a Customer. The subscription token is only unique within the customer scope, thus it is possible to reuse the same subscription token for different customers. For this reason, when you are handling individual subscriptions, you are always required to use the Customer resource.
A subscription can be created by a customer through the submission form. The subscription object can be cancelled through the API.
Name | Type | Description |
---|---|---|
token | string | The token is under the scope of a customer |
object | string | Will be "subscription" |
created | integer | |
plan | array | |
plan->period_amount | integer | |
plan->period_type | string | day, month or year |
plan->items | object | A list of items the subscription has |
plan->items>item_id | required | |
plan->items>item_description | required | |
plan->items>unit_amount | required | |
plan->items>currency | optional | |
plan->items>quantity | optional | |
plan->items>discount | optional | |
plan->currency | string | |
cycle_number | integer | |
period_start | integer | |
period_end | integer | |
next_charge | integer | |
status | string | |
customer | object | |
metadata | object |
{
"token": "50aaeccb73dd310010",
"object": "subscription",
"created": 1375217068,
"display_name": "Plus Plan",
"plan": {
"period_amount": 1,
"period_type": "month",
"amount": 7200,
"currency": "USD",
"discount": 0.0,
"item_id": 101
},
"cycle_number": 1,
"period_start": 1375217068,
"period_end": 1375217068,
"next_charge": 1375217068,
"status": "active",
"customer": "cu4321",
"metadata": {}
}
Returns a list of all subscriptions.
Name | Required | Description |
---|---|---|
count | optional | |
offset | optional | |
customer | optional |
$ curl https://secure.peakium.com/api/v1/subscriptions/?count=2 \
-u pk_gEVUPX6FwObZSgg3v0BjkVxmdzatPyV9:
{
"object": "list",
"count": 2,
"data": [
{
"token": "50aaeccb73dd310010",
"object": "subscription",
"created": 1375217068,
"display_name": "Plus Plan",
"plan": {
"period_amount": 1,
"period_type": "month",
"amount": 7200,
"currency": "USD",
"discount": 0.0,
"item_id": 101
},
"cycle_number": 1,
"period_start": 1375217068,
"period_end": 1375217068,
"next_charge": 1375217068,
"status": "active",
"customer": "cu4321",
"metadata": {}
},
{...}
]
}
Returns a list of all subscriptions for a specific customer.
Name | Required | Description |
---|---|---|
count | optional | |
offset | optional |
$ curl https://secure.peakium.com/api/v1/customers/cu4321/subscriptions/?count=2 \
-u pk_gEVUPX6FwObZSgg3v0BjkVxmdzatPyV9:
{
"object": "list",
"count": 2,
"data": [
{
"token": "50aaeccb73dd310010",
"object": "subscription",
"created": 1375217068,
"display_name": "Plus Plan",
"plan": {
"period_amount": 1,
"period_type": "month",
"amount": 7200,
"currency": "USD",
"discount": 0.0,
"item_id": 101
},
"cycle_number": 1,
"period_start": 1375217068,
"period_end": 1375217068,
"next_charge": 1375217068,
"status": "active",
"customer": "cu4321",
"metadata": {}
},
{...}
]
}
To retrieve a specific subscription resource, you need to use the Customer resource for the subscription in the URI.
$ curl https://secure.peakium.com/api/v1/customers/cu4321/subscriptions/50aaeccb73dd310010/ \
-u pk_gEVUPX6FwObZSgg3v0BjkVxmdzatPyV9:
{
"token": "50aaeccb73dd310010",
"object": "subscription",
"display_name": "Plus Plan",
"plan": {
"period_amount": 1,
"period_type": "month",
"amount": 7200,
"currency": "USD",
"discount": 0.0,
"item_id": 101
},
"cycle_number": 1,
"period_start": 1375217068,
"period_end": 1375217068,
"next_charge": 1375217068,
"status": "active",
"customer": "cu4321",
"metadata": {}
}
This will cancel an active subscription, and stop any future charges. A cancelled subscription cannot be reactivated.
You need to use the Customer resource for the subscription in the URI to cancel a subscription.
$ curl https://secure.peakium.com/api/v1/customers/cu4321/subscriptions/50aaeccb73dd310010/ \
-u pk_gEVUPX6FwObZSgg3v0BjkVxmdzatPyV9: \
-X DELETE
{
"token": "50aaeccb73dd310010",
"object": "subscription",
"created": 1375217068,
"display_name": "Plus Plan",
"plan": {
"period_amount": 1,
"period_type": "month",
"amount": 7200,
"currency": "USD",
"discount": 0.0,
"item_id": 101
},
"cycle_number": 1,
"period_start": 1375217068,
"period_end": 1375217068,
"next_charge": 1375217068,
"status": "cancelled",
"customer": "cu4321",
"metadata": {}
}