Skip to content

@pesepay/angular

@pesepay/angular npm

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.

Your server creates the transaction and passes its reference number to the component:

src/app/checkout.component.ts
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.

InputTypeNotes
pesepayPesepay | null | Promise<Pesepay | null>Optional. What loadPesepay() returns. Fixed on first render.
optionsElementsOptionstheme, 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>.

ComponentElementoptions
<pesepay-checkout-element>checkoutrequired: { referenceNumber }
<pesepay-payment-element>paymentrequired: { referenceNumber }
<pesepay-card-element>cardoptional
<pesepay-mobile-element>mobileoptional: { provider }, …
<pesepay-scan-element>scanoptional: { provider }
<pesepay-hosted-card-element>hostedCardrequired: { 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>.

<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.