Skip to content

PaymentCallback & Status ​

PaymentCallback ​

Returned by every gateway's handleCallback() (and AYA's verifyRedirect()) once the signature is verified.

Field / MethodTypeDescription
orderIdstringYour order ID
statusPaymentStatusThe status mapped onto this package's statuses
gatewayStatusstringThe gateway's own status value, unmapped
gatewayReferencestring | undefinedThe gateway's ID for the payment
amountstring | undefinedThe amount the gateway reports, exactly as it sent it
rawRecord<string, unknown>The verified payload, as plain JavaScript values; JSON numbers are their exact text as strings
acknowledgementAcknowledgementThe response the gateway expects
isSuccessful()booleanstatus === 'successful'

Build one yourself to test your own fulfillment code, with an object: new PaymentCallback({ orderId, status, gatewayStatus, gatewayReference?, amount?, raw?, acknowledgement? }). status takes a PaymentStatus value, and acknowledgement defaults to Acknowledgement.default().

Acknowledgement ​

A class with read-only fields; new Acknowledgement({ status?, body?, headers? }) builds one.

Field / MethodTypeDescription
statusnumberHTTP status, 200 by default
bodystringResponse body, e.g. KBZ Pay's success; empty by default
headersRecord<string, string>Response headers, { 'Content-Type': 'text/plain' } by default
send(res)voidWrites the status, headers and body to a node:http ServerResponse (or Express res) and ends it
toResponse()ResponseThe acknowledgement as a Fetch API Response

Acknowledgement.default() is an empty 200 with Content-Type: text/plain. Write it with your framework's response API, see Acknowledging.

PaymentStatusResult ​

Returned by kbz.status(), aya.status() and yoma.status(). A class with read-only fields.

Field / MethodTypeDescription
orderIdstring | undefinedYour order ID; undefined for Yoma, which returns only the reference
statusPaymentStatusThe mapped status
gatewayStatusstringThe gateway's own status value
gatewayReferencestring | undefinedThe gateway's ID for the payment
amountstring | undefinedThe amount the gateway reports
rawRecord<string, unknown>The gateway's response
isSuccessful()booleanstatus === 'successful'

CallbackRequest ​

MemberTypeDescription
CallbackRequest.from({ body, headers, query })CallbackRequestFrom the raw parts: the body as a string, Buffer, Uint8Array or ArrayBuffer, the headers as an object or [name, value] pairs, the query string as a string, URLSearchParams or an object. All three are optional
CallbackRequest.fromJson(payload, headers?)CallbackRequestFrom a decoded payload, encoded as a JSON body
CallbackRequest.fromNodeRequest(req)Promise<CallbackRequest>From a node:http IncomingMessage (Express req, or Koa ctx.req without a body parser)
CallbackRequest.fromWebRequest(request)Promise<CallbackRequest>From a Fetch API Request, read from a clone
rawBodyUint8ArrayThe raw body, exactly as received
bodystringThe raw body, decoded as UTF-8
headersRecord<string, string>Headers with lowercase names; repeated headers joined with ,
queryRecord<string, string>Query string values (the first of each)
header(name)string | undefinedOne header, case-insensitively
parsedBody()Record<string, unknown>The body decoded as JSON or a form; JSON numbers are their exact text as strings
input()Record<string, unknown>The body merged over the query string
queryInput()Record<string, unknown>The query string merged over the body

PaymentStatus ​

type PaymentStatus = 'successful' | 'pending' | 'failed' | 'canceled' | 'expired' | 'unknown': statuses are plain strings, and the PaymentStatus object names each value.

ConstantValue
PaymentStatus.Successfulsuccessful
PaymentStatus.Pendingpending
PaymentStatus.Failedfailed
PaymentStatus.Canceledcanceled
PaymentStatus.Expiredexpired
PaymentStatus.Unknownunknown

PaymentStatus.values lists every status. PaymentStatus.isFinal(status) is false for pending and unknown. resolveStatus(statuses, gatewayStatus) maps a trimmed gateway value through an object and returns 'unknown' when it is not listed.

Released under the MIT License, except where a package says otherwise.