PayPal™
Enabling PayPal™ for your account
Using PayPal™ in your Web Application
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>PayPal Demo</title>
<script src="https://console.payengine.co/js/1.0.0/embed.js?key=<your public key>" async></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.22.0/axios.min.js"
integrity="sha512-m2ssMAtdCEYGWXQ8hXVG4Q39uKYtbfaJL5QMTbhl2kc6vYyubrKHhr6aLLXW4ITeXSywQLn1AhsAaqrJl8Acfg=="
crossorigin="anonymous" referrerpolicy="no-referrer"></script>
</head>
<body>
<h4>PayPal</h4>
<div id="button"></div>
<script>
const merchantId = "<Your Merchant ID>";
const amount = "<Amount you want to charge>";
const submit = (paypalOrderID) => {
axios
.post(
"<Your Back End Application>/api/charge",
{
merchantID: merchantId,
paypalOrderID: paypalOrderID,
amount: String(amount),
}
)
.then((resp) => {
//Handle Response from your backend
})
.catch((err) => {
//Handle Error from your backend
});
};
window.onload = () => {
Platform.PayPal.configure({
merchantId: merchantId,
amount: amount,
selector: "#button",
buttonColor: "silver", // Button color: "gold" | "blue" | "silver" | "white" | "black"
buttonShape: "pill", // Button shape: rect, pill, sharp
buttonLabel: "paypal", // Button label: "paypal" | "checkout" | "buynow" | "pay"
buttonHeight: 36, // utton height in pixels (25-55)
onApprove: (paypalData) => {
console.log('onApprove', paypalData)
// submit the paypal order ID to capture via /api/payment/sale
submit(paypalData.paypalOrderID)
},
onCancel: (paypalData) => {
console.log('onCancel', paypalData)
},
onError: (err) => {
console.error('onError', err)
}
});
};
</script>
</body>
</html>Presenting the PayPal™ button
Sample Responses
Customizing PayPal™ button
Last updated