active_merchant_pay2go 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 044ce646132e49b4a79ec747b69f49a0e3daea11d41aeb7648d3bd286bada20e
|
4
|
+
data.tar.gz: 76fe360143635dfb30198a5daccbeda548ef63e15bb2b0289113eb5cf93c7d7d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 157c9cb059bf0f3177b2b7c11eb6364a8c46b2976984c5ca2105f6cc16d4ad0d36fdf7e8bd9a5a89531674ccbb3f9667fc5442a1eb4f2ec11dca3ac6450c26bf
|
7
|
+
data.tar.gz: 7ec6214ab9ce0a80f958561a4fb448c12c0f914da5d25452c57220e265c100c36d5ab0a7bed7f464a6997432d6478fff27265334432f57c1c3774687bd9f2487
|
data/README.md
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
|
7
7
|
[](https://gitter.im/imgarylai/active_merchant_pay2go?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
8
8
|
|
9
|
-
這個 gem 的目的是要串接 [
|
9
|
+
這個 gem 的目的是要串接 [智付通(原智付寶)](https://www.spgateway.com) 的金流,不過不是只有單純的 API 封裝,是透過 [active_merchant](https://github.com/activemerchant/active_merchant) 和 [offsite_payments](https://github.com/activemerchant/offsite_payments) 包裝後可以快速的在 Rails 上使用。
|
10
10
|
|
11
11
|
另外非常感謝 [active_merchant_allpay](https://github.com/xwaynec/active_merchant_allpay)。
|
12
12
|
|
@@ -26,7 +26,7 @@ $ bundle
|
|
26
26
|
|
27
27
|
## 設定
|
28
28
|
|
29
|
-
- 建議第一次使用的人可以先看一下官方的文件... [
|
29
|
+
- 建議第一次使用的人可以先看一下官方的文件... [Official API](https://www.spgateway.com/dw_files/info_api/spgateway_gateway_MPGapi_V1_0_3.pdf) 。
|
30
30
|
|
31
31
|
- 建立 `config/initializers/pay2go.rb`
|
32
32
|
``` sh
|
@@ -7,10 +7,10 @@ module OffsitePayments #:nodoc:
|
|
7
7
|
module Integrations #:nodoc:
|
8
8
|
module Pay2go
|
9
9
|
|
10
|
-
VERSION = '1.
|
10
|
+
VERSION = '1.4'
|
11
11
|
RESPOND_TYPE = 'String'
|
12
|
-
CHECK_VALUE_FIELDS = %w(
|
13
|
-
CHECK_CODE_FIELDS = %w(
|
12
|
+
CHECK_VALUE_FIELDS = %w(MerchantID RespondType TimeStamp Version MerchantOrderNo Amt ItemDesc)
|
13
|
+
CHECK_CODE_FIELDS = %w(MerchantID RespondType TimeStamp Version MerchantOrderNo Amt ItemDesc)
|
14
14
|
|
15
15
|
CONFIG = %w(
|
16
16
|
MerchantID LangType TradeLimit ExpireDate NotifyURL EmailModify LoginType
|
@@ -1,4 +1,5 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require 'openssl'
|
2
3
|
require 'digest'
|
3
4
|
|
4
5
|
module OffsitePayments #:nodoc:
|
@@ -6,7 +7,7 @@ module OffsitePayments #:nodoc:
|
|
6
7
|
module Pay2go
|
7
8
|
class Helper < OffsitePayments::Helper
|
8
9
|
FIELDS = %w(
|
9
|
-
MerchantID LangType MerchantOrderNo Amt ItemDesc TradeLimit ExpireDate ExpireTime ReturnURL NotifyURL CustomerURL ClientBackURL Email EmailModify LoginType OrderComment CREDIT CreditRed InstFlag UNIONPAY WEBATM VACC CVS BARCODE CUSTOM TokenTerm
|
10
|
+
MerchantID LangType MerchantOrderNo Amt ItemDesc TradeLimit ExpireDate ExpireTime ReturnURL NotifyURL CustomerURL ClientBackURL Email EmailModify LoginType OrderComment CREDIT CreditRed InstFlag UNIONPAY ALIPAY WEBATM VACC CVS BARCODE CUSTOM TokenTerm
|
10
11
|
)
|
11
12
|
|
12
13
|
FIELDS.each do |field|
|
@@ -26,13 +27,38 @@ module OffsitePayments #:nodoc:
|
|
26
27
|
def time_stamp(date)
|
27
28
|
add_field 'TimeStamp', date.to_time.to_i
|
28
29
|
end
|
29
|
-
def
|
30
|
-
|
31
|
-
|
32
|
-
}
|
30
|
+
def detail(data)
|
31
|
+
detail = {}
|
32
|
+
return detail if data.blank?
|
33
33
|
|
34
|
-
|
35
|
-
|
34
|
+
detail['Receiver'] = data[:receiver]
|
35
|
+
detail['Tel1'] = data[:phones].first
|
36
|
+
detail['Tel2'] = data[:phones].last
|
37
|
+
detail['Count'] = data[:items].count
|
38
|
+
data[:items].each_with_index do |item, index|
|
39
|
+
i = index + 1
|
40
|
+
detail["Pid#{i}"] = item[:pid]
|
41
|
+
detail["Title#{i}"] = item[:name]
|
42
|
+
detail["Desc#{i}"] = item[:description]
|
43
|
+
detail["Price#{i}"] = item[:price]
|
44
|
+
detail["Qty#{i}"] = item[:quantity]
|
45
|
+
end
|
46
|
+
detail
|
47
|
+
end
|
48
|
+
def encrypted_data(detail = {})
|
49
|
+
key = OffsitePayments::Integrations::Pay2go.hash_key
|
50
|
+
iv = OffsitePayments::Integrations::Pay2go.hash_iv
|
51
|
+
|
52
|
+
aes = OpenSSL::Cipher.new('AES-256-CBC')
|
53
|
+
aes.encrypt
|
54
|
+
aes.key = key
|
55
|
+
aes.iv = iv
|
56
|
+
|
57
|
+
raw_data = URI.encode_www_form @fields.merge(detail(detail))
|
58
|
+
trade_info = (aes.update(raw_data) + aes.final).unpack('H*').first
|
59
|
+
|
60
|
+
add_field 'TradeInfo', trade_info
|
61
|
+
add_field 'TradeSha', Digest::SHA256.hexdigest("HashKey=#{key}&#{trade_info}&HashIV=#{iv}").upcase
|
36
62
|
end
|
37
63
|
end
|
38
64
|
|
@@ -6,9 +6,7 @@ module OffsitePayments #:nodoc:
|
|
6
6
|
module Pay2go
|
7
7
|
class Notification < OffsitePayments::Notification
|
8
8
|
PARAMS_FIELDS = %w(
|
9
|
-
Status
|
10
|
-
EscrowBank TokenUseStatus RedAmt RespondCode Auth Card6No Card4No Inst InstFirst InstEach ECI PayBankCode
|
11
|
-
PayerAccount5Code CodeNo BankCode Barcode_1 Barcode_2 Barcode_3 ExpireDate ExpireTime CheckCode
|
9
|
+
Status MerchantID TradeInfo TradeSha Version
|
12
10
|
)
|
13
11
|
|
14
12
|
PARAMS_FIELDS.each do |field|
|
@@ -17,6 +15,33 @@ module OffsitePayments #:nodoc:
|
|
17
15
|
end
|
18
16
|
end
|
19
17
|
|
18
|
+
# Overrides above define_method
|
19
|
+
def trade_info
|
20
|
+
key = OffsitePayments::Integrations::Pay2go.hash_key
|
21
|
+
iv = OffsitePayments::Integrations::Pay2go.hash_iv
|
22
|
+
|
23
|
+
aes = OpenSSL::Cipher.new('AES-256-CBC')
|
24
|
+
aes.decrypt
|
25
|
+
aes.padding = 0
|
26
|
+
aes.key = key
|
27
|
+
aes.iv = iv
|
28
|
+
|
29
|
+
raw_data = aes.update([@params['TradeInfo']].pack('H*')) + aes.final
|
30
|
+
URI.decode_www_form(raw_data).to_h
|
31
|
+
end
|
32
|
+
|
33
|
+
TRADE_INFO_FIELDS = %w(
|
34
|
+
Message Amt TradeNo MerchantOrderNo PaymentType RespondType CheckCode PayTime IP
|
35
|
+
EscrowBank TokenUseStatus RedAmt RespondCode Auth Card6No Card4No Inst InstFirst InstEach ECI PayBankCode
|
36
|
+
PayerAccount5Code CodeNo BankCode Barcode_1 Barcode_2 Barcode_3 ExpireDate ExpireTime
|
37
|
+
)
|
38
|
+
|
39
|
+
TRADE_INFO_FIELDS.each do |field|
|
40
|
+
define_method field.underscore do
|
41
|
+
trade_info[field]
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
20
45
|
def success?
|
21
46
|
status == 'SUCCESS'
|
22
47
|
end
|
@@ -33,12 +58,10 @@ module OffsitePayments #:nodoc:
|
|
33
58
|
end
|
34
59
|
|
35
60
|
def checksum_ok?
|
36
|
-
|
37
|
-
|
38
|
-
}
|
61
|
+
key = OffsitePayments::Integrations::Pay2go.hash_key
|
62
|
+
iv = OffsitePayments::Integrations::Pay2go.hash_iv
|
39
63
|
|
40
|
-
|
41
|
-
Digest::SHA256.hexdigest(hash_raw_data).upcase == check_code
|
64
|
+
Digest::SHA256.hexdigest("HashKey=#{key}&#{@params['TradeInfo']}&HashIV=#{iv}").upcase == trade_sha
|
42
65
|
end
|
43
66
|
end
|
44
67
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_merchant_pay2go
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
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: 2019-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemerchant
|
@@ -103,8 +103,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
103
|
- !ruby/object:Gem::Version
|
104
104
|
version: '0'
|
105
105
|
requirements: []
|
106
|
-
|
107
|
-
rubygems_version: 2.6.8
|
106
|
+
rubygems_version: 3.0.0
|
108
107
|
signing_key:
|
109
108
|
specification_version: 4
|
110
109
|
summary: pay2go(智付寶) gem
|