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. Types: Types.
Payments
startPayment
startPayment(paymentData: PaymentData, config?: StartPaymentConfig): Promise<SimplePayResponse>Starts a one-time payment (POST /start). Redirect the customer to the returned paymentUrl.
paymentData:PaymentDataconfig.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 ofurl- Defaults:
currency: 'HUF',language: 'HU',method: 'CARD', 30-minute timeout (override with thetimeoutfield) - When
itemsis sent, SimplePay ignorestotal. - Guide: One-time payment
getPaymentResponse
getPaymentResponse(r: string, s: string): SimplePayResultVerifies and decodes the back-URL r and s parameters. Synchronous.
- Replaces spaces in
swith+. - 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
handleIpnRequest
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 bodyincomingSignature: theSignatureheadermerchantKey: the account's secret key- Errors:
Invalid IPN request signature,Invalid IPN request body,Missing merchant key - Guide: IPN
Recurring payments
startRecurringPayment
startRecurringPayment(paymentData: RecurringPaymentData, config?: StartPaymentConfig): Promise<SimplePayRecurringResponse>Payment with card registration (POST /start). The response's tokens array is needed for later charges.
config:redirectUrlorurls, as forstartPayment.- Always
CARD;threeDSReqAuthMethoddefaults to'02'. recurringdefaults for falsy fields:times: 3,until: about 180 days,maxAmount: 12000.
startTokenPayment
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
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
Transactions
getTransactionStatus
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
statusis aTransactionStatus(types);endStateistruewhen the status is final. - Errors:
Pass exactly one of transactionId or orderRef,Invalid transaction id: …,SimplePay API error: … - Guide: Refunds and queries
queryTransactions
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 dataquery.refunds: also return the refund status and the refundsquery.currency: currency of the merchant account (default:HUF)- The response type follows the
detailedandrefundsflags. - Errors:
Pass at least one transactionId or orderRef,Invalid transaction id: …,SimplePay API error: … - Guide: Refunds and queries
refund
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
Google Pay
startGooglePay
startGooglePay(paymentData: GooglePayPaymentData, config?: PaymentConfig): Promise<SimplePayGooglePayResponse>Google Pay charge (POST /dogooglepay, type: 'CIT').
HUF_SZEPis not supported.- Error code
3004withredirectUrlis 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
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 POSTs { googlePayToken, orderRef } to authorizationEndpoint. Config: GooglePayButtonConfig.
Guide: Google Pay
Apple Pay
startApplePay
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
doApplePay(paymentData: ApplePayChargeData): Promise<SimplePayApplePayChargeResponse>Apple Pay charge (POST /doapplepay). Throws if applePayStatus is not STATUS_SUCCESS.
renderApplePayButton
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.
Guide: Apple Pay
Helpers
generateSignature
generateSignature(body: string, merchantKey: string): stringHMAC-SHA384 signature, Base64-encoded. Throws Missing merchant key for an empty key.
checkSignature
checkSignature(responseText: string, signature: string, merchantKey: string): booleanVerifies a signature with a timing-safe comparison (crypto.timingSafeEqual). Returns false for a non-string or different-length signature.
toISO8601DateString
toISO8601DateString(date: Date): stringThe 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>.
