spree-alpha-card 0.0.1 → 0.0.2

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
2
  SHA1:
3
- metadata.gz: 78ed63682e84c410e8f9d30af5f73d4a3e930a43
4
- data.tar.gz: 08ddb37006c38a2194b275b27903b5a67f46d28f
3
+ metadata.gz: 7a430d112d3d9480cd0b2276dd780ecd682b5aa8
4
+ data.tar.gz: 7f7bd5a820e6f624607de15341ee3e0650e87f64
5
5
  SHA512:
6
- metadata.gz: 52841262de81f7ffd1c32de9298fe49d16d738ff45f0f50b8061a4d58839b6230930393f43164d359846babbbb9dd36d4e1ae855ac313f87f23c85f7f496dbc3
7
- data.tar.gz: 01b1f519ebd8dddb945f0d3d73996e06d84adfcdbb8f5baca2c6218d79881194bd0edb47e42583bfe248fed3acabda9e9b3422f0db67dddced01ec511bfe5067
6
+ metadata.gz: 28b6f9f2a9a44599c7c956d24d75fbec3cfbb8fb7effdafa60ed42314bfe779cbb01c637e7f96cc129ba5a2555f5644192d49de4a2ab335986ca474705ac0dd1
7
+ data.tar.gz: b9a29e15c615ab271d29ac9a24672cbfc3efb4ddbc4532c9cbeaf9d1ba67e6b4df37050b59d76419c2ce98788c7cab9d3e85a2be1dd0cb3ac8dbead58b56146a
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ /spec/dummy
data/Gemfile.lock CHANGED
@@ -77,6 +77,8 @@ GEM
77
77
  descendants_tracker (~> 0.0.1)
78
78
  colorize (0.7.7)
79
79
  columnize (0.9.0)
80
+ crack (0.4.2)
81
+ safe_yaml (~> 1.0.0)
80
82
  css_parser (1.3.6)
81
83
  addressable
82
84
  deface (1.0.1)
@@ -208,6 +210,7 @@ GEM
208
210
  rspec-mocks (~> 3.2.0)
209
211
  rspec-support (~> 3.2.0)
210
212
  rspec-support (3.2.2)
213
+ safe_yaml (1.0.4)
211
214
  sass (3.2.19)
212
215
  sass-rails (4.0.5)
213
216
  railties (>= 4.0.0, < 5.0)
@@ -271,11 +274,15 @@ GEM
271
274
  unf (0.1.4)
272
275
  unf_ext
273
276
  unf_ext (0.0.7.1)
277
+ vcr (2.9.3)
274
278
  virtus (1.0.5)
275
279
  axiom-types (~> 0.1)
276
280
  coercible (~> 1.0)
277
281
  descendants_tracker (~> 0.0, >= 0.0.3)
278
282
  equalizer (~> 0.0, >= 0.0.9)
283
+ webmock (1.21.0)
284
+ addressable (>= 2.3.6)
285
+ crack (>= 0.3.2)
279
286
 
280
287
  PLATFORMS
281
288
  ruby
@@ -291,6 +298,8 @@ DEPENDENCIES
291
298
  sass-rails (~> 4.0.2)
292
299
  spree-alpha-card!
293
300
  sqlite3
301
+ vcr
302
+ webmock
294
303
 
295
304
  BUNDLED WITH
296
305
  1.10.2
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require 'spree/testing_support/common_rake'
2
+
3
+ task :default => [:spec]
4
+
5
+ desc 'Generates a dummy app for testing'
6
+ task :test_app do
7
+ ENV['LIB_NAME'] = 'spree-alpha-card'
8
+ Rake::Task['common:test_app'].invoke
9
+ end
10
+
@@ -41,12 +41,7 @@ module Spree
41
41
 
42
42
 
43
43
 
44
-
45
-
46
44
  def purchase money, credit_card, options = {}
