active_merchant-epsilon 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/.env.sample +3 -0
  3. data/.gitignore +17 -0
  4. data/CHANGELOG.md +29 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +256 -0
  8. data/Rakefile +19 -0
  9. data/active_merchant-epsilon.gemspec +31 -0
  10. data/lib/active_merchant/billing/convenience_store.rb +55 -0
  11. data/lib/active_merchant/billing/gateways/epsilon.rb +194 -0
  12. data/lib/active_merchant/billing/gateways/epsilon/epsilon_base.rb +132 -0
  13. data/lib/active_merchant/billing/gateways/epsilon/epsilon_mission_code.rb +30 -0
  14. data/lib/active_merchant/billing/gateways/epslion_convenience_store.rb +27 -0
  15. data/lib/active_merchant/epsilon.rb +9 -0
  16. data/lib/active_merchant/epsilon/version.rb +5 -0
  17. data/test/fixtures/vcr_cassettes/autheticate_three_d_secure_card_successful.yml +46 -0
  18. data/test/fixtures/vcr_cassettes/cancel_recurring_fail.yml +82 -0
  19. data/test/fixtures/vcr_cassettes/cancel_recurring_successful.yml +83 -0
  20. data/test/fixtures/vcr_cassettes/change_recurring_amount_failure.yml +85 -0
  21. data/test/fixtures/vcr_cassettes/change_recurring_amount_successful.yml +85 -0
  22. data/test/fixtures/vcr_cassettes/convenience_store_purchase_fail.yml +39 -0
  23. data/test/fixtures/vcr_cassettes/convenience_store_purchase_successful.yml +50 -0
  24. data/test/fixtures/vcr_cassettes/find_user_failure.yml +44 -0
  25. data/test/fixtures/vcr_cassettes/find_user_success.yml +44 -0
  26. data/test/fixtures/vcr_cassettes/installment_purchase_successful.yml +46 -0
  27. data/test/fixtures/vcr_cassettes/purchase_fail.yml +45 -0
  28. data/test/fixtures/vcr_cassettes/purchase_successful.yml +46 -0
  29. data/test/fixtures/vcr_cassettes/purchase_with_three_d_secure_card_successful.yml +45 -0
  30. data/test/fixtures/vcr_cassettes/purchase_with_verification_value.yml +46 -0
  31. data/test/fixtures/vcr_cassettes/recurring_fail.yml +45 -0
  32. data/test/fixtures/vcr_cassettes/recurring_successful.yml +46 -0
  33. data/test/fixtures/vcr_cassettes/registered_purchase_fail.yml +45 -0
  34. data/test/fixtures/vcr_cassettes/registered_purchase_successful.yml +46 -0
  35. data/test/fixtures/vcr_cassettes/registered_recurring_fail.yml +45 -0
  36. data/test/fixtures/vcr_cassettes/registered_recurring_successful.yml +46 -0
  37. data/test/fixtures/vcr_cassettes/revolving_purchase_successful.yml +46 -0
  38. data/test/fixtures/vcr_cassettes/terminate_recurring_fail.yml +96 -0
  39. data/test/fixtures/vcr_cassettes/terminate_recurring_successful.yml +82 -0
  40. data/test/fixtures/vcr_cassettes/verify_fail.yml +45 -0
  41. data/test/fixtures/vcr_cassettes/verify_successful.yml +85 -0
  42. data/test/fixtures/vcr_cassettes/void_fail.yml +42 -0
  43. data/test/fixtures/vcr_cassettes/void_successful.yml +85 -0
  44. data/test/remote/gateways/remote_epsilon_convenience_store_test.rb +27 -0
  45. data/test/remote/gateways/remote_epsilon_test.rb +249 -0
  46. data/test/test_helper.rb +162 -0
  47. data/test/unit/gateways/epsilon_test.rb +11 -0
  48. data/wercker.yml +18 -0
  49. metadata +248 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: de0b3aa4a30a45fb2382fd5ffc122fa5ee478aaa
