2.1.2 • Published 4 years ago
paynamicsjs v2.1.2
Paynamics - https://www.paynamics.com/
Information
- Paynamics Gateway intergration for NodeJS
- From paynamics documentation example PHP
Installation
NPM
npm install paynamicsjs --save
YARN
yarn add paynamicsjs
Usage
Generate payment signature
const { generateSignature, verifySignature } = require("paynamicsjs")
// xml format
const items = `
<Items>
<itemname>Your Items</itemname>
<quantity>1</quantity>
<amount>50.00</amount>
</Items>
`;
const signature = generateSignature({
merchant_id: "your merchant id", // set this as your merchant id
merchant_key: "your merchant key", // set this as your merchant key
notification: "https://yourapi.com/notification", // POST url from paynamics
response: "https://yourapi.com/response", // GET url for transaction result
cancel: "https://yourapi.com/cancel", // GET url when the user cancels
items,
requestid: '123', // order id for your app
ip: '', // ip
firstName: '', // customer's firstname
middleName: '', // customer's middlename
lastName: '', // customer's lastname
address1: '', // customer's address1
address2: '', // customer's address2
city: '',
state: '',
country: '',
zip: '',
email: '',
phone: '',
mobile: '',
clientip: '',
amount: '', // set it to 2 decimal places
currency: '', // PHP
items: items,
})
`;
Serve the HTML with paymentSignature as the value for the form.
serve this html to your customer and it will be routed to paynamics' web page payment.
notice that the value of the form is the string from generateSignature function above..
<form id="paynamics-form" name="form1" method="post" hidden action="https://testpti.payserv.net/webpaymentv2/default.aspx">
<input type="text" name="paymentrequest" id="paymentrequest" value="paymentSignature" >
<input type="submit">
</form>
<script>
$(function () {
window.onload = function(){
$("#paynamics-form").submit();
}
})
</script>
Get the result for payment through POST request
after the user succesfully entered the card details,
paynamics api will POST request to your web api. (notification url)
the body request will be paymentresponse variable.
const mid = "" // merchant_id
const paymentResponse = "" // post request data from https://yourapi.com/notification
verifySignature(mid, paymentResponse, (err, res) => {
if(err) {
// err
}
if(res) {
// success
// res is object {
// success: true,
// requestid: "your order id",
// paynamicsResponse: {
// // some info. just console log it
// }
// }
}
})