47
- logger.debug "-"*1024
48
- logger.debug "AlphaCardGateway#purchase..."
49
-
50
45
  opts = {
51
46
  type: 'sale',
52
47
  email: options[:email],
@@ -56,41 +51,21 @@ module Spree
56
51
  add_money! opts, money, options
57
52
  add_credit_card! opts, credit_card
58
53
 
59
- res = ::AlphaCard.request opts, account
60
-
61
- logger.debug res.inspect
62
- logger.debug "-"*1024
63
-
64
- ActiveMerchant::Billing::Response.new res.success?, "AlphaCardGateway#purchase: #{res.text}", res.data, response_params(res)
54
+ request opts, 'purchase'
65
55
  end
66
56
 
67
57
 
68
58
 
69
- # TODO implement #credit to support credit & refund in admin area
70
- #
71
- # problem: cc number is not stored, therefore payment profiles at gateway is probably required & needs to be implemented
72
- #
73
- #
74
- # STATUS current implementation does not work!
75
- #
76
59
  def credit money, reference, options = {}
77
- logger.debug "-"*1024
78
- logger.debug "AlphaCardGateway#credit..."
79
-
80
60
  opts = {type: 'credit'}
81
61
  add_money! opts, money, currency: options[:originator].payment.currency
82
- add_credit_card! opts, options[:originator].payment.source
62
+ opts[:transactionid] = reference
83
63
 
84
- res = ::AlphaCard.request opts, account
85
-
86
- logger.debug "-"*1024
87
-
88
- ActiveMerchant::Billing::Response.new res.success?, "AlphaCardGateway#credit: #{res.text}", res.data, response_params(res)
64
+ request opts, 'credit'
89
65
  end
90
66
 
91
67
 
92
68
 
93
-
94
69
  protected
95
70
 
96
71
  def spree_money_to_alpha_card cents
@@ -119,16 +94,25 @@ module Spree
119
94
  opts.merge! ccnumber: cc.number, ccexp: exp
120
95
  end
121
96
 
122
- def response_params result
97
+ def request opts, originator
98
+ begin
99
+ res = provider.request opts, account
100
+ ActiveMerchant::Billing::Response.new res.success?, "AlphaCardGateway##{originator}: #{res.text}", res.data, response_params(res.data)
101
+ rescue ::AlphaCard::AlphaCardError => e
102
+ ActiveMerchant::Billing::Response.new false, "AlphaCardGateway##{originator}: #{e.message}", e.response.data, response_params(e.response.data)
103
+ end
104
+ end
105
+
106
+ def response_params data
123
107
  options = {
124
108
  test: test?,
125
- authorization: result.data['authcode'],
126
- avs_result: result.data['avsresponse'].presence,
127
- cvv_result: result.data['cvvresponse'].presence,
109
+ authorization: data['authcode'].presence,
110
+ avs_result: data['avsresponse'].presence,
111
+ cvv_result: data['cvvresponse'].presence,
128
112
  }
129
113
 
130
- unless result.success?
131
- options[:error_code] = result.data['response_code']
114
+ unless data['response_code'] == '100'
115
+ options[:error_code] = data['response_code']
132
116
  end
133
117
 
134
118
  options
@@ -1,6 +1,6 @@
1
1
  module Spree
2
2
  module AlphaCard
3
- VERSION = '0.0.1'
3
+ VERSION = '0.0.2'
4
4
  end
5
5
  end
6
6
 
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://secure.alphacardgateway.com/api/transact.php
6
+ body:
7
+ encoding: US-ASCII
8
+ string: type=credit&amount=67.99&currency=USD&transactionid=123456&username=demo&password=password
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Length:
15
+ - '90'
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Wed, 10 Jun 2015 15:36:13 GMT
27
+ Server:
28
+ - Apache
29
+ Content-Length:
30
+ - '152'
31
+ Content-Type:
32
+ - text/html; charset=UTF-8
33
+ body:
34
+ encoding: UTF-8
35
+ string: response=3&responsetext=Transaction not found REFID:3157461142&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=&type=credit&response_code=300
36
+ http_version:
37
+ recorded_at: Wed, 10 Jun 2015 15:36:14 GMT
38
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://secure.alphacardgateway.com/api/transact.php
6
+ body:
7
+ encoding: US-ASCII
8
+ string: type=sale&email=l%40larskluge.com&orderid=12345678&ipaddress=&amount=10.00&currency=USD&ccnumber=1234123412341234&ccexp=0715&username=demo&password=password
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Length:
15
+ - '156'
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Wed, 10 Jun 2015 16:01:55 GMT
27
+ Server:
28
+ - Apache
29
+ Content-Length:
30
+ - '163'
31
+ Content-Type:
32
+ - text/html; charset=UTF-8
33
+ body:
34
+ encoding: UTF-8
35
+ string: response=3&responsetext=Invalid Credit Card Number REFID:3157462326&authcode=&transactionid=&avsresponse=&cvvresponse=&orderid=12345678&type=sale&response_code=300
36
+ http_version:
37
+ recorded_at: Wed, 10 Jun 2015 16:01:56 GMT
38
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://secure.alphacardgateway.com/api/transact.php
6
+ body:
7
+ encoding: US-ASCII
8
+ string: type=sale&email=l%40larskluge.com&orderid=12345678&ipaddress=&amount=0.99&currency=USD&ccnumber=4111111111111111&ccexp=0715&username=demo&password=password
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Length:
15
+ - '155'
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Wed, 10 Jun 2015 15:57:16 GMT
27
+ Server:
28
+ - Apache
29
+ Content-Length:
30
+ - '137'
31
+ Content-Type:
32
+ - text/html; charset=UTF-8
33
+ body:
34
+ encoding: UTF-8
35
+ string: response=2&responsetext=DECLINE&authcode=&transactionid=2708356296&avsresponse=&cvvresponse=&orderid=12345678&type=sale&response_code=200
36
+ http_version:
37
+ recorded_at: Wed, 10 Jun 2015 15:57:18 GMT
38
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,38 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: post
5
+ uri: https://secure.alphacardgateway.com/api/transact.php
6
+ body:
7
+ encoding: US-ASCII
8
+ string: type=sale&email=l%40larskluge.com&orderid=12345678&ipaddress=&amount=256.67&currency=USD&ccnumber=4111111111111111&ccexp=0715&username=demo&password=password
9
+ headers:
10
+ Accept:
11
+ - "*/*; q=0.5, application/xml"
12
+ Accept-Encoding:
13
+ - gzip, deflate
14
+ Content-Length:
15
+ - '157'
16
+ Content-Type:
17
+ - application/x-www-form-urlencoded
18
+ User-Agent:
19
+ - Ruby
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Date:
26
+ - Wed, 10 Jun 2015 13:54:43 GMT
27
+ Server:
28
+ - Apache
29
+ Content-Length:
30
+ - '143'
31
+ Content-Type:
32
+ - text/html; charset=UTF-8
33
+ body:
34
+ encoding: UTF-8
35
+ string: response=1&responsetext=SUCCESS&authcode=123456&transactionid=2708218696&avsresponse=&cvvresponse=&orderid=12345678&type=sale&response_code=100
36
+ http_version:
37
+ recorded_at: Wed, 10 Jun 2015 13:54:44 GMT
38
+ recorded_with: VCR 2.9.3
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+
4
+ RSpec.describe Spree::Gateway::AlphaCardGateway do
5
+
6
+ let(:provider) { described_class.new }
7
+
8
+ let(:cc) do
9
+ cc = double('credit_card')
10
+ allow(cc).to receive(:year).and_return("2015")
11
+ allow(cc).to receive(:month).and_return("7")
12
+ allow(cc).to receive(:number).and_return("4" + "1"*15)
13
+ cc
14
+ end
15
+
16
+
17
+ context 'basics' do
18
+
19
+ it 'uses itself as provider class' do
20
+ expect(provider).to be_an_instance_of(described_class)
21
+ end
22
+
23
+ end
24
+
25
+ context '#spree_money_to_alpha_card' do
26
+
27
+ it 'formats cents correctly' do
28
+ expect(provider.send :spree_money_to_alpha_card, 254_67).to eq("254.67")
29
+ expect(provider.send :spree_money_to_alpha_card, 99).to eq("0.99")
30
+ expect(provider.send :spree_money_to_alpha_card, 6).to eq("0.06")
31
+ expect(provider.send :spree_money_to_alpha_card, 199_06).to eq("199.06")
32
+ end
33
+
34
+ end
35
+
36
+
37
+ context '#add_credit_card!' do
38
+
39
+ it 'sets the date correctly' do
40
+ o = {}
41
+ provider.send :add_credit_card!, o, cc
42
+ expect(o).to include(ccexp: "0715")
43
+ end
44
+
45
+ it 'returns the card number' do
46
+ o = {}
47
+ provider.send :add_credit_card!, o, cc
48
+ expect(o).to include(ccnumber: '4111111111111111')
49
+ end
50
+
51
+ end
52
+
53
+
54
+ context 'api calls' do
55
+
56
+ before :each do
57
+ provider.set_preference :login, "demo"
58
+ provider.set_preference :password, "password"
59
+ end
60
+
61
+ context '#purchase' do
62
+
63
+ let(:opts) do
64
+ {
65
+ email: "l@larskluge.com",
66
+ order_id: "12345678",
67
+ ipaddress: "::1",
68
+ currency: "USD",
69
+ }
70
+ end
71
+
72
+ it 'purchases successfully' do
73
+ response = VCR.use_cassette("simple purchase") do
74
+ provider.purchase 256_67, cc, opts
75
+ end
76
+
77
+ expect(response).to be_an_instance_of(::ActiveMerchant::Billing::Response)
78
+ expect(response).to be_success
79
+ expect(response.params).to include("type" => "sale")
80
+ expect(response.authorization).to eq("123456")
81
+ expect(response.error_code).to be_nil
82
+ end
83
+
84
+ it 'declines a low amount' do
85
+ response = VCR.use_cassette("purchase: low amount") do
86
+ provider.purchase 99, cc, opts
87
+ end
88
+
89
+ expect(response).to be_an_instance_of(::ActiveMerchant::Billing::Response)
90
+ expect(response).to_not be_success
91
+ expect(response.authorization).to be_nil
92
+ expect(response.message).to match(/declined/i)
93
+ expect(response.error_code).to eq("200")
94
+ end
95
+
96
+ it 'tests a fatal error; cc number invalid' do
97
+ allow(cc).to receive(:number).and_return("1234"*4)
98
+
99
+
100
+ response = VCR.use_cassette("purchase: invalid cc number") do
101
+ provider.purchase 10_00, cc, opts
102
+ end
103
+
104
+ expect(response).to be_an_instance_of(::ActiveMerchant::Billing::Response)
105
+ expect(response).to_not be_success
106
+ expect(response.authorization).to be_nil
107
+ expect(response.message).to match(/invalid credit card number/i)
108
+ expect(response.error_code).to eq("300")
109
+ end
110
+
111
+ end
112
+
113
+ context '#credit' do
114
+
115
+ it 'credits fails b/c alpha card test endpoint does not provide a valid transaction id for testing' do
116
+ payment = double("Spree::Payment", currency: "USD")
117
+ refund = double("Spree::Refund", payment: payment)
118
+ opts = {originator: refund}
119
+
120
+ response = VCR.use_cassette('credit without valid transaction id') do
121
+ provider.credit 67_99, "123456", opts
122
+ end
123
+
124
+ expect(response).to be_an_instance_of(::ActiveMerchant::Billing::Response)
125
+ expect(response).to_not be_success
126
+ expect(response.message).to match(/transaction not found/i)
127
+ expect(response.error_code).to eq("300")
128
+ end
129
+
130
+ end
131
+
132
+ end
133
+
134
+ end
135
+
@@ -0,0 +1,54 @@
1
+ # Configure Rails Environment
2
+ ENV['RAILS_ENV'] = 'test'
3
+
4
+ begin
5
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
6
+ rescue LoadError
7
+ puts "Could not load dummy application. Please ensure you have run `bundle exec rake test_app`"
8
+ end
9
+
10
+ require 'rspec/rails'
11
+ require 'ffaker'
12
+ require 'rspec/active_model/mocks'
13
+ require 'vcr'
14
+ require 'webmock'
15
+
16
+ # Requires supporting ruby files with custom matchers and macros, etc,
17
+ # in spec/support/ and its subdirectories.
18
+ Dir[File.join(File.dirname(__FILE__), "support/**/*.rb")].each {|f| require f }
19
+
20
+ require 'spree/testing_support/factories'
21
+ require 'spree/testing_support/controller_requests'
22
+ require 'spree/testing_support/url_helpers'
23
+
24
+ module Spree
25
+ module AlphaCard
26
+ module TestHelper
27
+ def test_credentials
28
+ @test_credentials ||= YAML::load_file(File.new("#{Engine.config.root}/config/credentials.yml"))
29
+ end
30
+ end
31
+ end
32
+ end
33
+
34
+ RSpec.configure do |config|
35
+ config.color = true
36
+ config.infer_spec_type_from_file_location!
37
+ config.mock_with :rspec
38
+ config.use_transactional_fixtures = true
39
+
40
+ config.include Spree::TestingSupport::ControllerRequests, type: :controller
41
+ config.include FactoryGirl::Syntax::Methods
42
+ config.include Spree::TestingSupport::UrlHelpers
43
+
44
+ config.filter_run_excluding :external => true
45
+
46
+ config.include Spree::AlphaCard::TestHelper
47
+ end
48
+
49
+ VCR.configure do |c|
50
+ # c.allow_http_connections_when_no_cassette = true
51
+ c.cassette_library_dir = 'spec/cassettes'
52
+ c.hook_into :webmock
53
+ end
54
+
@@ -28,6 +28,8 @@ Gem::Specification.new do |spec|
28
28
  spec.add_development_dependency 'sass-rails', '~> 4.0.2'
29
29
  spec.add_development_dependency 'sqlite3'
30
30
  spec.add_development_dependency 'byebug'
31
+ spec.add_development_dependency 'vcr'
32
+ spec.add_development_dependency 'webmock'
31
33
 
32
34
  spec.add_runtime_dependency 'alpha_card', '~> 0.2.5'
33
35
  spec.add_runtime_dependency 'spree_core', '>= 3.0.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spree-alpha-card
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lars Kluge
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-09 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,6 +136,34 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: vcr
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ - !ruby/object:Gem::Dependency
154
+ name: webmock
155
+ requirement: !ruby/object:Gem::Requirement
156
+ requirements:
157
+ - - ">="
158
+ - !ruby/object:Gem::Version
159
+ version: '0'
160
+ type: :development
161
+ prerelease: false
162
+ version_requirements: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
139
167
  - !ruby/object:Gem::Dependency
140
168
  name: alpha_card
141
169
  requirement: !ruby/object:Gem::Requirement
@@ -171,13 +199,21 @@ executables: []
171
199
  extensions: []
172
200
  extra_rdoc_files: []
173
201
  files:
202
+ - ".gitignore"
174
203
  - Gemfile
175
204
  - Gemfile.lock
205
+ - Rakefile
176
206
  - app/models/spree/gateway/alpha_card_gateway.rb
177
207
  - lib/spree-alpha-card.rb
178
208
  - lib/spree/alpha_card.rb
179
209
  - lib/spree/alpha_card/engine.rb
180
210
  - lib/spree/alpha_card/version.rb
211
+ - spec/cassettes/credit_without_valid_transaction_id.yml
212
+ - spec/cassettes/purchase_invalid_cc_number.yml
213
+ - spec/cassettes/purchase_low_amount.yml
214
+ - spec/cassettes/simple_purchase.yml
215
+ - spec/models/spree/gateway/alpha_card_gateway_spec.rb
216
+ - spec/spec_helper.rb
181
217
  - spree-alpha-card.gemspec
182
218
  homepage: ''
183
219
  licenses:
@@ -203,4 +239,10 @@ rubygems_version: 2.4.5
203
239
  signing_key:
204
240
  specification_version: 4
205
241
  summary: Alpha Card Payment Gateway for Spree
206
- test_files: []
242
+ test_files:
243
+ - spec/cassettes/credit_without_valid_transaction_id.yml
244
+ - spec/cassettes/purchase_invalid_cc_number.yml
245
+ - spec/cassettes/purchase_low_amount.yml
246
+ - spec/cassettes/simple_purchase.yml
247
+ - spec/models/spree/gateway/alpha_card_gateway_spec.rb
248
+ - spec/spec_helper.rb