项目作者: calvertyang

项目描述 :
智付通(Spgateway)API 包裝
高级语言: Ruby
项目地址: git://github.com/calvertyang/spgateway.git
创建时间: 2017-02-17T02:00:34Z
项目社区:https://github.com/calvertyang/spgateway

开源协议:MIT License

下载


Gem Version
Build Status

智付通 Spgateway

這是智付通 API 的 Ruby 包裝,更多資訊請參閱 API 文件專區

  • 這不是 Rails 插件,只是個 API 包裝。
  • 使用時只需要傳送需要的參數即可,不用產生檢查碼,spgateway_client 會自己產生。
  • 感謝大兜撰寫的 allpay

安裝

  1. gem install spgateway_client

使用

  1. test_client = Spgateway::Client.new({
  2. merchant_id: 'MERCHANT_ID',
  3. hash_key: 'HASH_KEY',
  4. hash_iv: 'HASH_IV',
  5. mode: :test
  6. })
  7. production_client = Spgateway::Client.new({
  8. merchant_id: 'MERCHANT_ID',
  9. hash_key: 'HASH_KEY',
  10. hash_iv: 'HASH_IV'
  11. })
  12. test_client.query_trade_info({
  13. MerchantOrderNo: '4e19cab1',
  14. Amt: 100
  15. })

本文件撰寫時,智付通共有 5 個 API:

API 名稱 版本 說明
MPG API 1.0.3 MPG(Multi Payment Gateway),單一串接多種支付方式。
透過 MPG API 可串接平台提供的所有支付方式。
交易查詢 API 1.0.1 透過交易查詢 API 可自動化查核所有交易是否同步更新付款資訊。
信用卡-取消授權 API 1.0.0 透過取消授權 API,可進行信用卡交易授權取消,以返還持卡人及商店信用卡額度。
信用卡-請退款 API 1.0.0 透過請退款 API,可進行信用卡交易的請退款。
信用卡-定期定額 API 1.0.6 透過信用卡定期定額 API,可進行信用卡定期定額交易。

詳細 API 參數請參閱智付通技術串接手冊,注意幾點:

  • 使用時不用煩惱 MerchantIDRespondTypeCheckValueTimeStampVersion,正如上述範例一樣。
  • MPG/信用卡-定期定額 API 回傳的內容是 HTML,這個請求應該是交給瀏覽器發送的。

Spgateway::Client

實體方法 回傳 說明
verify_check_code(params) Boolean 用於檢查收到的參數,其檢查碼是否正確,用於智付通的 NotifyURL 參數及檢核資料回傳的合法性。
generate_mpg_params(params) Hash 用於產生 MPG API 表單需要的參數。
query_trade_info(params) Hash 用於查詢交易狀態。
credit_card_deauthorize(params) Hash 用於進行信用卡交易授權取消作業。
credit_card_deauthorize_by_merchant_order_no(params) Hash credit_card_deauthorize 的捷徑方法,將 IndexType 設為 1
credit_card_deauthorize_by_trade_no(params) Hash credit_card_deauthorize 的捷徑方法,將 IndexType 設為 2
credit_card_collect_refund(params) Hash 用於進行信用卡交易的請退款作業。
credit_card_collect_refund_by_merchant_order_no(params) Hash credit_card_collect_refund 的捷徑方法,將 IndexType 設為 1
credit_card_collect_refund_by_trade_no(params) Hash credit_card_collect_refund 的捷徑方法,將 IndexType 設為 2
generate_credit_card_period_params(params) Hash 用於產生信用卡-定期定額 API 表單需要的參數。

使用範例

MPG、信用卡-定期定額
  1. git clone git@github.com:CalvertYang/spgateway.git
  2. cd spgateway
  3. bundle install
  4. ruby examples/server.rb
交易狀態查詢
  1. result = test_client.query_trade_info({
  2. MerchantOrderNo: '4e19cab1',
  3. Amt: 100
  4. })
  5. puts "Result: #{result}"
  6. puts "Valid?: #{@client.verify_check_code(result)}"
信用卡-取消授權模組
  1. result = test_client.credit_card_deauthorize({
  2. TradeNo: '16010112345678901',
  3. Amt: 100,
  4. IndexType: 1
  5. })
  6. puts "Result: #{result}"
  7. puts "Valid?: #{@client.verify_check_code(result)}"
  1. result = test_client.credit_card_deauthorize_by_merchant_order_no({
  2. MerchantOrderNo: '4e19cab1',
  3. Amt: 100
  4. })
  5. puts "Result: #{result}"
  6. puts "Valid?: #{@client.verify_check_code(result)}"
  1. result = test_client.credit_card_deauthorize_by_trade_no({
  2. TradeNo: '16010112345678901',
  3. Amt: 100
  4. })
  5. puts "Result: #{result}"
  6. puts "Valid?: #{@client.verify_check_code(result)}"
信用卡-請退款模組
  1. result = test_client.credit_card_collect_refund({
  2. MerchantOrderNo: '4e19cab1',
  3. Amt: 100,
  4. CloseType: 2,
  5. IndexType: 1
  6. })
  7. puts "Result: #{result}"
  1. result = test_client.credit_card_collect_refund_by_merchant_order_no({
  2. MerchantOrderNo: '4e19cab1',
  3. Amt: 100,
  4. CloseType: 2
  5. })
  6. puts "Result: #{result}"
  1. result = test_client.credit_card_collect_refund_by_trade_no({
  2. TradeNo: '16010112345678901',
  3. Amt: 100,
  4. CloseType: 2
  5. })
  6. puts "Result: #{result}"

License

MIT

Analytics