PPayNow Docs
Menu — PayNowWebSdk

API Reference

PayNowWebSdk

The facade your Jaspr web host instantiates. Wraps a PaymentApi + PaymentEngine + status poller.

PayNowWebSdk (in packages/paynow_jaspr_sdk/lib/src/paynow_web_sdk.dart) is what the gateway page consumes. Construct one per session:

final sdk = PayNowWebSdk(
              api: createPaymentApi(),
              tokenStore: InMemoryTokenStore(),
            );
            

Methods

Future<void> initialize({String? clientToken})

Saves the bearer JWT to the TokenStore so subsequent calls can attach it. No-op when clientToken is null/empty.

Future<String?> readClientToken()

Returns the saved bearer JWT (or null).

Future<void> clearSession()

Clears the saved bearer JWT. Doesn't terminate any in-flight requests.

void restoreSession(PaymentSession session)

Hydrates the engine with a PaymentSession (typically returned by /web-payment/initiate). Triggers an event on sessionStream, which the page listens to.

Future<PaymentSession> createInvoice(CreateInvoiceRequest request)

POST /web-payment/initiate. Use only when the page is the initiator (rare — most flows initiate server-side via merchantInitiateMiddleware).

Future<PaymentSession> generateQr(GenerateQrRequest request)

POST /web-payment/{paynow,one-pay}/merchant-qr. Returns a session with state: qrGenerated and qrPayload populated.

Future<PaymentSession> validateAccount(ValidateAccountRequest request)

POST /web-payment/initiate-payment-request (or the /paynow/ variant for wallet). Returns state: otpRequired.

Future<PaymentSession> submitOtp(SubmitOtpRequest request)

POST /payment-request (or the /paynow/process-payment-request variant). Returns state: waitingPayment (OnePay account, ack-only) or state: success/failed (PayNow wallet).

Future<PaymentSession> refreshStatus(String paymentId)

POST /web-payment/check-status. Used by the status poller and the manual "Refresh" button.

bool get supportsStatusPolling

True when fetchStatus is wired to a real backend endpoint (i.e., the underlying PayNowOnePayApi has a non-empty statusPath). False disables the poller silently.

void startStatusPolling(String paymentId, {PollSchedule schedule})

Begin polling. Re-entrant for the same paymentId. No-ops when supportsStatusPolling is false.

void stopStatusPolling()

Stop the active poller. Idempotent.

Future<void> disposeStatusPolling()

Tear down the poller permanently. Call from your page's dispose().

Streams

Stream<PaymentEvent> get sessionStream

Broadcast stream of PaymentEvents — emitted on every successful API call, every state transition, and every poll tick that produced a new state. Subscribe in your page's initState and setState from the listener.

PaymentSession? get currentSession

The most recent session (or null before bootstrap).