Skip to content

Recurring payments (card storage and tokens) ​

With recurring payments the customer registers their card during the first payment. SimplePay then issues tokens: each token can be used for one later charge without the customer (MIT – merchant initiated transaction).

Prerequisite

Recurring payments must be enabled for your merchant account by SimplePay. Otherwise SimplePay answers with an error code (for example 5044, see Error codes).

1. Card registration ​

startRecurringPayment works like startPayment, with two extra fields: customer and recurring.

ts
import { startRecurringPayment, toISO8601DateString } from 'simplepay-js-sdk'

const sixMonths = new Date(Date.now() + 182 * 24 * 60 * 60 * 1000)

const response = await startRecurringPayment({
  orderRef: 'sub-2026-0001',
  total: 4990,
  currency: 'HUF',
  customerEmail: '[email protected]',
  customer: 'Test Customer',         // customer's name
  recurring: {
    times: 6,                        // number of tokens = number of later charges
    until: toISO8601DateString(sixMonths), // tokens are valid until this date
    maxAmount: 10000,                // maximum amount of one charge
  },
  invoice: { name: 'Test Customer', country: 'HU', state: 'Budapest', city: 'Budapest', zip: '1111', address: 'Fő utca 1.' },
})

// response.paymentUrl – redirect the customer here
// response.tokens     – save these for the customer
await saveTokens(customerId, response.tokens, response.transactionId)

Differences from startPayment:

  • Card (CARD) only; the method field is ignored.
  • The second (config) argument is the same as for startPayment: redirectUrl or urls. startTokenPayment also accepts a { redirectUrl } config.
  • The request sends threeDSReqAuthMethod: '02' (registered user) by default. Set the threeDSReqAuthMethod field to send '01' (guest) or '05' (registered with a third-party identifier) instead.
  • The other startPayment order fields (items, delivery, timeout, maySelect* and so on) work here too.
  • If a recurring field is falsy (0, ''), the SDK uses a default: times: 3, until: about 180 days from now, maxAmount: 12000. The type marks all three fields as required.

The response (SimplePayRecurringResponse) contains the usual fields plus a tokens: string[] array.

Tokens are your responsibility

You must store the tokens securely (per customer, together with the registration transactionId). The SDK stores nothing.

2. Back URL and IPN ​

Same endpoints as one-time payments: back URL and IPN. The card registration IPN has two extra fields:

  • cardMask: the masked card number, for example xxxx-xxxx-xxxx-1234
  • expiry: the card's expiry, for example 2028-12-31T00:00:00+01:00

Save them so the customer can see which card is registered.

3. Charging a token ​

When the next charge is due (for example in a daily cron job), call startTokenPayment:

ts
import { startTokenPayment } from 'simplepay-js-sdk'

const response = await startTokenPayment({
  orderRef: `sub-2026-0001-${Date.now()}`, // new orderRef for every charge
  token: nextUnusedToken,                   // a token not used yet
  total: 4990,                              // at most maxAmount
  currency: 'HUF',
  method: 'CARD',                           // required, must be CARD
  customer: 'Test Customer',
  customerEmail: '[email protected]',
  language: 'EN',
})

// response.transactionId identifies the charge
await markTokenUsed(nextUnusedToken)
  • The call goes to SimplePay's /dorecurring endpoint with type: 'MIT' and threeDSReqAuthMethod (default '02', overridable with the threeDSReqAuthMethod field).
  • No redirect is needed; the response (SimplePayTokenResponse) has no paymentUrl.
  • An IPN reports the result, just like a one-time payment.
  • Use each token once. When the tokens run out or until has passed, the customer must register the card again.

4. Removing a card ​

Let customers remove their registered card. cardId is the SimplePay transaction ID of the card registration (the transactionId of the startRecurringPayment response).

ts
import { cancelCard } from 'simplepay-js-sdk'

const response = await cancelCard(registrationTransactionId)

if (response.status === 'DISABLED') {
  await deleteTokensAndCard(customerId) // the remaining tokens can go too
}

HUF account only

cancelCard always uses SIMPLEPAY_MERCHANT_ID_HUF / SIMPLEPAY_MERCHANT_KEY_HUF. Cards registered on other currency accounts cannot be removed with it yet.

Response (SimplePayCancelCardResponse): salt, merchant, cardId, status: 'DISABLED', expiry.

Sandbox test cards for recurring payments ​

Card numberResult
4908 3660 9990 0425Successful payment
5437 5884 9903 4193Registration succeeds, payment fails
6757 6192 9705 7001Registration fails, payment succeeds

Details: Testing.

Unofficial community SDK. Not affiliated with or endorsed by SimplePay Zrt. MIT License.