Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

allpay

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

allpay

AllPay 全方位金流介接 SDK for Node.js

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

AllPay 全方位金流介接 SDK for Node.js

NPM version Build Status

NPM status

安裝方式

建議使用 Node.js 套件管理工具 npm 安裝。

$ npm install allpay

使用方式

初始化

安裝完畢後,你可以使用 require 載入套件:

var Allpay = require("allpay");
var allpay = new Allpay({
  merchantID: "YOUR_MERCHANT_ID",
  hashKey: "YOUR_HASH_KEY",
  hashIV: "YOUR_HASH_IV",
  mode: "test",
  debug: false
});

merchantID必填,廠商編號(由 AllPay 提供)。

hashKey必填,全方位金流介接的 HashKey。

hashIV必填,全方位金流介接的 HashIV。

mode選填,於生產環境使用時請設定為 "production"(預設為 "test")。

debug選填,設為 true 可查看除錯訊息(預設為 false)。

設定連線(非必要)
allpay.setHost({
  baseUrl: "payment-stage.allpay.com.tw",
  port: 80,
  useSSL: false
});

baseUrl選填,介接網址(預設為 payment.allpay.com.tw)。

port選填,連接埠(預設為 443)。

useSSL選填,使用 SSL 連線(預設為 true)。

支援以下功能

訂單產生
  • allpay.aioCheckOut(options, callback)
訂單查詢
信用卡定期定額訂單查詢
信用卡關帳/退刷/取消/放棄
廠商通知退款
廠商申請撥款/退款
產生交易檢查碼
驗證資料正確性

使用範例

訂單產生
  • 一般交易
allpay.aioCheckOut({
  MerchantTradeNo: "TS20160502000001",
  MerchantTradeDate: "2016/05/02 00:00:00",
  TotalAmount: 100,
  TradeDesc: "商城購物測試",
  Items: [{
    name: "商品一",
    quantity: "1",
    price: 100
  }],
  ReturnURL: "http://localhost/receive",
  ChoosePayment: "ALL"
}, function(err, result) {
  // Do something here...
});
  • 一般交易(含電子發票)
allpay.aioCheckOut({
  MerchantTradeNo: "TS20160502000001",
  MerchantTradeDate: "2016/05/02 00:00:00",
  TotalAmount: 100,
  TradeDesc: "商城購物測試",
  Items: [{
    name: "商品一",
    quantity: "1",
    price: 100
  }],
  ReturnURL: "http://localhost/receive",
  ChoosePayment: "ALL",
  InvoiceMark: "Y",
  RelateNumber: "TS20160502000001",
  CustomerEmail: "test@localhost.com",
  TaxType: "1",
  InvoiceItems: [{
    name: "商品一",
    count: "1",
    word: "個",
    price: "100",
    taxType: "1"
  }],
  InvType: "07"
}, function(err, result) {
  // Do something here...
});
  • 信用卡定期定額
allpay.aioCheckOut({
  MerchantTradeNo: "TS20160502000001",
  MerchantTradeDate: "2016/05/02 00:00:00",
  TotalAmount: 100,
  TradeDesc: "商城購物測試",
  Items: [{
    name: "商品一",
    quantity: "1",
    price: 100
  }],
  ReturnURL: "http://localhost/receive",
  ChoosePayment: "Credit",
  PeriodAmount: 100,
  PeriodType: "M",
  Frequency: 1,
  ExecTimes: 6,
}, function(err, result) {
  // Do something here...
});

訂單查詢
allpay.queryTradeInfo({
  MerchantTradeNo: "TS20160502000001"
}, function(err, result) {
  // Do something here...
});

信用卡定期定額訂單查詢
allpay.queryCreditCardPeriodInfo({
  MerchantTradeNo: "TS20160502000001"
}, function(err, result) {
  // Do something here...
});

信用卡關帳/退刷/取消/放棄
allpay.doAction({
  MerchantTradeNo: "TS20160502000001",
  TradeNo: "1605020000459168",
  Action: "C",
  TotalAmount: "100",
}, function(err, result) {
  // Do something here...
});

廠商通知退款
allpay.aioChargeback({
  MerchantTradeNo: "TS20160502000001",
  TradeNo: "1605020000459168",
  ChargeBackTotalAmount: "100",
}, function(err, result) {
  // Do something here...
});

廠商申請撥款/退款
allpay.capture({
  MerchantTradeNo: "TS20160502000001",
  CaptureAMT: 100,
  UserRefundAMT: 0,
}, function(err, result) {
  // Do something here...
});

產生交易檢查碼
var checkMacValue = allpay.genCheckMacValue({
  MerchantID: "2000214",
  MerchantTradeNo: "TS20160502000001",
  MerchantTradeDate: "2016/05/02 00:00:00",
  PaymentType: "aio",
  TotalAmount: 100,
  TradeDesc: "商城購物測試",
  ItemName: "商品一 100 元 x1",
  ReturnURL: "http://localhost/receive",
  ChoosePayment: "ALL",
  NeedExtraPaidInfo: "N",
  DeviceSource: "P",
});

驗證資料正確性
var isDataValid = allpay.isDataValid({
  HandlingCharge: "5",
  ItemName: "商品一 100 元 x1",
  MerchantID: "2000214",
  MerchantTradeNo: "TS20160502000001",
  PayAmt: "0",
  PaymentDate: "2016/05/02 00:01:23",
  PaymentType: "Credit_CreditCard",
  PaymentTypeChargeFee: "5",
  RedeemAmt: "0",
  TradeAmt: "100",
  TradeDate: "2016/05/02 00:00:00",
  TradeNo: "1605020000459168",
  TradeStatus: "1",
  CheckMacValue: "ABE4DDCB8F9895B7FD33858EFB095422"
});

Callback

Callback 會返回 2 個參數,分別為 error 和一個 JSON 物件。

以下為範例 callback 函數:

function callback (err, response) {
  if (err) {
    console.log(err);
  } else {
    console.dir(response);
  }
}

詳細參數說明請參閱全方位金流API介接技術文件

License

MIT

Analytics

Keywords

FAQs

Package last updated on 02 May 2016

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc