0.1.2 • Published 2 months ago

paymaya-node-sdk v0.1.2

Weekly downloads
11
License
ISC
Repository
-
Last release
2 months ago

PayMaya-Node-SDK

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).

Code Climate

Dependencies

Tests:

Installation

npm install paymaya-node-sdk

Prerequisites

API Keys

To use your PayMaya Node SDK, you need to have a different API key for Sandbox and Production environment.

Sandbox 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
Production Environment

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.

Usage

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));
}

Checkout

1. Initiate SDK
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

2. Create Checkout object
var Checkout = sdk.Checkout;
var checkout = new Checkout();
3. Execute Checkout API
  • Initiate Checkout - Checkout service entry point. It returns a checkoutId, and redirectUrl. Use the redirectUrl 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);

Customization

1. Initiate SDK
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

2. Create Customization object
var Customization = require("paymaya-node-sdk").Customization;
var customization = new Customization();
3. Execute Customization API
  • 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);

Webhook

1. Initiate SDK
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

2. Create Webhook object
var Webhook = require("paymaya-node-sdk").Webhook;
var webhook = new Webhook();
3. Execute Webhook API
  • 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);

Summary

  • 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.

Contribution

  • If you would like to contribute, please fork the repo and send in a pull request.
0.1.2

2 months ago

0.1.0

8 years ago

0.0.1

8 years ago