npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tendopay

v1.0.0

Published

TendoPay JavaScrip API Integration

Downloads

2

Readme

TendoPay SDK for Node

TendoPay Client SDK to integrate the TendoPay payment solution with your own Ecommerce.


Requirements

Features

  • Make a purchase and securely and redirect the payment to the TendoPay platform.
  • Get purchase information as a callback.

Installation

npm install tendopay --save

Or

yarn add tendopay

Identify your E-Commerce by adding the following to your .env

## Merchant and client Credentials
## For sandbox API credentials login to: https://sandbox.tendopay.ph/merchants/login
## For Production API Credentials login to: https://app.tendopay.ph/merchants/login
MERCHANT_ID=
MERCHANT_SECRET=
CLIENT_ID=
CLIENT_SECRET=

## Redirect URI when the transaction succeeds
REDIRECT_URL=

## Redirect URI when the transaction fails
ERROR_REDIRECT_URL=

## To enable sandbox mode uncomment SANDBOX_HOST_URL
#SANDBOX_HOST_URL=https://sandbox.tendopay.ph


#API
## to generate token for sandbox login to: https://sandbox.tendopay.ph/merchants/login
## to generate token for production to: https://app.tendopay.ph/merchants/login
MERCHANT_PERSONAL_ACCESS_TOKEN=

Usage

Make sure to properly handle Promise rejections in the following implementations

Setup

Start by creating the TendoPayClient that you will later use to communicte with the TendoPay platform.

const tendopay = require('tendopay');

const TendoPayClient = tendopay.Client;
const tendoPayClient = new TendoPayClient();

1. Make a purchase

To redirect the user to the TendoPay platform with the proper credentials and purchase information, you need to generate the unique TendoPayURL hash.

Payment(...) is a method from the root module, and returns an instance of a TendoPay Payment that will be used below to generate the URL. getTendoPayURL(...) is an async method from the TendoPayClient, and returns the generated URL from the latter's payment property.

  • Example Implementation
const orderId = '#123123123123';
const orderPrice = 999;
const orderAmount = +orderPrice;
const orderTitle = 'Test Order #1';

const tendoPayPayment = new tendopay.Payment({
  orderId,
  requestAmount: orderAmount,
  description: orderTitle
});

tendoPayClient.payment = tendoPayPayment;

redirect(await tendoPayClient.getTendoPayURL());

2. Handle the TendoPay callback

Once the TendoPay platform has handled the payment request, it will redirect to your website with a callback. You should add a handler for that callback in the REDIRECT_URL GET route specified in your .env.

isCallbackRequest(...) is a method from the TendoPayClient, and will assert if the received GET request is legitimate. verifyTransaction(...) is an async method from the TendoPayClient, and will make sure the request you POSTed to the TendoPay platform, and the response you received are aligned. VerifyTransactionRequest(...) is a method from the root module, and creates a request instance readable by the TendoPay API.

  • Example Implementation
if (TendoPayClient.isCallbackRequest({request: req})) {
  const transaction = await tendoPayClient.verifyTransaction({
    merchantOrderId,
    verificationRequest: new tendopay.VerifyTransactionRequest({
      requestParams: req.query
    })
  });

  res.json({
    success: transaction.isVerified(),
    query: req.query
  });
} else {
  res.json({
    error: 'Not a callback request'
  });
}

3. Notify the TendoPay platform about the purchase

When you have received and processed the TendoPay response, you need to let the platform know the status of the purchase.

NotifyRequest(...) is a method from the root module, and will create a TendoPay ready request instance. getTransactionDetail(...) is an async method from the TendoPayClient and will return the information you need about the payment.

  • Example Implementation
const {transactionNumber} = new tendopay.NotifyRequest(req.body);
const {merchantId, merchantOrderId, amount, status} =
await tendoPayClient.getTransactionDetail(transactionNumber);

console.log({merchantId, merchantOrderId, amount, status});
// Search Merchant side transaction by merchantOrderId
// Check if the transaction is already processed
// The process should stop here if this transaction is already done.
// return 200 if this is a duplicated notification

switch (status) {
case tendopay.Constants.values.PURCHASE_TRANSACTION_SUCCESS:
  // The transaction is successfully completed
  // Do merchant job here
  break;
  case tendopay.Constants.values.PURCHASE_TRANSACTION_FAILURE:
  // The transaction is unsuccessfully completed.
  // Do merchant job here
  break;
  case tendopay.Constants.values.CANCEL_TRANSACTION_SUCCESS:
  // the previous transaction is successfully cancelled
  // Do merchant job here
  break;
}

res.status(200).json();

4. Request a cancellation of the purchase

If a purchase is eligible (see terms & conditions), you can use the Javascript SDK to request its cancellation.

cancelTransaction(...) is an async method from the TendoPayClient, and will request the cancellation from the TendoPay platform provided a transaction ID.

  • Example Implementation
const transactionNumber = 'TEST-OID-123324567890';
const {status, message} = await tendoPayClient.cancelTransaction({ transactionNumber });

console.log({status, message});

switch (status) {
  case 200:
  // The transaction has been successfully cancelled
  // Do merchant job here
  break;
  default:
  // There was an issue cancelling the transaction
  // Do merchant job here
  break;
}

FAQ

I'm having issues using the SDK, where can I get support ?

Help! I can't find the credentials for the .env file ?

Can I use this SDK on the client side ?

  • The TendoPay SDK should ONLY be used on the server side. Revealing your merchant credentials to the public might endanger your merchant account by allowing people to hack and create fake purchases.

I'm a bit lost, can I get an example ?