---
url: https://simplepay.webmania.cc/en/reference/api.md
description: >-
  Every exported simplepay-js-sdk function with parameters, return values and
  errors: startPayment, getPaymentResponse, handleIpnRequest,
  startRecurringPayment, startTokenPayment, cancelCard, getTransactionStatus,
  queryTransactions, refund, startGooglePay, startApplePay, doApplePay,
  renderGooglePayButton, renderApplePayButton.
---

# Functions

The package has three entry points:

| Import | Runs in | Contents |
|---|---|---|
| `simplepay-js-sdk` | server (Node.js) | payments, IPN, recurring, Google Pay and Apple Pay server side, helpers |
| `simplepay-js-sdk/google-pay` | browser | `renderGooglePayButton` |
| `simplepay-js-sdk/apple-pay` | browser | `renderApplePayButton` |

Server functions read the keys from [environment variables](./environment). Types: [Types](./types).

## Payments

### `startPayment`

```ts
startPayment(paymentData: PaymentData, config?: StartPaymentConfig): Promise<SimplePayResponse>
```

Starts a one-time payment (`POST /start`). Redirect the customer to the returned `paymentUrl`.

* `paymentData`: [`PaymentData`](./types#paymentdata)
* `config.redirectUrl`: return URL for this payment (default: `SIMPLEPAY_REDIRECT_URL`)
* `config.urls`: `{ success, fail, cancel, timeout }`, a separate URL per outcome; when given, it is sent instead of `url`
* Defaults: `currency: 'HUF'`, `language: 'HU'`, `method: 'CARD'`, 30-minute timeout (override with the `timeout` field)
* When `items` is sent, SimplePay ignores `total`.
* Guide: [One-time payment](../guide/one-time-payment)

### `getPaymentResponse`

```ts
getPaymentResponse(r: string, s: string): SimplePayResult
```

Verifies and decodes the back-URL `r` and `s` parameters. Synchronous.

* Replaces spaces in `s` with `+`.
* Picks the currency and key from the merchant ID.
* Errors: `Merchant id not found in the environment: …`, `Missing SimplePay configuration for …`, `Invalid response signature`
* Guide: [Back URL](../guide/back-url)

### `handleIpnRequest`

```ts
handleIpnRequest(ipnBody: string, incomingSignature: string, merchantKey: string): { responseBody: string, signature: string }
```

Handles an IPN: verifies the signature, inserts `receiveDate`, signs the response. Synchronous.

* `ipnBody`: the **raw** request body
* `incomingSignature`: the `Signature` header
* `merchantKey`: the account's secret key
* Errors: `Invalid IPN request signature`, `Invalid IPN request body`, `Missing merchant key`
* Guide: [IPN](../guide/ipn)

## Recurring payments

### `startRecurringPayment`

```ts
startRecurringPayment(paymentData: RecurringPaymentData, config?: StartPaymentConfig): Promise<SimplePayRecurringResponse>
```

Payment with card registration (`POST /start`). The response's `tokens` array is needed for later charges.

* `config`: `redirectUrl` or `urls`, as for `startPayment`.
* Always `CARD`; `threeDSReqAuthMethod` defaults to `'02'`.
* `recurring` defaults for falsy fields: `times: 3`, `until`: about 180 days, `maxAmount: 12000`.

### `startTokenPayment`

```ts
startTokenPayment(paymentData: TokenPaymentData, config?: PaymentConfig): Promise<SimplePayTokenResponse>
```

Charges a stored token without the customer (`POST /dorecurring`, `type: 'MIT'`). `method` must be `'CARD'`. `config.redirectUrl` overrides `SIMPLEPAY_REDIRECT_URL`.

### `cancelCard`

```ts
cancelCard(cardId: string): Promise<SimplePayCancelCardResponse>
```

Removes a registered card (`POST /cardcancel`). `cardId` is the SimplePay `transactionId` of the card registration. Always uses the **HUF** account keys. On success `status` is `'DISABLED'`.

Guide: [Recurring payments](../guide/recurring-payments)

## Transactions

### `getTransactionStatus`

```ts
getTransactionStatus(query: TransactionStatusQuery): Promise<SimplePayTransactionStatusResponse>
```

Status of one transaction (`POST /status`). Exactly one identifier is required: `transactionId` or `orderRef`.

* `query.currency`: currency of the merchant account (default: `HUF`)
* The response `status` is a `TransactionStatus` ([types](./types)); `endState` is `true` when the status is final.
* Errors: `Pass exactly one of transactionId or orderRef`, `Invalid transaction id: …`, `SimplePay API error: …`
* Guide: [Refunds and queries](../guide/refunds-and-queries)

### `queryTransactions`

```ts
queryTransactions<Q extends TransactionQuery>(query: Q): Promise<SimplePayQueryResponse<Q>>
```

Looks up one or more transactions (`POST /query`) by `transactionIds` and/or `orderRefs`.

* `query.detailed`: also return the order data
* `query.refunds`: also return the refund status and the refunds
* `query.currency`: currency of the merchant account (default: `HUF`)
* The response type follows the `detailed` and `refunds` flags.
* Errors: `Pass at least one transactionId or orderRef`, `Invalid transaction id: …`, `SimplePay API error: …`
* Guide: [Refunds and queries](../guide/refunds-and-queries)

### `refund`

```ts
refund(refundData: RefundData): Promise<SimplePayRefundResponse>
```

Refunds a `FINISHED` transaction fully or partially (`POST /refund`), by `transactionId` or `orderRef`.

* `refundData.refundTotal`: the amount to refund (in the transaction's currency)
* `refundData.currency`: the transaction's currency, which also picks the merchant account (default: `HUF`)
* Returns: `refundTransactionId`, `refundTotal`, `remainingTotal`
* Errors: `Pass exactly one of transactionId or orderRef`, `Invalid transaction id: …`, `Invalid refund total: …`, `SimplePay API error: …`
* Guide: [Refunds and queries](../guide/refunds-and-queries)

## Google Pay

### `startGooglePay`

```ts
startGooglePay(paymentData: GooglePayPaymentData, config?: PaymentConfig): Promise<SimplePayGooglePayResponse>
```

Google Pay charge (`POST /dogooglepay`, `type: 'CIT'`).

* `HUF_SZEP` is not supported.
* Error code `3004` with `redirectUrl` is not thrown: the response is returned and the browser redirects to 3DS.
* Errors: `Missing Google Pay token`, `Google Pay does not support HUF_SZEP`, `SimplePay API error: …`

### `renderGooglePayButton`

```ts
import { renderGooglePayButton } from 'simplepay-js-sdk/google-pay'

renderGooglePayButton(config: GooglePayButtonConfig): Promise<void>
```

Renders the Google Pay button in the browser if the browser can pay with Google Pay. On click it `POST`s `{ googlePayToken, orderRef }` to `authorizationEndpoint`. Config: [`GooglePayButtonConfig`](./types#googlepaybuttonconfig).

Guide: [Google Pay](../guide/google-pay)

## Apple Pay

### `startApplePay`

```ts
startApplePay(paymentData: ApplePayStartData): Promise<SimplePayApplePayStartResponse>
```

Apple Pay session for merchant validation (`POST /startapplepay`). `domain` is the registered FQDN. The response contains `transactionId` and `applePaySession`.

### `doApplePay`

```ts
doApplePay(paymentData: ApplePayChargeData): Promise<SimplePayApplePayChargeResponse>
```

Apple Pay charge (`POST /doapplepay`). Throws if `applePayStatus` is not `STATUS_SUCCESS`.

### `renderApplePayButton`

```ts
import { renderApplePayButton } from 'simplepay-js-sdk/apple-pay'

renderApplePayButton(config: ApplePayButtonConfig): Promise<void>
```

Renders the Apple Pay button in the browser if available. Config: [`ApplePayButtonConfig`](./types#applepaybuttonconfig).

Guide: [Apple Pay](../guide/apple-pay)

## Helpers

### `generateSignature`

```ts
generateSignature(body: string, merchantKey: string): string
```

HMAC-SHA384 signature, Base64-encoded. Throws `Missing merchant key` for an empty key.

### `checkSignature`

```ts
checkSignature(responseText: string, signature: string, merchantKey: string): boolean
```

Verifies a signature with a timing-safe comparison (`crypto.timingSafeEqual`). Returns `false` for a non-string or different-length signature.

### `toISO8601DateString`

```ts
toISO8601DateString(date: Date): string
```

The date format SimplePay expects: `2026-12-31T18:00:00+00:00` (UTC, no milliseconds). Useful for `recurring.until`.

## Not exported

`getSimplePayConfig` and `getCurrencyFromMerchantId` are internal and cannot be imported from the package. Read the key from `process.env.SIMPLEPAY_MERCHANT_KEY_<CURRENCY>`.
