active_merchant_pay2go 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/.travis.yml +4 -1
- data/Gemfile +5 -0
- data/README.md +22 -12
- data/active_merchant_pay2go.gemspec +2 -3
- data/lib/active_merchant_pay2go.rb +3 -0
- data/lib/active_merchant_pay2go/version.rb +1 -1
- data/lib/generators/pay2go/install_generator.rb +4 -0
- data/lib/generators/pay2go/templates/README +11 -0
- data/lib/offsite_payments/integrations/pay2go.rb +31 -220
- data/lib/offsite_payments/integrations/pay2go_period.rb +112 -0
- metadata +13 -25
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d23e9bc1ca09cac881fece50e4e64bfdedc87cc2
|
4
|
+
data.tar.gz: 5ff36d0f6871ee64f0ebc9d7e5f980019e91231b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c973f9d2cbc1dfcf245b24162fb4e04d0d4ca26240b8bf59222c8b5b3b5921e6118dfc030c77a581302c8c5c76ac4f657c5a32e7943cf45cb37fef2355298f8
|
7
|
+
data.tar.gz: b851ecbc935c2ae482168ce92ed47b22b9c9cadad7d16ffa172972552c04d74f07f87b37480c553e508608ddd4e263ba6b42c96a24e8aa59f3171774bab2b5dc
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/imgarylai/active_merchant_pay2go.svg?branch=master)](https://travis-ci.org/imgarylai/active_merchant_pay2go)
|
2
|
+
[![Code Climate](https://codeclimate.com/github/imgarylai/active_merchant_pay2go/badges/gpa.svg)](https://codeclimate.com/github/imgarylai/active_merchant_pay2go)
|
3
|
+
|
1
4
|
# ActiveMerchantPay2go
|
2
5
|
|
3
6
|
This gem integrate Rails with [pay2go(智付寶)](https://www.pay2go.com/).
|
4
7
|
|
5
8
|
It was inspired by [active_merchant_allpay](https://github.com/xwaynec/active_merchant_allpay).
|
6
9
|
|
7
|
-
*WARNING:* This gem is not fully tested.
|
8
|
-
|
9
10
|
## Installation
|
10
11
|
|
11
12
|
Add this line to your application's Gemfile:
|
@@ -22,23 +23,30 @@ $ bundle
|
|
22
23
|
|
23
24
|
## Setup
|
24
25
|
|
25
|
-
|
26
|
-
|
27
|
-
2. Create file `config/initializers/pay2go.rb`
|
26
|
+
- I would suggest reading the [official API](https://www.pay2go.com/dw_files/info_api/pay2go_gateway_MPGapi_V1_1_4.pdf) first.
|
28
27
|
|
28
|
+
- Create file `config/initializers/pay2go.rb`
|
29
29
|
``` sh
|
30
30
|
rails g pay2go:install
|
31
31
|
```
|
32
32
|
|
33
|
-
|
33
|
+
- Go to Pay2go and get your credential information. Then fill in `config/initializers/pay2go.rb`
|
34
|
+
```rb
|
35
|
+
OffsitePayments::Integrations::Pay2go.setup do |pay2go|
|
36
|
+
# You have to apply credential below by yourself.
|
37
|
+
pay2go.merchant_id = '123456'
|
38
|
+
pay2go.hash_key = 'xxx'
|
39
|
+
pay2go.hash_iv = 'yyy'
|
40
|
+
end
|
41
|
+
```
|
34
42
|
|
43
|
+
- Environment configuration:
|
35
44
|
```rb
|
36
45
|
# config/environments/development.rb
|
37
46
|
config.after_initialize do
|
38
47
|
ActiveMerchant::Billing::Base.mode = :development
|
39
48
|
end
|
40
49
|
```
|
41
|
-
|
42
50
|
```rb
|
43
51
|
# config/environments/production.rb
|
44
52
|
config.after_initialize do
|
@@ -48,30 +56,32 @@ end
|
|
48
56
|
|
49
57
|
## Example
|
50
58
|
|
51
|
-
```
|
59
|
+
```
|
52
60
|
<% payment_service_for @order,
|
53
61
|
@order.user.email,
|
54
62
|
service: :pay2go,
|
55
63
|
html: { :id => 'pay2go-form', :method => :post } do |service| %>
|
56
|
-
<% service.encrypted_data %>
|
57
64
|
<% service.time_stamp @order.created_at %>
|
58
65
|
<% service.merchant_order_no @order.id %>
|
59
66
|
<% service.amt @order.total_amount.to_i %>
|
60
67
|
<% service.item_desc @order.description %>
|
61
68
|
<% service.email @order.user.email %>
|
62
69
|
<% service.login_type 0 %>
|
70
|
+
<% service.encrypted_data %>
|
63
71
|
<%= submit_tag '付款' %>
|
64
72
|
<% end %>
|
65
73
|
```
|
74
|
+
This example code only fulfill the min requirements.
|
75
|
+
|
76
|
+
To customize settings, you should read the documents.
|
77
|
+
I put some comments in the [code](https://github.com/imgarylai/active_merchant_pay2go/blob/master/lib/offsite_payments/integrations/pay2go.rb) as well!
|
66
78
|
|
67
|
-
|
68
|
-
Or you can read [code](https://github.com/imgarylai/active_merchant_pay2go/blob/master/lib/offsite_payments/integrations/pay2go.rb#L47-L99) here!
|
79
|
+
Here is an [example app](https://github.com/imgarylai/rails_active_merchant_pay2go) though it is really rough.
|
69
80
|
|
70
81
|
## Contributing
|
71
82
|
|
72
83
|
Bug reports and pull requests are welcome on GitHub at https://github.com/imgarylai/active_merchant_pay2go. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
73
84
|
|
74
|
-
|
75
85
|
## License
|
76
86
|
|
77
87
|
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
@@ -19,12 +19,11 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency 'activemerchant'
|
23
|
-
spec.add_dependency 'offsite_payments'
|
22
|
+
spec.add_dependency 'activemerchant', '~> 1.50'
|
23
|
+
spec.add_dependency 'offsite_payments', '~> 2'
|
24
24
|
|
25
25
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
26
26
|
spec.add_development_dependency 'rake', '~> 10.0'
|
27
|
-
spec.add_development_dependency 'test-unit', '~> 3.0'
|
28
27
|
spec.add_development_dependency 'rails', '>= 3.2.6', '< 5'
|
29
28
|
|
30
29
|
end
|
@@ -2,10 +2,13 @@ require 'action_view'
|
|
2
2
|
require 'active_merchant_pay2go/version'
|
3
3
|
require 'active_merchant'
|
4
4
|
require 'offsite_payments'
|
5
|
+
require 'active_support/core_ext/string'
|
6
|
+
require 'uri'
|
5
7
|
|
6
8
|
module OffsitePayments
|
7
9
|
module Integrations
|
8
10
|
autoload :Pay2go, 'offsite_payments/integrations/pay2go'
|
11
|
+
autoload :Pay2goPeriod, 'offsite_payments/integrations/pay2go_period'
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
@@ -0,0 +1,11 @@
|
|
1
|
+
===============================================================================
|
2
|
+
|
3
|
+
Please check and setup your `config/initializers/pay2go.rb`
|
4
|
+
|
5
|
+
OffsitePayments::Integrations::Pay2go.setup do |pay2go|
|
6
|
+
pay2go.merchant_id =
|
7
|
+
pay2go.hash_key =
|
8
|
+
pay2go.hash_iv =
|
9
|
+
end
|
10
|
+
|
11
|
+
===============================================================================
|
@@ -7,20 +7,8 @@ module OffsitePayments #:nodoc:
|
|
7
7
|
|
8
8
|
VERSION = '1.2'
|
9
9
|
RESPOND_TYPE = 'String'
|
10
|
-
CHECK_VALUE_FIELDS =
|
11
|
-
|
12
|
-
'MerchantID',
|
13
|
-
'MerchantOrderNo',
|
14
|
-
'TimeStamp',
|
15
|
-
'Version'
|
16
|
-
]
|
17
|
-
|
18
|
-
CHECK_CODE_FIELDS = [
|
19
|
-
'Amt',
|
20
|
-
'MerchantID',
|
21
|
-
'MerchantOrderNo',
|
22
|
-
'TradeNo'
|
23
|
-
]
|
10
|
+
CHECK_VALUE_FIELDS = %w(Amt MerchantID MerchantOrderNo TimeStamp Version)
|
11
|
+
CHECK_CODE_FIELDS = %w(Amt MerchantID MerchantOrderNo TradeNo)
|
24
12
|
|
25
13
|
mattr_accessor :service_url
|
26
14
|
mattr_accessor :merchant_id
|
@@ -51,58 +39,17 @@ module OffsitePayments #:nodoc:
|
|
51
39
|
end
|
52
40
|
|
53
41
|
class Helper < OffsitePayments::Helper
|
54
|
-
|
55
|
-
|
42
|
+
FIELDS = %w(
|
43
|
+
MerchantID LangType MerchantOrderNo Amt ItemDesc TradeLimit ExpireDate ReturnURL NotifyURL CustomerURL
|
44
|
+
ClientBackURL Email EmailModify LoginType OrderComment CREDIT CreditRed InstFlag UNIONPAY WEBATM VACC
|
45
|
+
CVS BARCODE CUSTOM TokenTerm
|
46
|
+
)
|
47
|
+
|
48
|
+
FIELDS.each do |field|
|
49
|
+
mapping field.underscore.to_sym, field
|
50
|
+
end
|
56
51
|
mapping :account, 'MerchantID' # AM common
|
57
|
-
# 語系
|
58
|
-
mapping :lang_type, 'LangType'
|
59
|
-
# 廠商交易編號 *
|
60
|
-
mapping :merchant_order_no, 'MerchantOrderNo'
|
61
|
-
# 交易金額
|
62
|
-
mapping :amt, 'Amt'
|
63
52
|
mapping :amount, 'Amt' # AM common
|
64
|
-
# 商品資訊 *
|
65
|
-
mapping :item_desc, 'ItemDesc'
|
66
|
-
# 交易限制秒數
|
67
|
-
mapping :trade_limit, 'TradeLimit'
|
68
|
-
# 繳費有效期限(適用於非即時交易))
|
69
|
-
mapping :expire_date, 'ExpireDate'
|
70
|
-
# 支付完成返回商店網址
|
71
|
-
mapping :return_url, 'ReturnURL'
|
72
|
-
# 支付通知網址
|
73
|
-
mapping :notify_url, 'NotifyURL'
|
74
|
-
# CustomerURL
|
75
|
-
mapping :customer_url, 'CustomerURL'
|
76
|
-
# Client 端返回廠商網址
|
77
|
-
mapping :client_back_url, 'ClientBackURL'
|
78
|
-
# 付款人電子信箱 *
|
79
|
-
mapping :email, 'Email'
|
80
|
-
# 付款人電子信箱是否開放修改
|
81
|
-
mapping :email_modify, 'EmailModify'
|
82
|
-
# 智付寶會員 *
|
83
|
-
mapping :login_type, 'LoginType'
|
84
|
-
# 商店備註
|
85
|
-
mapping :order_comment, 'OrderComment'
|
86
|
-
# 信用卡一次付清啟用
|
87
|
-
mapping :credit ,'CREDIT'
|
88
|
-
# 信用卡紅利啟用
|
89
|
-
mapping :credit_red, 'CreditRed'
|
90
|
-
# 信用卡分期付款啟用
|
91
|
-
mapping :inst_flag ,'InstFlag'
|
92
|
-
# 信用卡銀聯卡啟用
|
93
|
-
mapping :unionpay ,'UNIONPAY'
|
94
|
-
# WEBATM 啟用
|
95
|
-
mapping :webatm, 'WEBATM'
|
96
|
-
# ATM 轉帳啟用
|
97
|
-
mapping :vacc, 'VACC'
|
98
|
-
# 超商代碼繳費啟用
|
99
|
-
mapping :cvs, 'CVS'
|
100
|
-
# 條碼繳費啟用
|
101
|
-
mapping :barcode, 'BARCODE'
|
102
|
-
# 自訂支付啟用
|
103
|
-
mapping :custom, 'CUSTOM'
|
104
|
-
# 快速結帳 *
|
105
|
-
mapping :token_term, 'TokenTerm'
|
106
53
|
|
107
54
|
def initialize(order, account, options = {})
|
108
55
|
super
|
@@ -116,23 +63,30 @@ module OffsitePayments #:nodoc:
|
|
116
63
|
end
|
117
64
|
|
118
65
|
def encrypted_data
|
119
|
-
raw_data = OffsitePayments::Integrations::Pay2go::CHECK_VALUE_FIELDS.sort.map { |field|
|
120
|
-
|
121
|
-
}
|
66
|
+
raw_data = URI.encode_www_form OffsitePayments::Integrations::Pay2go::CHECK_VALUE_FIELDS.sort.map { |field|
|
67
|
+
[field, @fields[field]]
|
68
|
+
}
|
122
69
|
|
123
70
|
hash_raw_data = "HashKey=#{OffsitePayments::Integrations::Pay2go.hash_key}&#{raw_data}&HashIV=#{OffsitePayments::Integrations::Pay2go.hash_iv}"
|
124
|
-
|
125
|
-
binding.pry if OffsitePayments::Integrations::Pay2go.debug
|
126
|
-
|
127
71
|
add_field 'CheckValue', Digest::SHA256.hexdigest(hash_raw_data).upcase
|
128
72
|
end
|
129
|
-
|
130
73
|
end
|
131
74
|
|
132
75
|
class Notification < OffsitePayments::Notification
|
76
|
+
PARAMS_FIELDS = %w(
|
77
|
+
Status Message MerchantID Amt TradeNo MerchantOrderNo PaymentType RespondType CheckCode PayTime IP
|
78
|
+
EscrowBank TokenUseStatus RespondCode Auth Card6No Card4No Inst InstFirst InstEach ECI PayBankCode
|
79
|
+
PayerAccount5Code CodeNo BankCode Barcode_1 Barcode_2 Barcode_3 ExpireDate CheckCode
|
80
|
+
)
|
81
|
+
|
82
|
+
PARAMS_FIELDS.each do |field|
|
83
|
+
define_method field.underscore do
|
84
|
+
@params[field]
|
85
|
+
end
|
86
|
+
end
|
133
87
|
|
134
88
|
def success?
|
135
|
-
|
89
|
+
status == 'SUCCESS'
|
136
90
|
end
|
137
91
|
|
138
92
|
# TODO 使用查詢功能實作 acknowledge
|
@@ -143,160 +97,17 @@ module OffsitePayments #:nodoc:
|
|
143
97
|
end
|
144
98
|
|
145
99
|
def complete?
|
146
|
-
|
147
|
-
when 'SUCCESS'
|
148
|
-
true
|
149
|
-
when 'CUSTOM'
|
150
|
-
true
|
151
|
-
else
|
152
|
-
false
|
153
|
-
end
|
100
|
+
%w(SUCCESS CUSTOM).include? status
|
154
101
|
end
|
155
102
|
|
156
103
|
def checksum_ok?
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
raw_data = OffsitePayments::Integrations::Pay2go::CHECK_CODE_FIELDS.sort.map { |field|
|
162
|
-
"#{field}=#{params_copy[field]}"
|
163
|
-
}.join('&')
|
104
|
+
raw_data = URI.encode_www_form OffsitePayments::Integrations::Pay2go::CHECK_CODE_FIELDS.sort.map { |field|
|
105
|
+
[field, @params[field]]
|
106
|
+
}
|
164
107
|
|
165
108
|
hash_raw_data = "HashIV=#{OffsitePayments::Integrations::Pay2go.hash_iv}&#{raw_data}&HashKey=#{OffsitePayments::Integrations::Pay2go.hash_key}"
|
166
|
-
|
167
|
-
Digest::SHA256.hexdigest(hash_raw_data).upcase == checksum
|
168
|
-
end
|
169
|
-
|
170
|
-
def status
|
171
|
-
@params['Status']
|
172
|
-
end
|
173
|
-
|
174
|
-
def message
|
175
|
-
@params['Message']
|
176
|
-
end
|
177
|
-
|
178
|
-
def merchant_id
|
179
|
-
@params['MerchantID']
|
180
|
-
end
|
181
|
-
|
182
|
-
def amt
|
183
|
-
@params['Amt']
|
184
|
-
end
|
185
|
-
|
186
|
-
def trade_no
|
187
|
-
@params['TradeNo']
|
188
|
-
end
|
189
|
-
|
190
|
-
def merchant_order_no
|
191
|
-
@params['MerchantOrderNo']
|
192
|
-
end
|
193
|
-
|
194
|
-
def payment_type
|
195
|
-
@params['PaymentType']
|
196
|
-
end
|
197
|
-
|
198
|
-
def respond_type
|
199
|
-
@params['RespondType']
|
200
|
-
end
|
201
|
-
|
202
|
-
def check_code
|
203
|
-
@params['CheckCode']
|
204
|
-
end
|
205
|
-
|
206
|
-
# 所有支付方式共同回傳參數
|
207
|
-
|
208
|
-
def pay_time
|
209
|
-
@params['PayTime']
|
210
|
-
end
|
211
|
-
|
212
|
-
def ip
|
213
|
-
@params['IP']
|
214
|
-
end
|
215
|
-
|
216
|
-
def escrow_bank
|
217
|
-
@params['EscrowBank']
|
218
|
-
end
|
219
|
-
|
220
|
-
def token_use_status
|
221
|
-
@params['TokenUseStatus']
|
109
|
+
Digest::SHA256.hexdigest(hash_raw_data).upcase == check_code
|
222
110
|
end
|
223
|
-
|
224
|
-
# 信用卡支付回傳參數
|
225
|
-
|
226
|
-
def respond_code
|
227
|
-
@params['RespondCode']
|
228
|
-
end
|
229
|
-
|
230
|
-
def auth
|
231
|
-
@params['Auth']
|
232
|
-
end
|
233
|
-
|
234
|
-
def card_6_no
|
235
|
-
@params['Card6No']
|
236
|
-
end
|
237
|
-
|
238
|
-
def card_4_no
|
239
|
-
@params['Card4No']
|
240
|
-
end
|
241
|
-
|
242
|
-
def inst
|
243
|
-
@params['Inst']
|
244
|
-
end
|
245
|
-
|
246
|
-
def inst_first
|
247
|
-
@params['InstFirst']
|
248
|
-
end
|
249
|
-
|
250
|
-
def inst_each
|
251
|
-
@params['InstEach']
|
252
|
-
end
|
253
|
-
|
254
|
-
def eci
|
255
|
-
@params['ECI']
|
256
|
-
end
|
257
|
-
|
258
|
-
# WEBATM、ATM 繳費回傳參數
|
259
|
-
|
260
|
-
def pay_bank_code
|
261
|
-
@params['PayBankCode']
|
262
|
-
end
|
263
|
-
|
264
|
-
def payer_account_5_code
|
265
|
-
@params['PayerAccount5Code']
|
266
|
-
end
|
267
|
-
|
268
|
-
# 超商代碼繳費回傳參數
|
269
|
-
|
270
|
-
def code_no
|
271
|
-
@params['CodeNo']
|
272
|
-
end
|
273
|
-
|
274
|
-
# ATM 轉帳回傳參數
|
275
|
-
def bank_code
|
276
|
-
@params['BankCode']
|
277
|
-
end
|
278
|
-
|
279
|
-
|
280
|
-
# 條碼繳費回傳參數
|
281
|
-
|
282
|
-
def barcode_1
|
283
|
-
@params['Barcode_1']
|
284
|
-
end
|
285
|
-
|
286
|
-
def barcode_2
|
287
|
-
@params['Barcode_2']
|
288
|
-
end
|
289
|
-
|
290
|
-
def barcode_3
|
291
|
-
@params['Barcode_3']
|
292
|
-
end
|
293
|
-
|
294
|
-
# 取號完成系統回傳參數
|
295
|
-
|
296
|
-
def expire_date
|
297
|
-
@params['ExpireDate']
|
298
|
-
end
|
299
|
-
|
300
111
|
end
|
301
112
|
end
|
302
113
|
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'digest'
|
3
|
+
|
4
|
+
module OffsitePayments #:nodoc:
|
5
|
+
module Integrations #:nodoc:
|
6
|
+
module Pay2goPeriod
|
7
|
+
|
8
|
+
VERSION = '1.0'
|
9
|
+
RESPOND_TYPE = 'String'
|
10
|
+
CHECK_VALUE_FIELDS = %w(PeriodAmt MerchantID MerchantOrderNo TimeStamp PeriodType)
|
11
|
+
CHECK_CODE_FIELDS = %w(PeriodType MerchantID MerchantOrderNo)
|
12
|
+
|
13
|
+
mattr_accessor :service_url
|
14
|
+
mattr_accessor :merchant_id
|
15
|
+
mattr_accessor :hash_key
|
16
|
+
mattr_accessor :hash_iv
|
17
|
+
mattr_accessor :debug
|
18
|
+
|
19
|
+
def self.service_url
|
20
|
+
mode = ActiveMerchant::Billing::Base.mode
|
21
|
+
case mode
|
22
|
+
when :production
|
23
|
+
'https://api.pay2go.com/API/PeriodAPI'
|
24
|
+
when :development
|
25
|
+
'https://capi.pay2go.com/API/PeriodAPI'
|
26
|
+
when :test
|
27
|
+
'https://capi.pay2go.com/API/PeriodAPI'
|
28
|
+
else
|
29
|
+
raise StandardError, "Integration mode set to an invalid value: #{mode}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.notification(post)
|
34
|
+
Notification.new(post)
|
35
|
+
end
|
36
|
+
|
37
|
+
def self.setup
|
38
|
+
yield(self)
|
39
|
+
end
|
40
|
+
|
41
|
+
class Helper < OffsitePayments::Helper
|
42
|
+
FIELDS = %w(
|
43
|
+
MerchantID MerchantOrderNo PeriodAmt ProdDesc PeriodAmtMode PeriodType PeriodPoint PeriodStartType
|
44
|
+
PeriodTimes ReturnURL ProDetail PeriodMemo PaymentInfo OrderInfo InvoiceInfo NotifyURL
|
45
|
+
)
|
46
|
+
|
47
|
+
FIELDS.each do |field|
|
48
|
+
mapping field.underscore.to_sym, field
|
49
|
+
end
|
50
|
+
mapping :account, 'MerchantID' # AM common
|
51
|
+
|
52
|
+
def initialize(order, account, options = {})
|
53
|
+
super
|
54
|
+
add_field 'MerchantID', OffsitePayments::Integrations::Pay2go.merchant_id
|
55
|
+
add_field 'Version', OffsitePayments::Integrations::Pay2goPeriod::VERSION
|
56
|
+
add_field 'RespondType', OffsitePayments::Integrations::Pay2goPeriod::RESPOND_TYPE
|
57
|
+
end
|
58
|
+
|
59
|
+
def time_stamp(date)
|
60
|
+
add_field 'TimeStamp', date.to_time.to_i
|
61
|
+
end
|
62
|
+
|
63
|
+
def encrypted_data
|
64
|
+
raw_data = URI.encode_www_form OffsitePayments::Integrations::Pay2goPeriod::CHECK_VALUE_FIELDS.sort.map { |field|
|
65
|
+
[field, @fields[field]]
|
66
|
+
}
|
67
|
+
|
68
|
+
hash_raw_data = "HashKey=#{OffsitePayments::Integrations::Pay2go.hash_key}&#{raw_data}&HashIV=#{OffsitePayments::Integrations::Pay2go.hash_iv}"
|
69
|
+
add_field 'CheckValue', Digest::SHA256.hexdigest(hash_raw_data).upcase
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
class Notification < OffsitePayments::Notification
|
75
|
+
PARAMS_FIELDS = %w(
|
76
|
+
Status Message MerchantID MerchantOrderNo PeriodType authDate authTime dateArray PeriodTotalAmt
|
77
|
+
PeriodFirstAmt PeriodAmt CheckCode
|
78
|
+
)
|
79
|
+
|
80
|
+
PARAMS_FIELDS.each do |field|
|
81
|
+
define_method field.underscore do
|
82
|
+
@params[field]
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
def success?
|
87
|
+
status == 'SUCCESS'
|
88
|
+
end
|
89
|
+
|
90
|
+
# TODO 使用查詢功能實作 acknowledge
|
91
|
+
# Pay2go 沒有遠端驗證功能,
|
92
|
+
# 而以 checksum_ok? 代替
|
93
|
+
def acknowledge
|
94
|
+
checksum_ok?
|
95
|
+
end
|
96
|
+
|
97
|
+
def complete?
|
98
|
+
%w(SUCCESS CUSTOM).include? status
|
99
|
+
end
|
100
|
+
|
101
|
+
def checksum_ok?
|
102
|
+
raw_data = URI.encode_www_form OffsitePayments::Integrations::Pay2goPeriod::CHECK_CODE_FIELDS.sort.map { |field|
|
103
|
+
[field, @params[field]]
|
104
|
+
}
|
105
|
+
|
106
|
+
hash_raw_data = "HashIV=#{OffsitePayments::Integrations::Pay2go.hash_iv}&#{raw_data}&HashKey=#{OffsitePayments::Integrations::Pay2go.hash_key}"
|
107
|
+
Digest::SHA256.hexdigest(hash_raw_data).upcase == check_code
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_merchant_pay2go
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gary
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemerchant
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '1.50'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '1.50'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: offsite_payments
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
33
|
+
version: '2'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
40
|
+
version: '2'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '10.0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: test-unit
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - "~>"
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '3.0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - "~>"
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '3.0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: rails
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -120,8 +106,10 @@ files:
|
|
120
106
|
- lib/active_merchant_pay2go.rb
|
121
107
|
- lib/active_merchant_pay2go/version.rb
|
122
108
|
- lib/generators/pay2go/install_generator.rb
|
109
|
+
- lib/generators/pay2go/templates/README
|
123
110
|
- lib/generators/pay2go/templates/pay2go.rb
|
124
111
|
- lib/offsite_payments/integrations/pay2go.rb
|
112
|
+
- lib/offsite_payments/integrations/pay2go_period.rb
|
125
113
|
homepage: https://github.com/imgarylai/active_merchant_pay2go
|
126
114
|
licenses:
|
127
115
|
- MIT
|
@@ -142,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
142
130
|
version: '0'
|
143
131
|
requirements: []
|
144
132
|
rubyforge_project:
|
145
|
-
rubygems_version: 2.
|
133
|
+
rubygems_version: 2.5.1
|
146
134
|
signing_key:
|
147
135
|
specification_version: 4
|
148
136
|
summary: pay2go(智付寶) gem
|