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.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
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-stage.allpay.com.tw)

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

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

取得目前設定
var config = allpay.getConfig();

訂單產生

商品參數設定:

Items: [{
  name: "商品名稱",
  price: 商品單價,
  currency: "幣別單位",
  quantity: 商品數量
}]

發票商品內容參數設定:

InvoiceItems: [{
  name: "商品名稱",
  count: 商品數量,
  word: "商品單位",
  price: 商品單價,
  taxType: "商品課稅別"
}]

額外可用參數:

paymentButton選填,表單按鈕要顯示的文字。(若沒有設定此參數,所產生的表單會包含自動送出的語法)

  • 一般交易
allpay.aioCheckOut({
  MerchantTradeNo: "TS20160502000001",
  MerchantTradeDate: "2016/05/02 00:00:00",
  TotalAmount: 100,
  TradeDesc: "商城購物測試",
  Items: [{
    name: "商品一",
    price: 100,
    currency: "元",
    quantity: 1
  }],
  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: "商品一",
    price: 100,
    currency: "元",
    quantity: 1
  }],
  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: "商品一",
    price: 100,
    currency: "元",
    quantity: 1
  }],
  ReturnURL: "http://localhost/receive",
  ChoosePayment: "Credit",
  PeriodAmount: 100,
  PeriodType: "M",
  Frequency: 1,
  ExecTimes: 6,
}, function(err, result) {
  // Do something here...
});
  • 回應內容
{
  url: 'https://payment-stage.allpay.com.tw/Cashier/AioCheckOut/V2',
  data: {
    MerchantID: '2000214',
    MerchantTradeNo: 'TS20160502000001',
    MerchantTradeDate: '2016/05/02 00:00:00',
    PaymentType: 'aio',
    TotalAmount: 100,
    TradeDesc: '商城購物測試',
    ItemName: '商品一 100 元 x 1',
    ReturnURL: 'http://localhost/receive',
    ChoosePayment: 'ALL',
    CheckMacValue: '5D6D710C359E8ACC20069C2FFFE34F24'
  },
  html: '<form id="_allpayForm" method="post" target="_self" action="https://payment-stage.allpay.com.tw/Cashier/AioCheckOut/V2"><input type="hidden" name="MerchantID" value="2000214" /><input type="hidden" name="MerchantTradeNo" value="TS20160502000001" /><input type="hidden" name="MerchantTradeDate" value="2016/05/02 00:00:00" /><input type="hidden" name="PaymentType" value="aio" /><input type="hidden" name="TotalAmount" value="100" /><input type="hidden" name="TradeDesc" value="商城購物測試" /><input type="hidden" name="ItemName" value="商品一 100 元 x 1" /><input type="hidden" name="ReturnURL" value="http://localhost/receive" /><input type="hidden" name="ChoosePayment" value="ALL" /><input type="hidden" name="CheckMacValue" value="5D6D710C359E8ACC20069C2FFFE34F24" /><script type="text/javascript">document.getElementById("_allpayForm").submit();</script></form>'
}

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

回應內容

{
  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'
}

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

回應內容

{
  ExecStatus: '1',
  MerchantID: '2000214',
  MerchantTradeNo: 'TS20160502000001',
  TradeNo: '1605020000459168',
  RtnCode: 1,
  PeriodType: 'M',
  Frequency: 1,
  ExecTimes: 6,
  PeriodAmount: 100,
  amount: 100,
  gwsr: 10530824,
  process_date: '2016/05/02 00:01:23',
  auth_code: '777777',
  card4no: '2222',
  card6no: '431195',
  TotalSuccessTimes: 1,
  TotalSuccessAmount: 100,
  ExecLog: [{
    RtnCode: 1,
    amount: 100,
    gwsr: 10530824,
    process_date: '2016/05/02 00:01:23',
    auth_code: '777777'
  }]
}

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

回應內容

{
  MerchantID: '2000214'
  MerchantTradeNo: 'TS20160502000001',
  TradeNo: '1605020000459168',
  RtnCode: '1',
  RtnMsg: 'OK'
}

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

回應內容

{
  status: '1',
  message: 'OK'
}

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

回應內容

{
  MerchantID: '2000214',
  MerchantTradeNo: 'TS20160502000001',
  TradeNo: '1605020000459168',
  RtnCode: '1',
  RtnMsg: 'OK',
  AllocationDate: '2016-05-05'
}

產生交易檢查碼

encryptType選填,加密類型 (預設為 MD5)

  • MD5 加密
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",
});
  • SHA256 加密
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",
}, "SHA256");

驗證資料正確性

encryptType選填,加密類型 (預設為 MD5)

  • 使用 MD5 加密來驗證資料
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"
});
  • 使用 SHA256 加密來驗證資料
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: "2DF1D23B841F2C8E9816F675A3FC6C77B92A92EC78E9BCF898B0C77ADF39DD7D"
}, "SHA256");

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 04 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