active_merchant_pay2go 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a7c89639901556b0c75b435b5fc8a5bd7baa6ad6
4
- data.tar.gz: 5eb69956ae3bd10381ba2cb495652fe279e1b11e
2
+ SHA256:
3
+ metadata.gz: 044ce646132e49b4a79ec747b69f49a0e3daea11d41aeb7648d3bd286bada20e
4
+ data.tar.gz: 76fe360143635dfb30198a5daccbeda548ef63e15bb2b0289113eb5cf93c7d7d
5
5
  SHA512:
6
- metadata.gz: 45b1bf1f21b4558afee41e3fa746aa96148e886b2956567aae229d937d8df4e5e4bd7e14debb2cf0574f4ddc9f29dcffb4a75fb31122f19f6b605956dc11f064
7
- data.tar.gz: fab15d72b651842e45cf386d7852c5e17ddffe530da9788ebaf2926d8dbcb059423e59f0ed63e447a423a710ae27d3ee28f649552f4fb3ca0a83daddc28a7d59
6
+ metadata.gz: 157c9cb059bf0f3177b2b7c11eb6364a8c46b2976984c5ca2105f6cc16d4ad0d36fdf7e8bd9a5a89531674ccbb3f9667fc5442a1eb4f2ec11dca3ac6450c26bf
7
+ data.tar.gz: 7ec6214ab9ce0a80f958561a4fb448c12c0f914da5d25452c57220e265c100c36d5ab0a7bed7f464a6997432d6478fff27265334432f57c1c3774687bd9f2487
data/README.md CHANGED
@@ -6,7 +6,7 @@
6
6
 
7
7
  [![Join the chat at https://gitter.im/imgarylai/active_merchant_pay2go](https://badges.gitter.im/imgarylai/active_merchant_pay2go.svg)](https://gitter.im/imgarylai/active_merchant_pay2go?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
8
8
 
9
- 這個 gem 的目的是要串接 [pay2go(智付寶)](https://www.pay2go.com/) 的金流,不過不是只有單純的 API 封裝,是透過 [active_merchant](https://github.com/activemerchant/active_merchant) 和 [offsite_payments](https://github.com/activemerchant/offsite_payments) 包裝後可以快速的在 Rails 上使用。
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
- - 建議第一次使用的人可以先看一下官方的文件... [official API](https://www.pay2go.com/dw_files/info_api/pay2go_gateway_MPGapi_V1_1_8.pdf) 。
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
@@ -1,3 +1,3 @@
1
1
  module ActiveMerchantPay2go
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.1"
3
3
  end
@@ -7,10 +7,10 @@ module OffsitePayments #:nodoc:
7
7
  module Integrations #:nodoc:
8
8
  module Pay2go
9
9
 
10
- VERSION = '1.2'
10
+ VERSION = '1.4'
11
11
  RESPOND_TYPE = 'String'
12
- CHECK_VALUE_FIELDS = %w(Amt MerchantID MerchantOrderNo TimeStamp Version)
13
- CHECK_CODE_FIELDS = %w(Amt MerchantID MerchantOrderNo TradeNo)
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 encrypted_data
30
- raw_data = URI.encode_www_form OffsitePayments::Integrations::Pay2go::CHECK_VALUE_FIELDS.sort.map { |field|
31
- [field, @fields[field]]
32
- }
30
+ def detail(data)
31
+ detail = {}
32
+ return detail if data.blank?
33
33
 
34
- hash_raw_data = "HashKey=#{OffsitePayments::Integrations::Pay2go.hash_key}&#{raw_data}&HashIV=#{OffsitePayments::Integrations::Pay2go.hash_iv}"
35
- add_field 'CheckValue', Digest::SHA256.hexdigest(hash_raw_data).upcase
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 Message MerchantID Amt TradeNo MerchantOrderNo PaymentType RespondType CheckCode PayTime IP
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
- raw_data = URI.encode_www_form OffsitePayments::Integrations::Pay2go::CHECK_CODE_FIELDS.sort.map { |field|
37
- [field, @params[field]]
38
- }
61
+ key = OffsitePayments::Integrations::Pay2go.hash_key
62
+ iv = OffsitePayments::Integrations::Pay2go.hash_iv
39
63
 
40
- hash_raw_data = "HashIV=#{OffsitePayments::Integrations::Pay2go.hash_iv}&#{raw_data}&HashKey=#{OffsitePayments::Integrations::Pay2go.hash_key}"
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.0
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: 2017-02-06 00:00:00.000000000 Z
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
- rubyforge_project:
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