Skip to main content

Enbank - NextJS example docs

Read on how the payment flow works first and the OpenAPI docs. Then look at the example code bellow.

Enbank Integration Documentation

import Script from "next/script";

function Page({ transactionId }) {
return (
<>
<Script src="http://pay.enbank.me/enbank-pay.min.js"></Script>
<enbank-pay transactionId={transactionId}></enbank-pay>
</>
)
}

export async function getServerSideProps() {
const rootPath = `https://enbank-server-local.fly.dev` // PROD URL is: https://pay.enbank.me
const response = await fetch(`${rootPath}/transactions/new`, {
method: "POST",
headers: {
'Content-Type': 'application/json',
'accept': 'application/json'
},
body: JSON.stringify({
/* The amount the user will be charged. */
amount: 9.99,
/* The private merchant security token */
token: '###PRIVATE_TOKEN###',
/* They payment description which will be show to the user when paying */
description: 'My Enbank transaction',
/* The url we will use to notify you when a transaction was successful */
successCallback: 'https://...',
/* The url we will use to notify you when a transaction has failed */
errorCallback: 'https://...',
}),
});
const data = await response.json();

return { props: { transactionId: data.transactionId } };
}

export default Page;