New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

alphapay

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

alphapay

Node.js implementation for alphapay

latest
Source
npmnpm
Version
0.2.4
Version published
Maintainers
1
Created
Source

build npm downloads

Overview

Node.js implementation for alphapay

See official doc

Install

npm i -S alphapay

Example

Generate payment url

Create an Alphapay instance

const alphapay = new Alphapay(PARTNER_CODE, CREDENTIAL_CODE);

Create a QR Code payment

const resp = await alphapay.createQRCodePayment("your-order-id", {
  description: 'Developer Test',
  price: Number((total * 100)).toFixed(0), // price should be an integer of the base unit of the currency 
  currency: CurrencyType.CAD, // CAD or CNY
  notify_url: "https://your.domain.backend/api/alphapay-success",
  channel: ChannelType.WECHAT // ALIPAY or UNION_PAY, some channel might not be available for different payment gateways
});

Handle alphapay response

if (resp.return_code != 'SUCCESS') {
  // handle exception
  return;
}
const redirectUrl = alphapay.getQRCodePaymentPageUrl("your-order-id", `https://your.domain.frontend/payment-success?orderId=your-order-id`);

Pass redirectUrl to the frontend

Redirect browser to the payment page

Redirect the page to the url generated in the backend:

window.location.href = redirectUrl;

Handle success notification in backend

Alphapay will post SuccessNotification up to 3 times to notify_url when payment succceeds.

const notification: SuccessNotification = req.body;
if (!alphapay.isNotificationValid(notification)) {
  // you can ignore validation for some alphapay apis
  // https://www.alphapay.com/api/CAD_en.html#PaymentSuccessPage
  // handle exception
  return;
}
const orderId = notification.partner_order_id; // your-order-id
const alphaOrder = await alphapay.getOrderStatus(orderId);
// IMPORTANT: your backend should be able to handle the repeated success notifications
doSomethingElseInYourBackend(orderId, alphaOrder);

Check payment status in redirectUrl

In redirectUrl you may want to check if SuccessNotification is properly handled in your backend.

For more info, see test file and live demo

Keywords

alphapay

FAQs

Package last updated on 19 Jun 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts