@pesepay/angular
Standalone Angular components for Pesepay Elements. Angular 22 or later; no zone.js required.
npm install @pesepay/js @pesepay/angular The components create, mount and destroy the elements from
@pesepay/js for you, including under
server rendering. They are standalone components with signal inputs.
Take a payment
Section titled “Take a payment”Your server creates the transaction and passes its reference number to the component:
import { Component, computed, input, output } from "@angular/core";import type { CheckoutOutcome } from "@pesepay/js";import { CheckoutElement, Elements } from "@pesepay/angular";
@Component({ selector: "app-checkout", imports: [Elements, CheckoutElement], template: ` <pesepay-elements> <pesepay-checkout-element [options]="options()" (finished)="finished.emit($event.outcome)" (loadError)="leave($event.fallbackUrl)" /> </pesepay-elements> `,})export class CheckoutComponent { readonly referenceNumber = input.required<string>(); /** * The payment has ended and the element shows the result. Fulfil the order * on your server, which Pesepay notifies too. */ readonly finished = output<CheckoutOutcome>(); protected readonly options = computed(() => ({ referenceNumber: this.referenceNumber(), }));
// The methods could not load: Pesepay's hosted checkout takes the payment. leave(fallbackUrl: string | undefined): void { if (fallbackUrl) window.location.assign(fallbackUrl); }}The component and its selector are yours to name. The Pesepay parts are the
<pesepay-…> tags inside it.
<pesepay-checkout-element> lists the methods and pays with its own button.
It runs every step itself, including the result when the customer comes back
from 3-D Secure, and emits (finished) once with outcome: succeeded,
failed, reversed or unknown. For your own Pay button, see
Custom payment flow.
<pesepay-elements>
Section titled “<pesepay-elements>”| Input | Type | Notes |
|---|---|---|
pesepay | Pesepay | null | Promise<Pesepay | null> | Optional. What loadPesepay() returns. Fixed on first render. |
options | ElementsOptions | theme, fonts, locale for every element inside. Changes are applied. |
Left out, pesepay defaults to loading Pesepay with the default options in
the browser. To set options, such as apiBaseUrl, call
loadPesepay({ apiBaseUrl }) once, in a field, and pass the promise.
<pesepay-elements> creates one elements group after the first render in the
browser, once Pesepay has loaded, and destroys it, and every element in it,
when it is destroyed. A new options object is passed to elements.update()
unless it equals the one applied. Give it a new object rather than changing
one in place.
Export it to a template variable with #checkout="pesepayElements" to pay
from the component that renders it: checkout.instance() and
checkout.elements() are signals. In a component inside it,
injectPesepay() and injectElements() return the same two signals. All of
them are null while Pesepay loads and during server rendering. The inject
functions throw outside <pesepay-elements>.
Element components
Section titled “Element components”| Component | Element | options |
|---|---|---|
<pesepay-checkout-element> | checkout | required: { referenceNumber } |
<pesepay-payment-element> | payment | required: { referenceNumber } |
<pesepay-card-element> | card | optional |
<pesepay-mobile-element> | mobile | optional: { provider }, … |
<pesepay-scan-element> | scan | optional: { provider } |
<pesepay-hosted-card-element> | hostedCard | required: { cardCheckout } |
Import each from @pesepay/angular as CheckoutElement, PaymentElement,
CardElement, MobileElement, ScanElement and HostedCardElement. Each
mounts its element into its own host element, which is display: block.
Outputs are typed for the element: (ready), (elementChange), (focus),
(blur), (escape) and (loadError), plus (status) on the mobile and
payment elements and (finished) on the checkout element. elementChange is
the element’s change event. It is not called change because Angular would
also deliver the DOM change events that bubble out of the card provider’s
form.
Changed options are passed to the element’s update(). A payment or
checkout element given a new referenceNumber is replaced, since one element
pays one transaction.
Outside the checkout element, to pay, read the element off the group with
elements.getElement(type) and pass it to confirmPayment(). One
<pesepay-elements> holds one element of each type; for two card fields, use
two <pesepay-elements>.
Server rendering
Section titled “Server rendering”<pesepay-elements> loads nothing before the first render in the browser,
and loadPesepay() resolves null on the server. On the server each element
component renders as an empty host element. See
Server-side rendering.
What’s next
Section titled “What’s next”- Quickstart: the whole checkout, server included
- Guides: each method, errors and theming, with Angular code
- Elements SDK reference: every component and injection helper