All Projects → naustudio → node-vn-payments

naustudio / node-vn-payments

Licence: Apache-2.0 license
Various VN Payment Gateways implemented for NodeJS

Programming Languages

javascript
184084 projects - #8 most used programming language
CSS
56736 projects
HTML
75241 projects

Projects that are alternatives of or similar to node-vn-payments

Midtrans Php
Official Midtrans Payment API Client for PHP | https://midtrans.com
Stars: ✭ 91 (-17.27%)
Mutual labels:  payment-gateway
Mpesa Php Sdk
A PHP sdk for the new Mpesa RESTful APIs
Stars: ✭ 134 (+21.82%)
Mutual labels:  payment-gateway
Test Payment Cards
Cheatsheet of test payment cards for various payment gateways
Stars: ✭ 217 (+97.27%)
Mutual labels:  payment-gateway
Whmcs Payment Gateway Alipay
A Simple Alipay payment gateway for WHMCS
Stars: ✭ 104 (-5.45%)
Mutual labels:  payment-gateway
J2pay
Multi-gateway payment processing library for java
Stars: ✭ 125 (+13.64%)
Mutual labels:  payment-gateway
Iso 8583 Socket Queue
ISO 8583 gateway
Stars: ✭ 141 (+28.18%)
Mutual labels:  payment-gateway
Woocommerce Gateway Offline
An offline gateway with the same functionality as the "cheque" gateway. Can be used for testing or another offline method if the check gateway is already in use.
Stars: ✭ 64 (-41.82%)
Mutual labels:  payment-gateway
Far-From-Home
A cross-platform mobile developed using Flutter and Firestore for House Rental Application with integrated payment module
Stars: ✭ 27 (-75.45%)
Mutual labels:  payment-gateway
Laravel Paddle
Paddle.com API integration for Laravel with support for webhooks/events
Stars: ✭ 132 (+20%)
Mutual labels:  payment-gateway
React Paystack
ReactJS library for implementing paystack payment gateway
Stars: ✭ 214 (+94.55%)
Mutual labels:  payment-gateway
Ovoid
Un-Official OVO API Wrapper
Stars: ✭ 121 (+10%)
Mutual labels:  payment-gateway
Sdk Dotnet
.Net SDK for Authorize.Net API
Stars: ✭ 124 (+12.73%)
Mutual labels:  payment-gateway
Manuals
Do design No code 💻📱🛒📚
Stars: ✭ 1,969 (+1690%)
Mutual labels:  payment-gateway
Adyen Php Api Library
Adyen API Library for PHP
Stars: ✭ 93 (-15.45%)
Mutual labels:  payment-gateway
Cashier Btc
💰 Self-hosted Bitcoin payment gateway (฿)
Stars: ✭ 223 (+102.73%)
Mutual labels:  payment-gateway
Openfintech
Opensource FinTech standards & payment provider data
Stars: ✭ 87 (-20.91%)
Mutual labels:  payment-gateway
Go Payment
Payment Connector for Midtrans and Xendit. Sample site that is using this payment proxy is https://imrenagi.com/donate
Stars: ✭ 136 (+23.64%)
Mutual labels:  payment-gateway
cryptopay-web
A payment gateway like Stripe for cryptocurrencies
Stars: ✭ 7 (-93.64%)
Mutual labels:  payment-gateway
Omnipay Pingpp
A Ping++ driver for the Omnipay PHP payment processing library. 一个聚合了支付宝(APP、Wap、PC、即时到账、扫码、企业付款),微信(APP、公众号、红包), 银联网关、银联企业网银、Apple Pay、QQ 钱包、易宝支付、百度钱包、京东支付、京东白条、招行一网通、分期支付等国内主流支付渠道的聚合支付网关(Ping++, also known as Pingpp/Pingxx/Pingplusplus)
Stars: ✭ 227 (+106.36%)
Mutual labels:  payment-gateway
Laravel Ebank
🤖 电商类站内虚拟积分与聚合支付解决方案
Stars: ✭ 192 (+74.55%)
Mutual labels:  payment-gateway

vn-payments

By Nau Studio Travis CI build status Code coverage status npm version GitHub license

Vietnam payment gateway helpers for NodeJS. Check out live demo here.

Thư viện hỗ trợ xây dựng URL tương tác với các cổng thanh toán trực tuyến ở Việt Nam.

From our experience doing NodeJS e-commerce website in Vietnam, implementing online payment process is often troublesome and error-prone due to strict hashing algorithm and uncertain remote request rejections. Besides, many payment gateways in Vietnam don't have sample code or SDK for server-side JavaScript (yet). Therefore, we have gathered a set of JavaScript classes (written in ES6) that help NodeJS apps exchange data with payment gateways with more confidence and ease by validating payload object and normalize multiple gateways specs into a common API.

Supported Payment Gateways

Các cổng thanh toán đang được hỗ trợ

Planned gateways:

Các cổng thanh toán dự định hỗ trợ:

  • 123Pay (chúng tôi chưa có tài liệu tích hợp, bạn có thể giúp?)
  • AlePay (AlePay chỉ hỗ trợ phương thức recurrent/subscription)

Install

# npm
npm install vn-payments --save
# yarn
yarn add vn-payments

Usage

Payment Workflow:

Below is sequence diagram of typical payment gateway process:

Bên dưới là sequence diagram minh họa quy trình thanh toán trực tuyến tiêu biểu:

