项目作者: yozian

项目描述 :
智付通API串接
高级语言: JavaScript
项目地址: git://github.com/yozian/spgateway.git
创建时间: 2018-01-09T13:44:50Z
项目社区:https://github.com/yozian/spgateway

开源协议:

下载


" class="reference-link">智付通API

簡化實作智付通付款流程與相關功能串接


已實作功能

範例

MPG Service

  • 付款(建立付款表單)
  1. const SpGateway = require("spgateway-api");
  2. const spgateway = new SpGateway(
  3. true, //(true for a dry run)
  4. your MerchantID,
  5. your HashKey,
  6. your HashIV,
  7. true // if you want to print info in console to debug. default is false
  8. );
  9. const mpgService = spgateway.createMpgService();
  10. // crate payModel
  11. let payModel = mpgService.createMpgPayModel();
  12. // set properties
  13. payModel.MerchantOrderNo = "myordernohere";
  14. payModel.NotifyURL = "http://mysite.com/api/spgateway/notify";
  15. payModel.ReturnURL = "http://mysite.com/api/spgateway/return";
  16. payModel.ClientBackURL = "http://mysite.com/shop";
  17. payModel.Amt = 928;
  18. payModel.ItemDesc = "ProductX";
  19. // create payform
  20. let payFormHtml = mpgService.getAutoPayForm(payModel);
  • 接收通知(notify & return)
  1. // take express request as example
  2. let JSONData = request.body.JSONData;
  3. mpgService
  4. .parseNotification(JSONData)
  5. .then((notify) => {
  6. // update your order here
  7. })
  8. .catch((err) => {
  9. // exception or checkCode validation fails
  10. })

Period Service (定期定額)

  • 付款(建立付款表單)
  1. let periodService = spgateway.createPeriodicalService();
  2. let payModel = periodService.createPeriodicalPayModel();
  3. // set properties
  4. payModel.PeriodAmt = 829;
  5. // create pay form html
  6. let payFormHtml = periodService.getAutoPayForm(payModel);
  • 接收通知(notify & return)
  1. // take express request as example
  2. let body = request.body; // it would be { "Period": "xxxxx..." }
  3. periodService
  4. .parseNotification(body)
  5. .then((notify) => {
  6. // update your order here
  7. })
  8. .catch((err) => {
  9. // exception or checkCode validation fails
  10. })

交易查詢

  1. let tradeInfoService = spgateway.createTradeInfoService();
  2. tradeInfoService.queryOrder("yourOrderNoHere", 200)
  3. .then((model) => {
  4. // success
  5. })
  6. .catch((err) => {
  7. // if check value validation fails or exception
  8. })

信用卡取消授權

  1. let cardCancelService = spgateway.createCreditCardCancelService();
  2. cardCancelService
  3. .CancelTransaction("yourOrderNoHere", 200)
  4. .then((model) => {
  5. // success
  6. })
  7. .catch((err) => {
  8. // if status !== success or exception
  9. })

信用卡請/退款

  1. let cardloseService = spgateway.createCreditCardCloseService();
  2. // 請款
  3. cardloseService
  4. .requestPayment("yourOrderNoHere", 200)
  5. .then((model) => {
  6. })
  7. .catch((err) => {
  8. })
  9. // 退款
  10. cardloseService
  11. .refund("yourOrderNoHere", 200)
  12. .then((model) => {
  13. })
  14. .catch((err) => {
  15. })

Debug Logger

  1. const spgateway = new SpGateway(
  2. true, //(true for a dry run)
  3. your MerchantID,
  4. your HashKey,
  5. your HashIV,
  6. true // if you want to print info to debug, default is false
  7. );

關於

歡迎 fork & pull request