
A small Angular example integrating with payhere.lk's JavaScript SDK
Initialize the node project (because node_modules folder is not included in repo).
npm install
With Angular installed on your machine via npm, run one of the following commands.
npx ng serve
ng serve
1. In your index.html
file, include the PayHere JavaScript SDK
<!doctype html>
<html lang="en">
<head>
...
<!-- Add this line -->
<script src="https://www.payhere.lk/lib/payhere.js"></script>
</head>
...
</html>
let payhere = (window as any).payhere;
PayHere JS SDK attaches to the window property. But without the downcast to any
, you will get compilation errors since TypeScript is a type safe language.
Example:
let payhere = (window as any).payhere;
const payment = {
"sandbox": true,
"merchant_id": "1211149", // Replace your Merchant ID
"return_url": undefined, // Important
"cancel_url": undefined, // Important
"notify_url": "http://sample.com/notify",
"order_id": "ItemNo12345",
"items": "Door bell wireles",
"amount": "1000.00",
"currency": "LKR",
"first_name": "Saman",
"last_name": "Perera",
"email": "[email protected]",
"phone": "0771234567",
"address": "No.1, Galle Road",
"city": "Colombo",
"country": "Sri Lanka",
"delivery_address": "No. 46, Galle road, Kalutara South",
"delivery_city": "Kalutara",
"delivery_country": "Sri Lanka",
"custom_1": "",
"custom_2": ""
}
payhere.onCompleted = (orderId: String) => {
console.log("PayHere Completed - Order number =", orderId);
};
payhere.onDismissed = () => {
console.log("PayHere Dismissed");
};
payhere.onError = (error: String) => {
console.log("PayHere Error =", error);
}
payhere.startPayment(payment);
-
You can ask questions in the Issues Section of this repo.
-
You can email a PayHere Developer at [email protected] for assistance.