Configuration
Full configuration reference for BetterPayment.
BetterPaymentConfig
import { BetterPayment, ProviderType } from 'better-payment';
const payment = new BetterPayment({
defaultProvider: ProviderType.IYZICO, // optional; the only enabled provider becomes default
mode: 'sandbox', // 'sandbox' | 'production' (default)
logger, // optional, see below
retry, // optional, see below
handler, // optional HTTP handler options
providers: {
iyzico: {
enabled: true,
config: {
apiKey: string,
secretKey: string,
baseUrl?: string, // default from mode
locale?: 'tr' | 'en',
},
},
paytr: {
enabled: true,
config: {
merchantId: string,
merchantKey: string,
merchantSalt: string,
testMode?: boolean, // default: mode === 'sandbox'
timeoutLimit?: number, // iFrame timeout in minutes, default 30
},
},
akbank: {
enabled: true,
config: {
merchantSafeId: string,
terminalSafeId: string,
secretKey: string,
subMerchantId?: string,
testMode?: boolean, // selects the test 3D gateway; default: mode === 'sandbox'
gateway3dUrl?: string, // override the securepay URL
},
},
parampos: {
enabled: true,
config: {
clientCode: string,
clientUsername: string,
clientPassword: string,
guid: string,
},
},
},
});Missing or empty credentials throw a ConfigurationError that lists the missing fields.
Default URLs
| Provider | sandbox | production |
|---|---|---|
| iyzico | https://sandbox-api.iyzipay.com | https://api.iyzipay.com |
| PayTR | https://www.paytr.com (with test_mode=1) | https://www.paytr.com |
| Akbank | https://apipre.akbank.com/api/v1/payment/virtualpos | https://api.akbank.com/api/v1/payment/virtualpos |
| Parampos | https://test-dmz.param.com.tr/turkpos.ws/service_turkpos_test.asmx | https://posws.param.com.tr/turkpos.ws/service_turkpos_prod.asmx |
Set baseUrl on a provider's config to override its default.
Provider Access
payment.iyzico // throws ProviderNotEnabledError if not enabled
payment.paytr
payment.akbank
payment.parampos
payment.use(ProviderType.PAYTR)
payment.isProviderEnabled(ProviderType.IYZICO) // boolean
payment.getEnabledProviders() // ProviderType[]Logging
logger: {
debug: (message, meta) => {},
info: (message, meta) => {},
error: (message, error, meta) => {},
}The logger receives the HTTP method, URL and status. Request and response bodies, which contain card data and credentials, are never logged.
Retry
retry: {
attempts: 3, // total attempts including the first
delay: 1000, // ms between attempts
statusCodes: [429, 503], // retry on these HTTP statuses (network errors are always retried)
}Only idempotent requests are retried: status, BIN and installment queries. Payment, refund and cancel requests are never retried. If one of them fails without a response, it returns status: 'pending' with errorCode: 'NETWORK_ERROR' so that you check the outcome with getPayment().
HTTP Handler
See BetterPaymentHandler for the options and the framework examples.