Typical payment gateway process

Diagram taken from OnePay Intl documentation

vn-payments provides helper classes that build URL for DO request and verify DR Response for supported payment gateway.

Currently we haven't implemented the QueryQR() functions. It is in our road map for next release.

vn-payments cung cấp các class giúp xây dựng URL với tham số mã hóa để thực hiện "DO request" và giúp kiểm tra "DR Response" trả về từ cổng thanh toán.

Hiện tại chúng tôi chưa hiện thực chức năng "QueryDR".

JavaScript sample code:

Import one of the payment gateway class from vn-payments:

Đầu tiên, import các class hỗ trợ thanh toán:

// ESM
import { OnePayDomestic } from 'vn-payments';
import { OnePayInternational } from 'vn-payments';
import { VNPay } from 'vn-payments';
import { SohaPay } from 'vn-payments';
import { NganLuong } from 'vn-payments';
// CommonJS
const { OnePayDomestic } = require('vn-payments');
const { OnePayInternational } = require('vn-payments');
const { VNPay } = require('vn-payments');
const { SohaPay } = require('vn-payments');
const { NganLuong } = require('vn-payments');

Instantiate the helper with merchant configs provided from the payment provider:

Tiếp theo, khởi tạo instance của các class thanh toán với thông tin thiết lập dành riêng cho merchant được cung cấp bởi cổng thanh toán:

const onepayIntl = new OnePayInternational({
  paymentGateway: 'https://mtf.onepay.vn/vpcpay/vpcpay.op',
  merchant: 'TESTONEPAY',
  accessCode: '6BEB2546',
  secureSecret: '6D0870CDE5F24F34F3915FB0045120DB',
});

Build checkout URL by passing checkout data to buildCheckoutUrl method. The checkout data is a structured object and will be validated with GatewayClass.checkoutSchema which is an instance of simpl-schema.

Checkout URL is an instance of so-called WHATWG URL, which assist parsing URL string into parts.

Then, redirect client to payment gateway's checkout handler:

Xây dựng URL chuyển đến cổng thanh toán bằng hàm buildCheckoutUrl. Dữ liệu truyền vào là một object có cấu trúc được định nghĩa sẵn bởi thư viện và sẽ được kiểm tra hợp lệ bởi GatewayClass.checkoutSchema. Hàm buildCheckoutUrl sẽ trả về Promise bất đồng bộ, khi hoàn tất, sẽ trả về một WHATWG URL. Sau khi có được URL checkout, redirect trình duyệt của khách qua URL này:

routes.post('/payment/checkout', (req, res) => {
  const params = Object.assign({}, req.body);

  // construct checkout payload from form data and app's defaults
  const checkoutData = {
    amount: parseInt(params.amount, 10),
    customerId: params.email,
    currency: 'VND',
    /*...*/
  };

  // buildCheckoutUrl is async operation and will return a Promise
  onepayIntl
    .buildCheckoutUrl(checkoutData)
    .then(checkoutUrl => {
      res.writeHead(301, { Location: checkoutUrl.href });
      res.end();
    })
    .catch(err => {
      res.send(err);
    });
});

Finally, handle payment gateway callback. One of the requirements is that the callback query parameters must be validated with the checksum sent along:

Cuối cùng, bạn sẽ cần xử lý URL callback từ cổng thanh toán. Một trong các yêu cầu đó là các tham số trong URL query trả về phải được kiểm tra tính hợp lệ với chuỗi mã hóa đính kèm:

routes.get('/payment/callback', (req, res) => {
  const query = req.query;

  onepayIntl.verifyReturnUrl(query).then(results => {
    if (results.isSucceed) {
      res.render('success', {
        title: 'Nau Store - Thank You',
        orderId: results.orderId,
        price: results.price,
        message: results.message,
      });
    } else {
      res.render('errors', {
        title: 'Nau Store - Payment Errors',
        message: results.message,
      });
    }
  });
});

For IPN Request to Website's Back End from Gateway server, implement another route handler according Gateway documentation and use the verifyReturnUrl to validate parameters sent from Gateway.

Về việc xử lý IPN Request gửi trực tiếp đến backend của trang bán hàng, bạn cần hiện thực một route handler theo tài liệu hướng dẫn của cổng thanh toán và sử dụng lại hàm verifyReturnUrl để kiểm tra tính hợp lệ của request gửi từ cổng thanh toán.

Example (Live Demo)

See the Express checkout cart in the example folder.

Example Getting Started:

  • Clone this repository.
  • Run npm install in example folder
  • Inside example folder, execute: npm start

Test cards for testing out example:

See testing cards info in CONTRIBUTING.md

API Document

See documentation.

Contributing

Interested in contributing to this project? See CONTRIBUTING.md

Road Map

  • Implement buildCheckoutUrl (A.K.A. DO Request) for OnePay, VNPay, SohaPay, NganLuong
  • Implement verifyReturnUrl (A.K.A. DR Response) for OnePay, VNPay, SohaPay, NganLuong
  • Implement queryDR methods for existing gateways
  • Implement helper class for AlePay
  • Implement helper class for 123Pay

FAQ

[TBC]

Thanks

  • Express starter kit for the checkout cart example.
  • Vietnam payment gateway's developers who worked with Nau Studio in preliminary projects that allows us make sure this code work.

License

Copyright 2019 Nau Studio https://naustud.io

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].