greenbanksdk-js-client
Version:
Greenbank Client Javascript SdK
92 lines (75 loc) • 2.13 kB
HTML
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../index.js"></script>
</head>
<body>
<h1>Hello world</h1>
<button onclick="paymerchant()">Pay Merchant</button>
<button onclick="paymentlink()">Create Payment Link</button>
<script>
// var apikey = window.prompt("Enter your api key");
var apikey = "44caebfb-7a2c-4ac1-826b-ffecde4b07a3";
function paymentlink() {
//method will return payment reference
// merchant can then load the paymerchant page with the reference that was returned.
// pass redirect_url
// pass selected payment channels
let params = {
amount: 2000,
currency: 'NGN',
description: 'Invoice payment Fee',
channels: ["flutterwave", "paypal", "greenbank", "stripe"],
customer_firstname: 'John',
customer_lastname: 'Eliam',
customer_email: 'user@onewattsolar.com',
redirect_url: "https://google.com",
meta: {
txntype: 'invoice_payment',
invoice_id: 134
},
onSuccess: (res) => {
// example - you can redirect to paymentlink here or just save the link
// window.location = new URL(res.data.link)
console.log(res)
greenbank.loadPaymentLinkModal(res.data.link)
},
onError: (res) => {
alert('error occured')
console.log(res)
},
onClose: () => {
alert('hello payment closed')
console.log('colose')
},
domain: 'test',
merchant_key: apikey,
}
greenbank.createPaymentLink(params)
}
function paymerchant() {
let payload = {
amount: 100,
currency: 'NGN',
description: 'Invoice payment Fee',
channels: ["flutterwave", "paypal"],
customer_firstname: 'John',
customer_lastname: 'Eliam',
customer_email: 'user@onewattsolar.com',
redirect_url: "https://google.com",
meta: {
txntype: 'invoice_payment',
invoice_id: 134
},
domain: 'test',
merchant_key: apikey,
}
greenbank.paymerchant(payload)
}
//44caebfb-7a2c-4ac1-826b-ffecde4b07a3
</script>
</body>
</html>