4
+ data.tar.gz: 44fbd6b127ffcf0fa4d463928a697664d94d6f25
5
+ SHA512:
6
+ metadata.gz: 1f7e2bafadd6cd3568cc254bf51d1191b2e4fb387f92ae48280ebecf7e8f4c646e0280bae804515d126b56c56d94ec410a9a3486e0245c78c64d6802f25901c9
7
+ data.tar.gz: cc2295750c7519d4fca101273b89ae1272c39988e2c28a84de1557517c6590fa93f19ece59f7701fe6d3da6f34b631fee08d92ce2739d06b009ff27c8c255993
@@ -0,0 +1,3 @@
1
+ CONTRACT_CODE=00000000
2
+ PROXY_ADDRESS=http://myproxy.com # if you need
3
+ PROXY_PORT=8888 # if you need
@@ -0,0 +1,17 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
15
+
16
+ .env
17
+ .ruby-version
@@ -0,0 +1,29 @@
1
+ # CHANGELOG
2
+
3
+ ### 0.5.0
4
+
5
+ * Separate ConvenienceStorePayment from EpsilonGateway and Create new gateway
6
+ * Require user_name in detail for purchase method
7
+ * Rename number_of_payments to payment_time
8
+ * Remove ActiveMerchant::Epsilon::InvalidActionError
9
+ * Remove ActiveMerchant::Epsilon::InvalidPaymentMethodError
10
+
11
+ ### 0.4.0
12
+
13
+ * Support credit card installment payment
14
+ * Support credit card revolving payment
15
+ * Fix response of credit card payment with 3D secure
16
+ * Remove raw_ssl_request method
17
+
18
+ ### 0.3.0
19
+
20
+ * Support credit card payment with 3D secure
21
+ * Disable to specify contract_code with purchase_detail
22
+
23
+ ### 0.2.0
24
+
25
+ * Specification user_name with purchase_detail
26
+
27
+ ### 0.1.0
28
+
29
+ * CreditCard verification_value is required by default
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in active_merchant-epsilon.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 GMO Pepabo, Inc.
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,256 @@
1
+ # ActiveMerchant::Epsilon
2
+ [![wercker status](https://app.wercker.com/status/43c6648e20f325c8c0a560c36e89781c/s/master "wercker status")](https://app.wercker.com/project/bykey/43c6648e20f325c8c0a560c36e89781c)
3
+
4
+ Epsilon integration for ActiveMerchant.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'active_merchant-epsilon'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install active_merchant-epsilon
21
+
22
+ ## Usage
23
+
24
+ ### Settings
25
+
26
+ An example Rails initializer would look something like this:
27
+
28
+ ```ruby
29
+ ActiveMerchant::Billing::Base.mode = :production
30
+ ActiveMerchant::Billing::EpsilonGateway.contract_code = '12345678'
31
+ ActiveMerchant::Billing::EpsilonGateway.proxy_port = 8080
32
+ ActiveMerchant::Billing::EpsilonGateway.proxy_address = 'myproxy.dev'
33
+ ```
34
+
35
+ ### CreditCard Payment
36
+
37
+ ```ruby
38
+ require 'active_merchant'
39
+
40
+ ActiveMerchant::Billing::Base.mode = :test
41
+
42
+ ActiveMerchant::Billing::EpsilonGateway.contract_code = 'YOUR_CONTRACT_CODE'
43
+
44
+ gateway = ActiveMerchant::Billing::EpsilonGateway.new
45
+
46
+ amount = 10000
47
+
48
+ ActiveMerchant::Billing::CreditCard.require_verification_value = true
49
+
50
+ credit_card = ActiveMerchant::Billing::CreditCard.new(
51
+ first_name: 'TARO',
52
+ last_name: 'YAMADA',
53
+ number: '4242424242424242',
54
+ month: '10',
55
+ year: Time.now.year + 1,
56
+ verification_value: '000', # security code
57
+ )
58
+
59
+ purchase_detail = {
60
+ user_id: 'YOUR_APP_USER_IDENTIFIER',
61
+ user_name: '山田 太郎',
62
+ user_email: 'yamada-taro@example.com',
63
+ item_code: 'ITEM001',
64
+ item_name: 'Greate Product',
65
+ order_number: 'UNIQUE ORDER NUMBER',
66
+ }
67
+
68
+ if credit_card.validate.empty?
69
+ # Capture 10000 yen from the credit card
70
+ response = gateway.purchase(amount, credit_card, purchase_detail)
71
+
72
+ if response.success?
73
+ puts "Successfully charged #{amount} yen to the credit card #{credit_card.display_number}"
74
+ else
75
+ raise StandardError, response.message
76
+ end
77
+ end
78
+ ```
79
+
80
+ ### CreditCard Payment with 3D secure
81
+
82
+ ```ruby
83
+ amount = 10000
84
+
85
+ ActiveMerchant::Billing::CreditCard.require_verification_value = true
86
+
87
+ credit_card = ActiveMerchant::Billing::CreditCard.new(
88
+ first_name: 'TARO',
89
+ last_name: 'YAMADA',
90
+ number: '4242424242424242',
91
+ month: '10',
92
+ year: Time.now.year + 1,
93
+ verification_value: '000', # security code
94
+ )
95
+
96
+ purchase_detail = {
97
+ user_id: 'YOUR_APP_USER_IDENTIFIER',
98
+ user_name: '山田 太郎',
99
+ user_email: 'yamada-taro@example.com',
100
+ item_code: 'ITEM001',
101
+ item_name: 'Greate Product',
102
+ order_number: 'UNIQUE ORDER NUMBER',
103
+ three_d_secure_check_code: 1,
104
+ }
105
+
106
+ if credit_card.validate.empty?
107
+ response = gateway.purchase(amount, credit_card, purchase_detail)
108
+
109
+ raise StandardError, response.message unless response.success?
110
+
111
+ if response.params['three_d_secure']
112
+ puts response.params['acs_url']
113
+ puts response.params['pareq']
114
+ else
115
+ # NOT 3D SECURE
116
+ puts "Successfully charged #{amount} yen to the credit card #{credit_card.display_number}"
117
+ end
118
+ end
119
+
120
+ # (The card holder identifies himself on credit card's page and comes back here)
121
+
122
+ # AND SECOND REQUEST
123
+
124
+ response = gateway.authenticate(
125
+ order_number: 'ORDER NUMBER',
126
+ three_d_secure_pares: 'PAYMENT AUTHENTICATION RESPONSE',
127
+ )
128
+
129
+ if response.success?
130
+ puts "Successfully charged to the credit card"
131
+ else
132
+ raise StandardError, response.message
133
+ end
134
+ ```
135
+
136
+ ### CreditCard Installment Payment
137
+
138
+ ```ruby
139
+ # (snip)
140
+
141
+ purchase_detail = {
142
+ user_id: 'YOUR_APP_USER_IDENTIFIER',
143
+ user_name: '山田 太郎',
144
+ user_email: 'yamada-taro@example.com',
145
+ item_code: 'ITEM001',
146
+ item_name: 'Greate Product',
147
+ order_number: 'UNIQUE ORDER NUMBER',
148
+ credit_type: ActiveMerchant::Billing::EpsilonGateway::CreditType::INSTALLMENT,
149
+ payment_time: 3, # 3, 5, 6, 10, 12, 15, 18, 20, 24
150
+ }
151
+
152
+ # (snip)
153
+ ```
154
+
155
+ ### CreditCard Revolving Payment
156
+
157
+ ```ruby
158
+ # (snip)
159
+
160
+ purchase_detail = {
161
+ user_id: 'YOUR_APP_USER_IDENTIFIER',
162
+ user_name: '山田 太郎',
163
+ user_email: 'yamada-taro@example.com',
164
+ item_code: 'ITEM001',
165
+ item_name: 'Greate Product',
166
+ order_number: 'UNIQUE ORDER NUMBER',
167
+ credit_type: ActiveMerchant::Billing::EpsilonGateway::CreditType::REVOLVING,
168
+ }
169
+
170
+ # (snip)
171
+ ```
172
+
173
+ ### Convenience Store Payment
174
+
175
+ ```ruby
176
+ ActiveMerchant::Billing::EpsilonConvenienceStoreGateway.contract_code = 'YOUR_CONTRACT_CODE'
177
+
178
+ gateway = ActiveMerchant::Billing::EpsilonConvenienceStoreGateway.new
179
+
180
+ convenience_store = ActiveMerchant::Billing::ConvenienceStore.new(
181
+ code: ActiveMerchant::Billing::ConvenienceStore::Code::LAWSON,
182
+ full_name_kana: 'ヤマダ タロウ',
183
+ phone_nubmer: '0312345678'
184
+ )
185
+
186
+ purchase_detail = {
187
+ user_id: 'YOUR_APP_USER_IDENTIFIER',
188
+ user_name: '山田 太郎',
189
+ user_email: 'yamada-taro@example.com',
190
+ item_code: 'ITEM001',
191
+ item_name: 'Greate Product',
192
+ order_number: 'UNIQUE ORDER NUMBER',
193
+ }
194
+
195
+ if credit_card.validate.empty?
196
+ # 10000 yen as convenience store paymet
197
+ response = gateway.purchase(amount, convenience_store, purchase_detail)
198
+
199
+ if response.success?
200
+ puts "Successfully charged #{amount} yen as convenience store payment"
201
+ puts "Receipt number is #{response.params['receipt_number']}"
202
+ puts "Payment limit date is #{response.params['convenience_store_limit_date']}"
203
+ else
204
+ raise StandardError, response.message
205
+ end
206
+ end
207
+ ```
208
+
209
+ ### Recurring Billing (Monthly subscritpion)
210
+
211
+ ```ruby
212
+ purchase_detail[:mission_code] = ActiveMerchant::Billing::EpsilonGateway::MissionCode::RECURRING_6
213
+
214
+ gateway.recurring(amount, creadit_card, purchase_detail)
215
+ ```
216
+
217
+ ### Cancel recurring billing
218
+
219
+ ```ruby
220
+ gateway.cancel_recurring(user_id: 'user_id', item_code: 'item_code')
221
+ ```
222
+
223
+ ### Void Transaction
224
+
225
+ ```ruby
226
+ gateway.void('order_number')
227
+ ```
228
+
229
+ ### Verify Credit Card
230
+
231
+ ```ruby
232
+ gateway.verify(credit_card, user_id: 'user_id', user_email: 'user@example.com')
233
+ ```
234
+
235
+ ### Error handling
236
+
237
+ If epsilon server returns status excepted 200, `#purchase` method raise `ActiveMerchant::ResponseError`.
238
+
239
+ When your request parameters are wrong(e.g. contract_code), the method return failuer response.
240
+
241
+ - `#success?` returns `false`
242
+ - `#params` has error detail
243
+
244
+ ```ruby
245
+ response = gateway.purchase(10000, creadit_card, invalid_detail)
246
+
247
+ response.success? # => false
248
+ response.params # => Hash included error detail
249
+ ```
250
+
251
+ ## Contributing
252
+
253
+ 1. Create your feature branch (`git checkout -b my-new-feature`)
254
+ 2. Commit your changes (`git commit -am 'Add some feature'`)
255
+ 3. Push to the branch (`git push origin my-new-feature`)
256
+ 4. Create a new Pull Request
@@ -0,0 +1,19 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ desc 'Run the unit test suite'
5
+ task :defualt => 'test:unit'
6
+
7
+ namespace :test do
8
+ Rake::TestTask.new(:unit) do |t|
9
+ t.pattern = 'test/unit/**/*_test.rb'
10
+ t.libs << 'test'
11
+ t.verbose = true
12
+ end
13
+
14
+ Rake::TestTask.new(:remote) do |t|
15
+ t.pattern = 'test/remote/**/*_test.rb'
16
+ t.libs << 'test'
17
+ t.verbose = true
18
+ end
19
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'active_merchant/epsilon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'active_merchant-epsilon'
8
+ spec.version = ActiveMerchant::Epsilon::VERSION
9
+ spec.authors = ['Kenichi TAKAHASHI']
10
+ spec.email = ['kenichi.taka@gmail.com']
11
+ spec.summary = %q{Epsilon integration for ActiveMerchant.}
12
+ spec.description = %q{Epsilon integration for ActiveMerchant.}
13
+ spec.homepage = 'http://github.com/pepabo/active_merchant-epsilon'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ['lib']
20
+
21
+ spec.add_dependency 'activemerchant', '~> 1.48.0'
22
+ spec.add_dependency 'nokogiri'
23
+
24
+ spec.add_development_dependency 'bundler', '~> 1.7'
25
+ spec.add_development_dependency 'dotenv'
26
+ spec.add_development_dependency 'pry-byebug'
27
+ spec.add_development_dependency 'rake', '~> 10.0'
28
+ spec.add_development_dependency 'tapp'
29
+ spec.add_development_dependency 'webmock'
30
+ spec.add_development_dependency 'vcr'
31
+ end
@@ -0,0 +1,55 @@
1
+ module ActiveMerchant
2
+ module Billing
3
+ class ConvenienceStore < Model
4
+ module Code
5
+ SEVEN_ELEVEN = 11
6
+ FAMILY_MART = 21
7
+ LAWSON = 31
8
+ SEICO_MART = 32
9
+ end
10
+
11
+ def initialize(code:, full_name_kana:, phone_number:)
12
+ @code = code
13
+ @full_name_kana = full_name_kana
14
+ @phone_number = phone_number
15
+ end
16
+
17
+ def code
18
+ @code
19
+ end
20
+
21
+ def name
22
+ @full_name_kana
23
+ end
24
+
25
+ def phone_number
26
+ @phone_number
27
+ end
28
+
29
+ def validate
30
+ errors_hash(validate_essential_attributes)
31
+ end
32
+
33
+ private
34
+
35
+ def validate_essential_attributes
36
+ errors = []
37
+
38
+ if code.blank?
39
+ errors << [:code, "is required"]
40
+ elsif !valid_code?(code)
41
+ errors << [:code, "is invalid"]
42
+ end
43
+
44
+ errors << [:full_name_kana, "is required"] if name.blank?
45
+ errors << [:phone_number, "is required"] if phone_number.blank?
46
+
47
+ errors
48
+ end
49
+
50
+ def valid_code?(code)
51
+ [SEVEN_ELEVEN, FAMILY_MART, LAWSON, SEICO_MART].include?(code.to_i)
52
+ end
53
+ end
54
+ end
55
+ end