@pesepay/vue
Vue components for Pesepay Elements. Vue 3.5 or later.
npm install @pesepay/js @pesepay/vue The components create, mount and destroy the elements from
@pesepay/js for you, including under
server rendering.
Take a payment
Section titled “Take a payment”Your server creates the transaction and passes its reference number to the component:
<script setup lang="ts">import type { CheckoutOutcome } from "@pesepay/js";import { CheckoutElement, Elements } from "@pesepay/vue";
const props = defineProps<{ referenceNumber: string }>();// The payment has ended and the element shows the result. Fulfil the order on// your server, which Pesepay notifies too.const emit = defineEmits<{ finished: [outcome: CheckoutOutcome] }>();
// The methods could not load: Pesepay's hosted checkout takes the payment.function leave(fallbackUrl: string | undefined): void { if (fallbackUrl) window.location.assign(fallbackUrl);}</script>
<template> <Elements> <CheckoutElement :options="{ referenceNumber: props.referenceNumber }" @finished="(event) => emit('finished', event.outcome)" @load-error="(event) => leave(event.fallbackUrl)" /> </Elements></template><CheckoutElement> 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.
<Elements>
Section titled “<Elements>”| Prop | 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, outside the component, and pass the
promise.
<Elements> creates one elements group once it is mounted and Pesepay has
loaded, and destroys it, and every element in it, when it unmounts.
Group-wide options that change, including a reactive object changed in place,
are passed to elements.update().
Its default slot receives { pesepay, elements }, so the component that
renders <Elements> can pay. In a child component, usePesepay() and
useElements() return the same two as shallow refs. All of them are null
while Pesepay loads and during server rendering. The composables throw
outside <Elements>.
Element components
Section titled “Element components”| Component | Element | options |
|---|---|---|
<CheckoutElement> | checkout | required: { referenceNumber } |
<PaymentElement> | payment | required: { referenceNumber } |
<CardElement> | card | optional |
<MobileElement> | mobile | optional: { provider }, … |
<ScanElement> | scan | optional: { provider } |
<HostedCardElement> | hostedCard | required: { cardCheckout } |
Each renders a <div>, with your id and class, and mounts its element
into it. Events are typed for the element: @ready, @change, @focus,
@blur, @escape and @load-error, plus @status on the mobile and
payment elements and @finished on the checkout element.
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
<Elements> holds one element of each type; for two card fields, use two
<Elements>.
Server rendering
Section titled “Server rendering”<Elements> loads nothing before it is mounted, and loadPesepay() resolves
null on the server. On the server, and in Nuxt, each element component
renders an empty <div>. 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 Vue code
- Elements SDK reference: every component, prop and composable