comecerodocs

Buy prepaid credit

POST
/customers/{customer_id}/credit_purchases

Makes an open invoice with one "Prepaid credit" line of amount, in the plan's currency, for the customer to pay through the normal invoice payment page. Once it is paid the credit is added to the subscription's usage plan, once whatever repeats. The credit is the line's price before tax, at most amount: where prices include tax, it is less than the total paid. The invoice says how much in credit_purchase.credit_granted (and in its line's meta). The first purchase makes the plan's credit and pays its meters from it. A refund or chargeback of the invoice takes back its share of the credit, as far as it is unused. Your shop must sell credit (usage_customer_settings on /settings/subscription). A shopper's token buys only for its own customer (me works, and needs a customer's login). Here customer_id is the Comecero customer id, not your own id. Send an Idempotency-Key header so a retry after a timeout never makes a second invoice: the same key with the same body answers the first invoice (200) for a day. A plan may have at most 20 unpaid credit invoices at once.

Authorization

headerAuthorizationBearer <token>

A secret, trusted or limited token. See Authentication.

Path Parameters

customer_id*string

The Comecero customer id, or me.

Header Parameters

Idempotency-Key?string

Makes a retry harmless: the same request again with the same key (after a timeout, say) changes nothing more and answers as the first one did. 1 to 128 printable ASCII characters, sent once (400, reference UbV150); an empty header counts as none. Use a new random key, such as a UUID, for each change you mean to make. The same key with another body is refused (409, reference UbV151).

Match^[ -~]{0,128}$
Lengthlength <= 128

Request Body

application/json
  1. body
subscription_id*string

The customer's subscription whose plan the credit is for (subscription_id of a customer_usage). At most 100 characters.

Length1 <= length <= 100
amount*string

The credit to buy, as a decimal string above 0 in the plan's currency, no finer than the currency allows ("20", "12.50"). It must be from the larger of the smallest sale and the shop's min to the shop's max, and at most 1000000000, with at most 6 decimal places (zeros after them are fine).

Match^(?=[^1-9]*[1-9])(?:0*[0-9]{0,9}(?:\.[0-9]{0,6}0*)?|0*1000000000(?:\.0*)?)$

Response Body

A retry: this Idempotency-Key already made an invoice for the same subscription and amount, and this is that invoice as it is now (it may be paid by then). Nothing new is made.

application/json
  1. response

A bill you send to a customer, who pays it from a link. A new invoice is a draft (draft: true): you can change it freely and the customer cannot see it. Publishing it (draft: false) fires invoice:published and, unless you ask otherwise, emails the customer a payment link. When the invoice is paid in full it closes (open: false) and becomes an order with the same id. Money fields are in the invoice currency unless the field name starts with settlement_.

object?"invoice"

The object type. Always invoice.

Value in"invoice"
url?string

The full URL of this invoice.

Formaturi
date_created?string

When the invoice was created.

Formatdate-time
date_modified?string

When the invoice was last changed.

Formatdate-time
date_due?|

When payment is due. Required before the invoice can be published.

Formatdate-time
past_due?boolean

True when date_due has passed and the invoice is still unpaid, scheduled, pending, failed or waiting for a retry.

invoice_id?string

The invoice id. It is also the order_id of the order the invoice becomes when paid.

test?boolean

True for a test invoice.

account_id?string

The account the invoice belongs to.

order_id?string

The id the order will have once the invoice is paid. Same as invoice_id.

open?boolean

True while the invoice can still be changed or paid. It turns false when the invoice is paid in full.

payment_status?string

Where payment stands. unpaid: nothing paid yet. scheduled: Comecero will charge the customer's saved payment method automatically (autopay_at). processing or pending: a payment is under way. completed: paid in full. failed or retry: the last automatic payment failed. cancelled and refunded follow the order.

Value in"unpaid""scheduled""processing""pending""completed""failed""retry""cancelled""refunded"
currency?string

The currency the customer pays in, a three-letter ISO 4217 code.

subtotal?number

The sum of the item subtotals after item discounts.

subtotal_original?number

The sum of the item subtotals before discounts.

shipping?number

Shipping after discounts.

shipping_original?number

Shipping before discounts.

discount?number

The discount on the whole invoice, apart from item discounts.

item_discounts?number

The sum of all item discounts.

total_discounts?number

discount plus item_discounts.

total_discounts_percent?number

The total discount as a fraction of the original total.

tax?number

Tax after discounts.

tax_original?number

Tax before discounts.

total?number

The amount the customer pays.

total_original?number

subtotal_original plus shipping_original plus tax_original.

tax_inclusive?boolean

True when item prices already include tax.

total_payments?number

The amount paid so far.

total_remaining?number

total minus total_payments: what is still to pay.

discount_on_gross?boolean

True when discounts are taken from the tax-inclusive price.

autopay?boolean

True when the invoice is to be charged automatically to the customer's saved payment method on the due date, once it is published.

for_subscription_proration?boolean

True when Comecero made this invoice for a mid-term subscription change.

autopay_at?|

When the automatic payment will run. Null when the invoice is not scheduled for automatic payment.

Formatdate-time
settlement_currency?string

The currency you are paid out in. This and the other settlement_ fields are not returned to limited tokens.

settlement_subtotal?number

subtotal in the settlement currency.

settlement_subtotal_original?number

subtotal_original in the settlement currency.

settlement_shipping?number

shipping in the settlement currency.

settlement_shipping_original?number

shipping_original in the settlement currency.

settlement_discount?number

discount in the settlement currency.

settlement_item_discounts?number

item_discounts in the settlement currency.

settlement_total_discounts?number

total_discounts in the settlement currency.

settlement_tax?number

tax in the settlement currency.

settlement_tax_original?number

tax_original in the settlement currency.

settlement_total?number

total in the settlement currency.

customer_ip_address?|

The customer's IP address, when known.

customer_ip_country?|

The country of customer_ip_address, a two-letter ISO 3166 code.

referrer?|

Where the sale came from, as you set it.

affiliate_id?|

The affiliate credited with the sale, as you set it.

promotion_code?|

The coupon code applied to the invoice.

items_count?integer

The number of items.

items_quantity?number

The sum of the item quantities.

draft?boolean

True while the invoice is a draft. A draft cannot be paid and limited tokens cannot see it. Once published, an invoice cannot go back to draft.

items?array<>

The items on the invoice.

shipping_item?|

The shipping line, or null when the invoice has no shipping.

customer?|

The customer the invoice is for, or null when none is set yet. Before an invoice is published, the customer must have every field your payment settings require.

order?||

Once the invoice is closed and paid, a link to its order, or the order itself when you expand order. Null while the invoice is open. Left out when the token may not read orders.

payments?|

A link to the invoice's payments, or the list of payments when you expand payments on a single invoice. Left out when the token may not read payments.

subscription?||

For a subscription renewal invoice, a link to the subscription, or the subscription itself when you expand subscription. Null otherwise. Left out when the token may not read subscriptions.

credit_purchase?

On an invoice for prepaid credit, one a customer opened (POST /customers/{customer_id}/credit_purchases) or an automatic top-up's: what it buys. The credit is added once the invoice is paid. Such an invoice is never changed (422, UbV152; 409, UbV165 for a top-up's). Left out on other invoices.

