offsite_payments_pay2go_cvs 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 52809e87085817b762e09ab1ace51c559f6db92c
4
+ data.tar.gz: d662eb6949cee91034a754faa304e38f2137acd0
5
+ SHA512:
6
+ metadata.gz: 4237263c1afe2806a04252c18ab1a964607a76c34f9ad33787a0c8e4a0acf50dcdff7c2ed9d546ff7a6b59e18c5eaefe4454102f08ece97df9a6b6e3382bc16f
7
+ data.tar.gz: 601ccf3d0d59fdda67be37290674de2a90420ea0ce8dbfb794d8e9a8e5b4db7f0ab23cba28bf79acf4ea0ae1cae4fa2abeab270d9300142c57e1267845cd511e
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at solve153@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in offsite_payments_pay2go_cvs.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,134 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ offsite_payments_pay2go_cvs (0.1.0)
5
+ money (>= 6)
6
+ offsite_payments (>= 2.7)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionmailer (4.2.11.1)
12
+ actionpack (= 4.2.11.1)
13
+ actionview (= 4.2.11.1)
14
+ activejob (= 4.2.11.1)
15
+ mail (~> 2.5, >= 2.5.4)
16
+ rails-dom-testing (~> 1.0, >= 1.0.5)
17
+ actionpack (4.2.11.1)
18
+ actionview (= 4.2.11.1)
19
+ activesupport (= 4.2.11.1)
20
+ rack (~> 1.6)
21
+ rack-test (~> 0.6.2)
22
+ rails-dom-testing (~> 1.0, >= 1.0.5)
23
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
24
+ actionview (4.2.11.1)
25
+ activesupport (= 4.2.11.1)
26
+ builder (~> 3.1)
27
+ erubis (~> 2.7.0)
28
+ rails-dom-testing (~> 1.0, >= 1.0.5)
29
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
30
+ active_utils (3.3.16)
31
+ activesupport (>= 4.2)
32
+ i18n
33
+ activejob (4.2.11.1)
34
+ activesupport (= 4.2.11.1)
35
+ globalid (>= 0.3.0)
36
+ activemodel (4.2.11.1)
37
+ activesupport (= 4.2.11.1)
38
+ builder (~> 3.1)
39
+ activerecord (4.2.11.1)
40
+ activemodel (= 4.2.11.1)
41
+ activesupport (= 4.2.11.1)
42
+ arel (~> 6.0)
43
+ activesupport (4.2.11.1)
44
+ i18n (~> 0.7)
45
+ minitest (~> 5.1)
46
+ thread_safe (~> 0.3, >= 0.3.4)
47
+ tzinfo (~> 1.1)
48
+ arel (6.0.4)
49
+ builder (3.2.3)
50
+ concurrent-ruby (1.1.5)
51
+ crass (1.0.4)
52
+ erubis (2.7.0)
53
+ globalid (0.4.2)
54
+ activesupport (>= 4.2.0)
55
+ i18n (0.9.5)
56
+ concurrent-ruby (~> 1.0)
57
+ loofah (2.2.3)
58
+ crass (~> 1.0.2)
59
+ nokogiri (>= 1.5.9)
60
+ mail (2.7.1)
61
+ mini_mime (>= 0.1.1)
62
+ metaclass (0.0.4)
63
+ mini_mime (1.0.1)
64
+ mini_portile2 (2.4.0)
65
+ minitest (5.11.3)
66
+ mocha (1.8.0)
67
+ metaclass (~> 0.0.1)
68
+ money (6.13.3)
69
+ i18n (>= 0.6.4, <= 2)
70
+ nokogiri (1.9.1)
71
+ mini_portile2 (~> 2.4.0)
72
+ offsite_payments (2.7.11)
73
+ actionpack (>= 3.2.20, < 6.0)
74
+ active_utils (~> 3.3.0)
75
+ activesupport (>= 3.2.14)
76
+ builder (>= 2.1.2, < 4.0.0)
77
+ i18n (>= 0.6.6)
78
+ nokogiri (~> 1.6)
79
+ power_assert (1.1.4)
80
+ rack (1.6.11)
81
+ rack-test (0.6.3)
82
+ rack (>= 1.0)
83
+ rails (4.2.11.1)
84
+ actionmailer (= 4.2.11.1)
85
+ actionpack (= 4.2.11.1)
86
+ actionview (= 4.2.11.1)
87
+ activejob (= 4.2.11.1)
88
+ activemodel (= 4.2.11.1)
89
+ activerecord (= 4.2.11.1)
90
+ activesupport (= 4.2.11.1)
91
+ bundler (>= 1.3.0, < 2.0)
92
+ railties (= 4.2.11.1)
93
+ sprockets-rails
94
+ rails-deprecated_sanitizer (1.0.3)
95
+ activesupport (>= 4.2.0.alpha)
96
+ rails-dom-testing (1.0.9)
97
+ activesupport (>= 4.2.0, < 5.0)
98
+ nokogiri (~> 1.6)
99
+ rails-deprecated_sanitizer (>= 1.0.1)
100
+ rails-html-sanitizer (1.0.4)
101
+ loofah (~> 2.2, >= 2.2.2)
102
+ railties (4.2.11.1)
103
+ actionpack (= 4.2.11.1)
104
+ activesupport (= 4.2.11.1)
105
+ rake (>= 0.8.7)
106
+ thor (>= 0.18.1, < 2.0)
107
+ rake (12.3.2)
108
+ sprockets (3.7.2)
109
+ concurrent-ruby (~> 1.0)
110
+ rack (> 1, < 3)
111
+ sprockets-rails (3.2.1)
112
+ actionpack (>= 4.0)
113
+ activesupport (>= 4.0)
114
+ sprockets (>= 3.0.0)
115
+ test-unit (3.3.3)
116
+ power_assert
117
+ thor (0.20.3)
118
+ thread_safe (0.3.6)
119
+ tzinfo (1.2.5)
120
+ thread_safe (~> 0.1)
121
+
122
+ PLATFORMS
123
+ ruby
124
+
125
+ DEPENDENCIES
126
+ bundler
127
+ mocha (~> 1.0)
128
+ offsite_payments_pay2go_cvs!
129
+ rails (>= 3.2.14)
130
+ rake
131
+ test-unit (~> 3.0)
132
+
133
+ BUNDLED WITH
134
+ 1.14.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 stan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,115 @@
1
+ # OffsitePaymentsPay2goCvs
2
+
3
+ 智付寶超商代碼幕後取號的 OffsitePayments Integrations,,並不是透過 MPG (Multi Payment Gateway) 進行串接,而是專門為了在不離開網站的情況下幕後取得超商代碼,與 CVS API gateway 介接。
4
+
5
+ 注意: 進行此種串接方式須先和智付寶聯絡,開通此功能權限後方可使用。
6
+
7
+
8
+ ## Installation
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+
13
+ gem 'offsite_payments'
14
+ gem 'offsite_payments_pay2go_cvs', github: 'GoodLife/offsite_payments_pay2go_cvs.git'
15
+
16
+
17
+ And then execute:
18
+
19
+ $ bundle install
20
+
21
+
22
+ ## Usage
23
+
24
+
25
+ ``` ruby
26
+
27
+ # config/environments/development.rb
28
+ config.after_initialize do
29
+ OffsitePayments::Base.integration_mode = :development
30
+ end
31
+
32
+ # config/environments/production.rb
33
+ config.after_initialize do
34
+ OffsitePayments::Base.integration_mode = :production
35
+ end
36
+
37
+ ```
38
+
39
+ ``` ruby
40
+
41
+ # initializers/pay2go_cvs.rb
42
+ OffsitePayments::Integrations::Pay2goCvs.setup do |pay2go_cvs|
43
+ pay2go_cvs.merchant_id = YOUR_MERCHANT_ID
44
+ pay2go_cvs.hash_key = YOUR_HASH_KEY
45
+ pay2go_cvs.hash_iv = YOUR_HASH_IV
46
+ end
47
+ ```
48
+
49
+ ## Example Usage
50
+
51
+ Once you’ve configured ActiveMerchantPay2goCvs, you need a checkout form; it looks like:
52
+
53
+ ``` ruby
54
+ <% payment_service_for @order,
55
+ @order.user.email,
56
+ :service => :pay2go,
57
+ :credential3 => get_cvs_order_path, # 用來接收參數並幕後取得超商代碼的 controller/action URL
58
+ :html => { :id => 'pay2go-checkout-form', :method => :post } do |service| %>
59
+ <% service.merchant_order_no @order.payments.last.identifier %>
60
+ <% service.respond_type "JSON" %>
61
+ <% service.time_stamp @order.created_at.to_i %>
62
+ <% service.version "1.0" %>
63
+ <% service.product_desc @order.number %>
64
+ <% service.amt @order.money %>
65
+ <% service.email @order.buyer.email %>
66
+ <% service.expire_date (@order.created_at + 7.days).strftime('%Y%m%d') %>
67
+ <% service.notify_url pay2go_return_url %>
68
+ <% service.encrypted_data %>
69
+ <%= submit_tag 'Buy!' %>
70
+ <% end %>
71
+ ```
72
+
73
+ And add fetcher to the customized service url (the `credential3` field) to process CVS code fetching.
74
+
75
+ ```ruby
76
+ class OrdersController < ApplicationController
77
+
78
+ def get_cvs
79
+ fetch_result = OffsitePayments::Integrations::Pay2goCvs::Fetcher.new(params).fetch
80
+ cvs_code = fetch_result['Result']['CVSCode']
81
+ end
82
+ ```
83
+
84
+ Also need a notification action when Pay2goCvs service notifies your server; it looks like:
85
+
86
+ ``` ruby
87
+ def notify
88
+ notification = OffsitePayments::Integrations::Pay2goCvs::Notification.new(request.raw_post)
89
+
90
+ order = Order.find_by_number(notification.merchant_order_no)
91
+
92
+ if notification.status && notification.checksum_ok?
93
+ # payment is compeleted
94
+ else
95
+ # payment is failed
96
+ end
97
+
98
+ render text: '1|OK', status: 200
99
+ end
100
+ ```
101
+
102
+ ## Troublechooting
103
+ If you get a error "undefined method \`payment\_service\_for\`", you can add following configurations to initializers/pay2go_cvs.rb.
104
+ ```
105
+ require "offsite_payments/integrations/action_view_helper"
106
+ ActionView::Base.send(:include, OffsitePayments::Integrations::ActionViewHelper)
107
+ ```
108
+
109
+ ## Contributing
110
+
111
+ 1. Fork it
112
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
113
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
114
+ 4. Push to the branch (`git push origin my-new-feature`)
115
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,16 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ desc "Run the unit test suite"
5
+ task :default => 'test:units'
6
+
7
+ task :test => 'test:units'
8
+
9
+ namespace :test do
10
+ Rake::TestTask.new(:units) do |t|
11
+ t.pattern = 'test/unit/**/*_test.rb'
12
+ t.libs << 'test'
13
+ t.verbose = true
14
+ end
15
+
16
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "offsite_payments_pay2go_cvs"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,317 @@
1
+ require "offsite_payments"
2
+
3
+ module OffsitePayments #:nodoc:
4
+ module Integrations #:nodoc:
5
+ module Pay2goCvs
6
+ # 網站內部 controller 接收原始 post data 的 URL
7
+ mattr_accessor :service_url
8
+ # CVS API gateway 的 URL
9
+ mattr_accessor :gateway_url
10
+ mattr_accessor :merchant_id
11
+ mattr_accessor :hash_key
12
+ mattr_accessor :hash_iv
13
+ mattr_accessor :debug
14
+
15
+ def self.gateway_url
16
+ mode = OffsitePayments.mode
17
+ case mode
18
+ when :production
19
+ 'https://core.spgateway.com/API/gateway/cvs'
20
+ when :development
21
+ 'https://ccore.spgateway.com/API/gateway/cvs'
22
+ when :test
23
+ 'https://ccore.spgateway.com/API/gateway/cvs'
24
+ else
25
+ raise StandardError, "Integration mode set to an invalid value: #{mode}"
26
+ end
27
+ end
28
+
29
+ def self.notification(post)
30
+ Notification.new(post)
31
+ end
32
+
33
+ def self.setup
34
+ yield(self)
35
+ end
36
+
37
+ def self.fetch_url_encode_data(fields)
38
+ check_fields = [:"Amt", :"MerchantID", :"MerchantOrderNo", :"TimeStamp", :"Version"]
39
+ raw_data = fields.sort.map{|field, value|
40
+ "#{field}=#{value}" if check_fields.include?(field.to_sym)
41
+ }.compact.join('&')
42
+
43
+ hash_raw_data = "HashKey=#{OffsitePayments::Integrations::Pay2goCvs.hash_key}&#{raw_data}&HashIV=#{OffsitePayments::Integrations::Pay2goCvs.hash_iv}"
44
+
45
+ sha256 = Digest::SHA256.new
46
+ sha256.update hash_raw_data.force_encoding("utf-8")
47
+ sha256.hexdigest.upcase
48
+ end
49
+
50
+ class Helper < OffsitePayments::Helper
51
+ ### 常見介面
52
+ # 廠商編號
53
+ mapping :merchant_id, 'MerchantID'
54
+ mapping :account, 'MerchantID' # AM common
55
+ # 回傳格式
56
+ mapping :respond_type, 'RespondType'
57
+ # 時間戳記
58
+ mapping :time_stamp, 'TimeStamp'
59
+ # 串接程式版本
60
+ mapping :version, 'Version'
61
+ # 廠商交易編號
62
+ mapping :merchant_order_no, 'MerchantOrderNo'
63
+ mapping :order, 'MerchantOrderNo' # AM common
64
+ # 交易金額(幣別:新台幣)
65
+ mapping :amt, 'Amt'
66
+ mapping :amount, 'Amt' # AM common
67
+ # 商品資訊(限制長度50字)
68
+ mapping :product_desc, 'ProdDesc'
69
+ # 繳費超商 (not required)
70
+ mapping :allow_store, 'AllowStore'
71
+ # 支付通知網址
72
+ mapping :notify_url, 'NotifyURL'
73
+ # 繳費有限日期,格式範例:20140620 (YYYYmmdd)
74
+ mapping :expire_date, 'ExpireDate'
75
+ # 繳費有限時間,格式範例:235959 (HHMMSS)
76
+ mapping :expire_time, 'ExpireTime'
77
+ # 付款人電子信箱
78
+ mapping :email, 'Email'
79
+ mapping :credential3, 'CustomizedUrl'
80
+
81
+ def initialize(order, account, options = {})
82
+ super
83
+ add_field 'MerchantID', OffsitePayments::Integrations::Pay2goCvs.merchant_id
84
+ end
85
+
86
+ def credential_based_url
87
+ @fields['CustomizedUrl']
88
+ end
89
+
90
+ def encrypted_data
91
+ url_encrypted_data = OffsitePayments::Integrations::Pay2goCvs.fetch_url_encode_data(@fields)
92
+ add_field 'CheckValue', url_encrypted_data
93
+ end
94
+ end
95
+
96
+ class Notification < OffsitePayments::Notification
97
+ attr_accessor :_params
98
+
99
+ def _params
100
+ if @_params.nil?
101
+ if @params.key?("Result") # result data in json
102
+ @_params = @params
103
+ @_params = @_params.merge(JSON.parse(@_params['Result']))
104
+ else
105
+ @_params = @params
106
+ end
107
+ end
108
+ @_params
109
+ end
110
+
111
+ # TODO 使用查詢功能實作 acknowledge
112
+ # 而以 checksum_ok? 代替
113
+ def acknowledge
114
+ checksum_ok?
115
+ end
116
+
117
+ def complete?
118
+ case status
119
+ when 'SUCCESS' # 付款/取號成功
120
+ true
121
+ end
122
+ end
123
+
124
+ def calculate_checksum
125
+ params_copy = _params.clone
126
+
127
+ check_fields = [:"Amt", :"MerchantID", :"MerchantOrderNo", :"TradeNo"]
128
+ raw_data = params_copy.sort.map{|field, value|
129
+ "#{field}=#{value}" if check_fields.include?(field.to_sym)
130
+ }.compact.join('&')
131
+
132
+ hash_raw_data = "HashIV=#{OffsitePayments::Integrations::Pay2goCvs.hash_iv}&#{raw_data}&HashKey=#{OffsitePayments::Integrations::Pay2goCvs.hash_key}"
133
+
134
+ sha256 = Digest::SHA256.new
135
+ sha256.update hash_raw_data.force_encoding("utf-8")
136
+ sha256.hexdigest.upcase
137
+ end
138
+
139
+ def checksum_ok?
140
+ calculate_checksum == check_code.to_s
141
+ end
142
+
143
+ def status
144
+ _params['Status']
145
+ end
146
+
147
+ def message
148
+ URI.decode(_params['Message'])
149
+ end
150
+
151
+ def merchant_id
152
+ _params['MerchantID']
153
+ end
154
+
155
+ def amt
156
+ _params['Amt'].to_s
157
+ end
158
+
159
+ # 訂單號碼
160
+ def item_id
161
+ merchant_order_no
162
+ end
163
+
164
+ # Pay2goCvs 端訂單號碼
165
+ def transaction_id
166
+ trade_no
167
+ end
168
+
169
+ def trade_no
170
+ _params['TradeNo']
171
+ end
172
+
173
+ def merchant_order_no
174
+ _params['MerchantOrderNo']
175
+ end
176
+
177
+ def payment_type
178
+ _params['PaymentType']
179
+ end
180
+
181
+ def respond_type
182
+ _params['RespondType']
183
+ end
184
+
185
+ def check_code
186
+ _params['CheckCode']
187
+ end
188
+
189
+ def pay_time
190
+ URI.decode(_params['PayTime']).gsub("+", " ")
191
+ end
192
+
193
+ def ip
194
+ _params['IP']
195
+ end
196
+
197
+ def escrow_bank
198
+ _params['EscrowBank']
199
+ end
200
+
201
+ # credit card
202
+ def respond_code
203
+ _params['RespondCode']
204
+ end
205
+
206
+ def auth
207
+ _params['Auth']
208
+ end
209
+
210
+ def card_6no
211
+ _params['Card6No']
212
+ end
213
+
214
+ def card_4no
215
+ _params['Card4No']
216
+ end
217
+
218
+ def inst
219
+ _params['Inst']
220
+ end
221
+
222
+ def inst_first
223
+ _params['InstFirst']
224
+ end
225
+
226
+ def inst_each
227
+ _params['InstEach']
228
+ end
229
+
230
+ def eci
231
+ _params['ECI']
232
+ end
233
+
234
+ def token_use_status
235
+ _params['TokenUseStatus']
236
+ end
237
+
238
+ # web atm, atm
239
+ def pay_bank_code
240
+ _params['PayBankCode']
241
+ end
242
+
243
+ def payer_account_5code
244
+ _params['PayerAccount5Code']
245
+ end
246
+
247
+ # cvs
248
+ def code_no
249
+ _params['CodeNo']
250
+ end
251
+
252
+ # barcode
253
+ def barcode_1
254
+ _params['Barcode_1']
255
+ end
256
+
257
+ def barcode_2
258
+ _params['Barcode_2']
259
+ end
260
+
261
+ def barcode_3
262
+ _params['Barcode_3']
263
+ end
264
+
265
+ # other about serials
266
+ def expire_date
267
+ _params['ExpireDate']
268
+ end
269
+
270
+ end
271
+
272
+ class Fetcher
273
+ attr_accessor :params
274
+
275
+ def initialize(params)
276
+ raise 'parameter missmatch' if params['CheckValue'] != OffsitePayments::Integrations::Pay2goCvs.fetch_url_encode_data(params)
277
+ @params = pay2go_params(params)
278
+ end
279
+
280
+ def fetch
281
+ result = RestClient.post OffsitePayments::Integrations::Pay2goCvs.gateway_url, {
282
+ MerchantID_: OffsitePayments::Integrations::Pay2goCvs.merchant_id,
283
+ PostData_: self.class.encrypted_data(@params.to_query)
284
+ }
285
+ if @params['RespondType'] == 'JSON'
286
+ JSON.parse(result)
287
+ else
288
+ result
289
+ end
290
+ end
291
+
292
+ private
293
+
294
+ def pay2go_params(params)
295
+ params.slice(:RespondType, :TimeStamp, :Version, :MerchantOrderNo, :Amt, :ProdDesc, :AllowStore, :NotifyURL, :ExpireDate, :ExpireTime, :Email)
296
+ end
297
+
298
+ def self.padding(str, blocksize = 32)
299
+ len = str.size
300
+ pad = blocksize - (len % blocksize)
301
+ str += pad.chr * pad
302
+ end
303
+
304
+ def self.encrypted_data(data)
305
+ cipher = OpenSSL::Cipher::AES.new(256, :CBC)
306
+ cipher.encrypt
307
+ cipher.padding = 0
308
+ cipher.key = OffsitePayments::Integrations::Pay2goCvs.hash_key[0..31]
309
+ cipher.iv = OffsitePayments::Integrations::Pay2goCvs.hash_iv
310
+ data = self.padding(data)
311
+ encrypted = cipher.update(data) + cipher.final
312
+ encrypted.unpack('H*').first
313
+ end
314
+ end
315
+ end
316
+ end
317
+ end
@@ -0,0 +1,8 @@
1
+ require "offsite_payments_pay2go_cvs/version"
2
+ require "offsite_payments"
3
+
4
+ module OffsitePayments
5
+ module Integrations
6
+ autoload :Pay2goCvs, "offsite_payments/integrations/pay2go_cvs"
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module OffsitePaymentsPay2goCvs
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,42 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "offsite_payments_pay2go_cvs/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "offsite_payments_pay2go_cvs"
7
+ spec.version = OffsitePaymentsPay2goCvs::VERSION
8
+ spec.authors = ["hrs", "stan"]
9
+ spec.email = ["hrs113355@gmail.com", "solve153@gmail.com"]
10
+
11
+ spec.summary = %q{OffsitePayments for Pay2go_cvs, a Taiwan based payment gateway}
12
+ spec.description = %q{OffsitePayments for Pay2go_cvs}
13
+ spec.homepage = "https://github.com/GoodLife/offsite_payments_pay2go_cvs"
14
+ spec.license = "MIT"
15
+
16
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
17
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
18
+ if spec.respond_to?(:metadata)
19
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
20
+
21
+ spec.metadata["homepage_uri"] = spec.homepage
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
28
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
29
+ end
30
+ spec.bindir = "exe"
31
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
32
+ spec.require_paths = ["lib"]
33
+
34
+ spec.add_runtime_dependency 'money', '>= 6'
35
+ spec.add_runtime_dependency 'offsite_payments', '>= 2.7'
36
+
37
+ spec.add_development_dependency "bundler"
38
+ spec.add_development_dependency "rake"
39
+ spec.add_development_dependency "test-unit", "~> 3.0"
40
+ spec.add_development_dependency "mocha", "~> 1.0"
41
+ spec.add_development_dependency "rails", ">= 3.2.14"
42
+ end
metadata ADDED
@@ -0,0 +1,159 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: offsite_payments_pay2go_cvs
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - hrs
8
+ - stan
9
+ autorequire:
10
+ bindir: exe
11
+ cert_chain: []
12
+ date: 2019-05-23 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: money
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '6'
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: '6'
28
+ - !ruby/object:Gem::Dependency
29
+ name: offsite_payments
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '2.7'
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '2.7'
42
+ - !ruby/object:Gem::Dependency
43
+ name: bundler
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - ">="
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ type: :development
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '0'
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ - !ruby/object:Gem::Dependency
71
+ name: test-unit
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: '3.0'
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: '3.0'
84
+ - !ruby/object:Gem::Dependency
85
+ name: mocha
86
+ requirement: !ruby/object:Gem::Requirement
87
+ requirements:
88
+ - - "~>"
89
+ - !ruby/object:Gem::Version
90
+ version: '1.0'
91
+ type: :development
92
+ prerelease: false
93
+ version_requirements: !ruby/object:Gem::Requirement
94
+ requirements:
95
+ - - "~>"
96
+ - !ruby/object:Gem::Version
97
+ version: '1.0'
98
+ - !ruby/object:Gem::Dependency
99
+ name: rails
100
+ requirement: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: 3.2.14
105
+ type: :development
106
+ prerelease: false
107
+ version_requirements: !ruby/object:Gem::Requirement
108
+ requirements:
109
+ - - ">="
110
+ - !ruby/object:Gem::Version
111
+ version: 3.2.14
112
+ description: OffsitePayments for Pay2go_cvs
113
+ email:
114
+ - hrs113355@gmail.com
115
+ - solve153@gmail.com
116
+ executables: []
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".gitignore"
121
+ - CODE_OF_CONDUCT.md
122
+ - Gemfile
123
+ - Gemfile.lock
124
+ - LICENSE.txt
125
+ - README.md
126
+ - Rakefile
127
+ - bin/console
128
+ - bin/setup
129
+ - lib/offsite_payments/integrations/pay2go_cvs.rb
130
+ - lib/offsite_payments_pay2go_cvs.rb
131
+ - lib/offsite_payments_pay2go_cvs/version.rb
132
+ - offsite_payments_pay2go_cvs.gemspec
133
+ homepage: https://github.com/GoodLife/offsite_payments_pay2go_cvs
134
+ licenses:
135
+ - MIT
136
+ metadata:
137
+ allowed_push_host: https://rubygems.org
138
+ homepage_uri: https://github.com/GoodLife/offsite_payments_pay2go_cvs
139
+ post_install_message:
140
+ rdoc_options: []
141
+ require_paths:
142
+ - lib
143
+ required_ruby_version: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ version: '0'
148
+ required_rubygems_version: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ requirements: []
154
+ rubyforge_project:
155
+ rubygems_version: 2.2.5
156
+ signing_key:
157
+ specification_version: 4
158
+ summary: OffsitePayments for Pay2go_cvs, a Taiwan based payment gateway
159
+ test_files: []