Bill a Customer Every Month
This tutorial takes you from an enabled account to a working monthly subscription: you create it, the payer pays the invoice Fluxis emails them, and your server learns about it by webhook. The concepts behind each step are in Subscriptions.
Subscriptions are in alpha, and your account must be enabled by Fluxis first. Without that, POST /v1/subscriptions answers 403.
Once your account is enabled, Subscriptions (Alpha) also appears in the dashboard sidebar. There you can create an email-invoiced subscription, list them by status or point of sale, search by customer email, open one to see its billing history and copy the payment link of an open invoice, and cancel it. This tutorial uses the API; each step says where the dashboard can do the same.
Before you start
You need:
- API credentials for the account, or for its organization. See API Credentials.
- A point of sale on that account whose
payment_optionsinclude the token you want to bill in. - A public HTTPS endpoint for webhooks. During development, ngrok or similar works.
The examples use the staging API, https://api.stgfluxis.us. In production, use https://api.fluxis.us.
Staging watches the real networks, so paying an invoice there moves real funds. Test with small amounts, such as 1 USDT.
1. Get a token
Code
The token is in data.token. Send it on every call below, together with your API key:
Code
2. Pick the point of sale and the token
List your points of sale and note the id of the one to bill from, and one of its payment_options:
Code
The token you bill in is a unique asset id, such as npolygon_t0xc2132D05D31c914a87C6611C10748AEb04B58e8F for USDT on Polygon. The payer can still pay with any other token the point of sale accepts, converted at the current rate.
3. Make sure a webhook is registered
Fluxis tells you about paid invoices, cancellations and expiries through the enabled webhooks on the subscription's account whose event types include subscription. If the account already has one, skip this step.
Otherwise, create one in the dashboard under Developers → Webhooks with the Subscriptions event, or register it via the API:
Code
Store the secret from the response now. It is shown only once, and you need it to verify every delivery.
A webhook receives only the event types it lists. To get payment notices on the same endpoint too, list both: ["payment_request", "subscription"]. See Webhooks.
4. Create the subscription
Code
Code
Save id against your customer. The subscription is pending until the first invoice is paid.
The payer receives the first invoice by email within a few minutes. To skip the wait, send them to invoice_url from your own page. If invoice_url is missing, the first invoice could not be opened yet; Fluxis retries within a minute and emails it, so you do not need to do anything.
Always send "collection_method": "email_invoice". A request without it is read as a wallet subscription, which needs a partner wallet, and is refused if it carries a payer_email.
In the dashboard, Subscriptions → New subscription creates the same email-invoiced subscription and sends the first invoice right away.
5. Handle the webhook
When the payer pays, your endpoint receives:
Code
A minimal handler in Node.js:
Code
- Verify the signature first. See Webhook Signature Verification for
verifyWebhookSignature. - Deduplicate on
payment_request_id. It identifies the invoice, and the same notice can be sent twice. - Fluxis makes one delivery attempt and does not retry. If your endpoint was down, read the subscription (step 6) or check
GET /v1/account/{accountID}/webhook/logs. - When billing stops, you receive
subscription_cancelledorsubscription_expiredinstead. See When a subscription ends.
6. Read and list
Read one subscription to check where it stands:
Code
List them, optionally by status or point of sale:
Code
In the dashboard, Subscriptions lists them with the same filters and a search by customer email; open one to see its billing history.
A cancellation for non-payment arrives as subscription_cancelled (step 5). A periodic read catches a notice your endpoint missed.
7. Cancel
When the customer asks to stop:
Code
The response is the subscription, now cancelled with cancellation_reason: "merchant_cancelled". Any invoice still awaiting payment is closed, and the payer is emailed that you cancelled. A second cancel answers 409.
In the dashboard, open the subscription and choose Cancel subscription.
Testing the full cycle
To see a second invoice without waiting a month, create a test subscription with "interval": "day". The second invoice opens one day after the first is paid.
Troubleshooting
| Symptom | What to check |
|---|---|
403 on create | The account is not enabled for subscriptions yet, or the credential does not reach the point of sale's account. |
400 "asset is not one this point of sale accepts" | Add the token to the point of sale's payment_options, or bill in one it already has. |
400 "payer_email is not accepted…" | collection_method is missing. Send email_invoice. |
| The payer did not get the email | Ask them to check spam, or send them invoice_url yourself. |
| The checkout says the payment expired | The payer chose a token and did not pay before the checkout closed. A fresh invoice is emailed automatically. |
| No webhook arrived | Check that the account has an enabled webhook whose event types include subscription, and your endpoint answered 200 in time: GET /v1/account/{accountID}/webhook/logs. |
If you are stuck, contact Fluxis with the subscription id.