Ruby on Rails的智付通信用卡定期定額扣款Gem
Ruby on Rails的智付通信用卡定期定額扣款Gem,相關API文件請參考信用卡定期定額API
0.7.0
0.6.0
0.5.2
spgateway_periodical_form
與spgateway_mpg_form
參數錯誤問題0.5.1
0.5.0
0.4.0
0.2.0
0.1.0
將此行加入你的 Gemfile:
gem 'spgateway_rails', git: https://github.com/ZneuRay/spgateway_rails.git
然後執行:
$ bundle install
MerchantID
、HashKey
、HashIV
,連結可參考下方config/initializers/spgateway.rb
並加入設定
SpgatewayRails.configure do |config|
config.merchant_id = ''
config.hash_key = ''
config.hash_iv = ''
config.mode = :development
end
controller
中設定你需要的付款條件,各參數請參考智付通API
spgateway_periodical.setup do |p|
p["ProdDesc"] = "月租費"
p["PeriodAmt"] = 1000
end
ProdDesc
與PeriodAmt
,如需回傳資料請加入NotifyURL
與ReturnURL
,其它需要修改再自行填入
RespondType : 'String'
TimeStamp : (timestamp)
Version : '1.0'
MerOrderNo : (timestamp in macroseconds 16位數)
PeriodAmt : 1000
PeriodType : 'M'
PeriodStartType : 2
PeriodTimes : 60
PeriodPoint : (今天)
PeriodType
後可使用下方指令自動幫你產生對應PeriodType
格式的今天日期
spgateway_periodical.reset_period_point
Form
信用卡定期定額扣款透過對智付通post request
,由智付通產生付款頁面,以下提供兩種方式
view helper
自動產生表單view helper
自動產生表單view
中自動產生付款表單,可自行設定按鈕名稱與樣式
spgateway_periodical_form
# 如要設定名稱與樣式請使用
spgateway_periodical_form(
btn_value: "付款",
btn_class: "btn btn-primary")
PostData_
內並實作發送要求
post_data = spgateway_periodical.get_encrypt_string
如有設定回傳URL
,智付通在交易完成後會將資料回傳
Period
即會自動解密並將結果轉換成hash,請自行記錄回傳資料
result = spgateway_periodical_result params[:Period]
result.get_result
# 如果想取得AES解密後的原始結果
result.get_raw_result
{
"Status"=>"SUCCESS",
"Message"=>"委託單成立,且首次授權成功",
"Result"=>{
"MerchantID"=>"MS1732037",
"MerchantOrderNo"=>"14839807785444715",
"PeriodType"=>"W",
"PeriodAmt"=>"2",
"AuthTimes"=>5,
"DateArray"=>"2017-01-10,2017-01-17,2017-01-24,2017-01-31,2017-02-07",
"TradeNo"=>"17011000532533523",
"AuthCode"=>"930637",
"RespondCode"=>"00",
"AuthTime"=>"20170110005325",
"CardNo"=>"400022******1111",
"EscrowBank"=>"KGI",
"AuthBank"=>"KGI",
"PeriodNo"=>"P170110005324Eajz3K"
}
}
Bug reports and pull requests are welcome on GitHub at https://github.com/ZneuRay/spgateway_rails.