The PayMaya Node SDK allows your Node.JS app to accept payments from your customers using any MasterCard and Visa enabled card (credit, debit, or prepaid).
npm install paymaya-node-sdk
To use your PayMaya Node SDK, you need to have a different API key for Sandbox and Production environment.
Sandbox credentials are useful for testing application integration. All transactions and money flow made in this environment are only simulated and does not reflect your production records. The following sandbox API key can be used for testing purposes:
Public-facing API Key: pk-TnpIh5X432Qw1DJLlMhzxRhBN4fvUp3SHPuHT3m5wv6
Secret API Key: sk-SNCvnXbvtAxU6mszPMoDl2M1d4e1ivko1E6PLGiOiqm
Upon successful integration testing, you can then request for production credentials. Upon receipt, just change your SDK initialization to use production environment to start accepting live transactions.
Public functions in Checkout, Payments, Customization and Webhook instances are executed asynchronously so you have to pass callback with two parameters for error and actual response. This is an example of callback:
var callback = function(err, response) {
if(err) {
console.log(err);
return;
}
console.log(JSON.stringify(response));
}
var sdk = require("paymaya-node-sdk");
var PaymayaSDK = sdk.PaymayaSDK;
PaymayaSDK.initCheckout(
<CHECKOUT_PUBLIC_FACING_API_KEY>,
<CHECKOUT_SECRET_API_KEY>,
PaymayaSDK.ENVIRONMENT.SANDBOX
);
If in Production, change environment to PaymayaSDK.ENVIRONMENT.PRODUCTION
var Checkout = sdk.Checkout;
var checkout = new Checkout();
- Initiate Checkout - Checkout service entry point. It returns a
checkoutId
, andredirectUrl
. Use theredirectUrl
to redirect the buyer to the Checkout page.
var YOUR_REQUEST_REFERENCE_NUMBER = "123456789";
var Checkout = sdk.Checkout;
var Contact = sdk.Contact;
var Address = sdk.Address;
var Buyer = sdk.Buyer;
var ItemAmountDetails = sdk.ItemAmountDetails;
var ItemAmount = sdk.ItemAmount;
var Item = sdk.Item;
var addressOptions = {
line1 : "9F Robinsons Cybergate 3",
line2 : "Pioneer Street",
city : "Mandaluyong City",
state : "Metro Manila",
zipCode : "12345",
countryCode : "PH"
};
var contactOptions = {
phone : "+63(2)1234567890",
email : "paymayabuyer1@gmail.com"
};
var buyerOptions = {
firstName : "John",
middleName : "Michaels",
lastName : "Doe"
};
var contact = new Contact();
contact.phone = contactOptions.phone;
contact.email = contactOptions.email;
buyerOptions.contact = contact;
var address = new Address();
address.line1 = addressOptions.line1;
address.line2 = addressOptions.line2;
address.city = addressOptions.city;
address.state = addressOptions.state;
address.zipCode = addressOptions.zipCode;
address.countryCode = addressOptions.countryCode;
buyerOptions.shippingAddress = address;
buyerOptions.billingAddress = address;
/**
* Construct buyer here
*/
var buyer = new Buyer();
buyer.firstName = buyerOptions.firstName;
buyer.middleName = buyerOptions.middleName;
buyer.lastName = buyerOptions.lastName;
buyer.contact = buyerOptions.contact;
buyer.shippingAddress = buyerOptions.shippingAddress;
buyer.billingAddress = buyerOptions.billingAddress;
var itemAmountDetailsOptions = {
shippingFee: "14.00",
tax: "5.00",
subTotal: "50.00"
};
var itemAmountOptions = {
currency: "PHP",
value: "69.00"
};
var itemOptions = {
name: "Leather Belt",
code: "pm_belt",
description: "Medium-sv"
};
var itemAmountDetails = new ItemAmountDetails();
itemAmountDetails.shippingFee = itemAmountDetailsOptions.shippingFee;
itemAmountDetails.tax = itemAmountDetailsOptions.tax;
itemAmountDetails.subTotal = itemAmountDetailsOptions.subTotal;
itemAmountOptions.details = itemAmountDetails;
var itemAmount = new ItemAmount();
itemAmount.currency = itemAmountOptions.currency;
itemAmount.value = itemAmountOptions.value;
itemAmount.details = itemAmountOptions.details;
itemOptions.amount = itemAmount;
itemOptions.totalAmount = itemAmount;
/**
* Contruct item here
*/
var item = new Item();
item.name = itemOptions.name;
item.code = itemOptions.code;
item.description = itemOptions.description;
item.amount = itemOptions.amount;
item.totalAmount = itemOptions.totalAmount;
// Add all items here
var items = [];
items.push(item);
var checkout = new Checkout();
checkout.buyer = buyer;
checkout.totalAmount = itemOptions.totalAmount;
checkout.requestReferenceNumber = YOUR_REQUEST_REFERENCE_NUMBER;
checkout.items = items;
checkout.execute(function (error, response) {
if (error) {
// handle error
} else {
// track response.checkoutId
// redirect to response.redirectUrl
}
});
- Retrieve Checkout - Use this call to get information about a checkout identified by a checkoutId.
checkout.retrieve(callback);
var PaymayaSDK = require("paymaya-node-sdk").PaymayaSDK;
PaymayaSDK.initCheckout(<CHECKOUT_PUBLIC_FACING_API_KEY>, <CHECKOUT_SECRET_API_KEY>, PaymayaSDK.ENVIRONMENT.SANDBOX);
If in Production, change environment to PaymayaSDK.ENVIRONMENT.PRODUCTION
var Customization = require("paymaya-node-sdk").Customization;
var customization = new Customization();
- Set Customization - Used to set a merchant's checkout page customization.
customization.logoUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/yourlogo.svg";
customization.iconUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon.ico";
customization.appleTouchIconUrl = "https://cdn.paymaya.com/production/checkout_api/customization_example/youricon_ios.ico";
customization.customTitle = "Checkout Page Title";
customization.colorScheme = "#368d5c";
customization.set(callback);
- Get Customization - Used to get a merchant's set checkout page customization.
customization.get(callback);
- Remove Customization - Used to remove a merchant's set checkout page customization.
customization.remove(callback);
var PaymayaSDK = require("paymaya-node-sdk").PaymayaSDK;
PaymayaSDK.initCheckout(<CHECKOUT_PUBLIC_FACING_API_KEY>, <CHECKOUT_SECRET_API_KEY>, PaymayaSDK.ENVIRONMENT.SANDBOX);
If in Production, change environment to PaymayaSDK.ENVIRONMENT.PRODUCTION
var Webhook = require("paymaya-node-sdk").Webhook;
var webhook = new Webhook();
- Set Webhook - Used to register an event-based webhook.
webhook.name = "CHECKOUT_SUCCESS"; // it can be CHECKOUT_SUCCESS or CHECKOUT_FAILURE
webhook.callbackUrl = "http://shop.someserver.com/success";
webhook.register(callback);
- Get Webhook - Used to retrieve the list of merchant registered webhooks.
webhook.retrieve(callback);
- Update Webhook - Used to update an existing event-based webhook.
webhook.name = "CHECKOUT_SUCCESS"; // it can be CHECKOUT_SUCCESS or CHECKOUT_FAILURE
webhook.callbackUrl = "http://shop.someserver.com/success_update";
webhook.update(callback);
- Remove Webhook - Used to delete an existing webhook. You cannot undo this action.
webhook.delete(callback);
- These docs in the SDK include an overview of usage, step-by-step integration instructions, and sample code.
- A sample app is included in the sample folder in the project.
- Checkout API Documentation and Payments API Documentation are currently available which cover error codes and server-side integration instructions.
- If you would like to contribute, please fork the repo and send in a pull request.