subscription_date_period_start?|

For a renewal invoice, the start of the billing period it covers. Left out when the token may not read subscriptions.

Formatdate-time
subscription_date_period_end?|

For a renewal invoice, the end of the billing period it covers. Left out when the token may not read subscriptions.

Formatdate-time
promotions?|

A link to the promotions applied to the invoice, or the list when you expand promotions on a single invoice.

options?|

A link to the payment options for the invoice, or the options themselves when you expand options on a single invoice.

meta?|

Your own data for this invoice, up to 2,048 characters as JSON.

formatted?

Only when you send formatted=true. The money and date fields above as display text in the customer's language.

Example Request
curl -X POST 'https://api.comecero.com/api/v1/customers/string/credit_purchases' \  -H 'Idempotency-Key: 3f2b6c1e-9d4a-4e8b-a1f7-5c0d2e9b8a64' \  -H 'Content-Type: application/json' \  -d '{  "subscription_id": "SB0123456789",  "amount": "25"}'
Example Response
{  "object": "invoice",  "url": "https://api.comecero.com/api/v1/invoices/4827-KTPMW-640",  "invoice_id": "4827-KTPMW-640",  "date_created": "2026-11-15T12:00:00Z",  "date_modified": "2026-11-15T12:00:00Z",  "currency": "USD",  "subtotal": 25,  "total": 25,  "total_remaining": 25,  "open": true,  "draft": false,  "items": [    {      "object": "invoice_item",      "item_id": "1",      "invoice_id": "4827-KTPMW-640",      "name": "Prepaid credit",      "quantity": 1,      "currency": "USD",      "price": 25,      "total": 25,      "meta": {        "credit_granted": "25"      }    }  ],  "subscription": null,  "credit_purchase": {    "subscription_id": "SB0123456789",    "amount": "25",    "credit_granted": "25",    "source": "manual"  }}