项目作者: ZneuRay

项目描述 :
Ruby on Rails的智付通信用卡定期定額扣款Gem
高级语言: Ruby
项目地址: git://github.com/ZneuRay/spgateway_rails.git


SpgatewayRails

Ruby on Rails的智付通信用卡定期定額扣款Gem,相關API文件請參考信用卡定期定額API

版本更新

0.7.0

  • 更新藍新金流API串接網址

0.6.0

  • 新增交易狀態查詢

0.5.2

  • 修正spgateway_periodical_formspgateway_mpg_form參數錯誤問題

0.5.1

  • 新增平台商店修改

0.5.0

  • 新增平台商店建立

0.4.0

  • 因智付通定期定額付款日期無法自行判斷,造成當月不存在該日期時將無法自動扣款,例如設定每月31日自動扣款,則無31日的月份將不會進行扣款,因此將超過28日的日期都調整至28日

0.2.0

  • 新增智付通MPG付款

0.1.0

  • 新增智付通定期定額付款功能

安裝

將此行加入你的 Gemfile:

  1. gem 'spgateway_rails', git: https://github.com/ZneuRay/spgateway_rails.git

然後執行:

  1. $ bundle install

設定

  1. 先到智付通網站註冊帳號並取得MerchantIDHashKeyHashIV,連結可參考下方
  2. 在你的專案建立config/initializers/spgateway.rb並加入設定
  1. SpgatewayRails.configure do |config|
  2. config.merchant_id = ''
  3. config.hash_key = ''
  4. config.hash_iv = ''
  5. config.mode = :development
  6. end

開始使用

條件設定

  • controller中設定你需要的付款條件,各參數請參考智付通API
  1. spgateway_periodical.setup do |p|
  2. p["ProdDesc"] = "月租費"
  3. p["PeriodAmt"] = 1000
  4. end
  • 各個必填的參數都有預設值(請參考下方),建議至少修改ProdDescPeriodAmt,如需回傳資料請加入NotifyURLReturnURL,其它需要修改再自行填入
  1. RespondType : 'String'
  2. TimeStamp : (timestamp)
  3. Version : '1.0'
  4. MerOrderNo : (timestamp in macroseconds 16位數)
  5. PeriodAmt : 1000
  6. PeriodType : 'M'
  7. PeriodStartType : 2
  8. PeriodTimes : 60
  9. PeriodPoint : (今天)
  • 當你修改PeriodType後可使用下方指令自動幫你產生對應PeriodType格式的今天日期
  1. spgateway_periodical.reset_period_point

產生付款Form

信用卡定期定額扣款透過對智付通post request,由智付通產生付款頁面,以下提供兩種方式

  1. 透過view helper自動產生表單
  2. 自行實作

透過view helper自動產生表單

  • view中自動產生付款表單,可自行設定按鈕名稱與樣式
  1. spgateway_periodical_form
  2. # 如要設定名稱與樣式請使用
  3. spgateway_periodical_form(
  4. btn_value: "付款",
  5. btn_class: "btn btn-primary")

自行發送要求

  • 可自行產生AES加密結果放入PostData_內並實作發送要求
  1. post_data = spgateway_periodical.get_encrypt_string

回傳資料

如有設定回傳URL,智付通在交易完成後會將資料回傳

  • 直接傳入Period即會自動解密並將結果轉換成hash,請自行記錄回傳資料
  1. result = spgateway_periodical_result params[:Period]
  2. result.get_result
  3. # 如果想取得AES解密後的原始結果
  4. result.get_raw_result
  • 轉換後資料結構如下 :
  1. {
  2. "Status"=>"SUCCESS",
  3. "Message"=>"委託單成立,且首次授權成功",
  4. "Result"=>{
  5. "MerchantID"=>"MS1732037",
  6. "MerchantOrderNo"=>"14839807785444715",
  7. "PeriodType"=>"W",
  8. "PeriodAmt"=>"2",
  9. "AuthTimes"=>5,
  10. "DateArray"=>"2017-01-10,2017-01-17,2017-01-24,2017-01-31,2017-02-07",
  11. "TradeNo"=>"17011000532533523",
  12. "AuthCode"=>"930637",
  13. "RespondCode"=>"00",
  14. "AuthTime"=>"20170110005325",
  15. "CardNo"=>"400022******1111",
  16. "EscrowBank"=>"KGI",
  17. "AuthBank"=>"KGI",
  18. "PeriodNo"=>"P170110005324Eajz3K"
  19. }
  20. }

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ZneuRay/spgateway_rails.