cardgate 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,57 @@
1
+ require 'test_helper'
2
+
3
+ module CardgateTestCases
4
+
5
+ class IdealRefundTestCases < Test::Unit::TestCase
6
+
7
+ def stub_cardgate_connection(status, response)
8
+ cardgate_connection do |stubs|
9
+ stubs.post('/rest/v1/ideal/refund/') { [status, {}, response] }
10
+ end
11
+ end
12
+
13
+ def new_refund_attributes_hash
14
+ {
15
+ site_id: 1,
16
+ referenced_transaction_id: 2307831,
17
+ amount: 100
18
+ }
19
+ end
20
+
21
+ def test_successful_refund
22
+ cardgate_connection = stub_cardgate_connection(201, CardgateFixtures::REFUND_SUCCESSFUL)
23
+ Cardgate::Gateway.stubs(:connection).returns(cardgate_connection)
24
+
25
+ refund = Cardgate::Ideal::Refund.new(new_refund_attributes_hash)
26
+ refund.initiate
27
+
28
+ assert_equal 2307831, refund.transaction_id
29
+ end
30
+
31
+ def test_unsuccessful_refund
32
+ cardgate_connection = stub_cardgate_connection(500, CardgateFixtures::REFUND_UNSUCCESSFUL)
33
+ Cardgate::Gateway.stubs(:connection).returns(cardgate_connection)
34
+
35
+ refund = Cardgate::Ideal::Refund.new(new_refund_attributes_hash)
36
+
37
+ assert_raises Cardgate::Exception do
38
+ refund.initiate
39
+ end
40
+ end
41
+
42
+ def test_params
43
+ refund_attributes = new_refund_attributes_hash
44
+ refund_attributes[:reason] = 'Double payed!'
45
+
46
+ refund = Cardgate::Ideal::Refund.new(refund_attributes)
47
+ params = refund.params
48
+
49
+ assert_equal 1, params[:refund][:site_id]
50
+ assert_equal 2307831, params[:refund][:referenced_transaction_id]
51
+ assert_equal 100, params[:refund][:amount]
52
+ assert_equal 'Double payed!', params[:refund][:reason]
53
+ end
54
+
55
+ end
56
+
57
+ end
@@ -0,0 +1,50 @@
1
+ require 'test_helper'
2
+
3
+ module CardgateTestCases
4
+
5
+ class PaymentTestCases < Test::Unit::TestCase
6
+
7
+ def stub_cardgate_connection(status, response)
8
+ cardgate_connection do |stubs|
9
+ stubs.post('/rest/v1/mistercash/payment/') { [status, {}, response] }
10
+ end
11
+ end
12
+
13
+ def test_create_payment
14
+
15
+ cardgate_connection = stub_cardgate_connection(201, CardgateFixtures::PAYMENT_SUCCESSFUL)
16
+ Cardgate::Gateway.stubs(:connection).returns(cardgate_connection)
17
+
18
+ payment = Cardgate::Payment.new({
19
+ site_id: 5112,
20
+ description: 'Nieuwe betaling',
21
+ ip_address: '83.84.166.218',
22
+ amount: 10000,
23
+ ref: 'testorder9',
24
+ currency: 'EUR',
25
+ return_url: 'http://nu.nl',
26
+ first_name: 'Michiel',
27
+ last_name: 'Sikkes',
28
+ email: 'michiel@firmhouse.com'
29
+ })
30
+
31
+ payment.provider = 'mistercash'
32
+ payment.initiate
33
+
34
+ end
35
+
36
+ def test_raise_if_provider_not_set
37
+ Cardgate::Gateway.merchant = 'a'
38
+ Cardgate::Gateway.api_key = 'b'
39
+
40
+ payment = Cardgate::Payment.new()
41
+ payment.provider = nil
42
+
43
+ assert_raises Cardgate::Exception do
44
+ payment.initiate
45
+ end
46
+ end
47
+
48
+ end
49
+
50
+ end
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ module CardgateTestCases
4
+
5
+ class ResponseTestCases < Test::Unit::TestCase
6
+
7
+ def test_response_body_nil
8
+ result = Faraday.new
9
+ result.stubs(:body).returns(nil)
10
+
11
+ assert_raises Cardgate::Exception do
12
+ Cardgate::Response.new(result)
13
+ end
14
+ end
15
+
16
+ def test_not_http_status_200
17
+ result = Faraday.new
18
+ result.stubs(:body).returns('error' => { code: 'test', message: 'test' })
19
+ result.stubs(:status).returns(404)
20
+
21
+ assert_raises Cardgate::Exception do
22
+ Cardgate::Response.new(result)
23
+ end
24
+ end
25
+
26
+ def test_response_with_body
27
+ result = Faraday.new
28
+ result.stubs(:body).returns('test')
29
+ result.stubs(:status).returns(200)
30
+
31
+ assert_nothing_raised do
32
+ Cardgate::Response.new(result)
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+ require 'mocha/test_unit'
3
+ require 'fixtures'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+
7
+ require 'cardgate'
8
+
9
+ def cardgate_connection
10
+ @connection ||= Faraday.new do |faraday|
11
+ faraday.response :json
12
+
13
+ faraday.adapter :test do |stubs|
14
+ yield(stubs)
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,29 @@
1
+ require 'test_helper'
2
+
3
+ module CardgateTestCases
4
+
5
+ class TransactionTestCases < Test::Unit::TestCase
6
+
7
+ def test_successful
8
+ transaction = Cardgate::Transaction.new({status: 200})
9
+
10
+ assert transaction.successful?
11
+
12
+ transaction = Cardgate::Transaction.new({status: 210})
13
+
14
+ assert transaction.successful?
15
+ end
16
+
17
+ def test_unsuccessful
18
+ transaction = Cardgate::Transaction.new({status: 100})
19
+
20
+ refute transaction.successful?
21
+
22
+ transaction = Cardgate::Transaction.new({status: 300})
23
+
24
+ refute transaction.successful?
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,66 @@
1
+ require 'test_helper'
2
+
3
+ module CardgateTestCases
4
+
5
+ class TransactionsTestCases < Test::Unit::TestCase
6
+
7
+ def stub_cardgate_connection
8
+ cardgate_connection do |stubs|
9
+ stubs.get('/rest/v1/transactions/2307824/') { [200, {}, CardgateFixtures::TRANSACTION_WITHOUT_CUSTOMER] }
10
+ stubs.get('/rest/v1/transactions/2307825/') { [200, {}, CardgateFixtures::TRANSACTION_WITH_CUSTOMER] }
11
+ stubs.get('/rest/v1/transactions/2307826/') { [200, {}, nil] }
12
+ end
13
+ end
14
+
15
+ def test_transaction_without_customer
16
+ cardgate_connection = stub_cardgate_connection()
17
+
18
+ Cardgate::Gateway.stubs(:connection).returns(cardgate_connection)
19
+
20
+ transaction = Cardgate::Transactions.find(2307824)
21
+
22
+ assert transaction.is_a? Cardgate::Transaction
23
+
24
+ assert_equal 200, transaction.status
25
+ assert_nil transaction.first_name
26
+ assert_equal 'ideal', transaction.payment_method
27
+ assert_equal '2014-04-22T15:19:01', transaction.timestamp
28
+ assert_equal 5112, transaction.site_id
29
+ assert_equal 'EUR', transaction.currency
30
+ assert_equal 100, transaction.amount
31
+ assert_equal 'test4', transaction.ref
32
+ assert_equal 2307824, transaction.transaction_id
33
+ end
34
+
35
+ def test_transaction_with_customer
36
+ cardgate_connection = stub_cardgate_connection()
37
+
38
+ Cardgate::Gateway.stubs(:connection).returns(cardgate_connection)
39
+
40
+ transaction = Cardgate::Transactions.find(2307825)
41
+
42
+ assert_equal 'Youri', transaction.first_name
43
+ assert_equal 'van der Lans', transaction.last_name
44
+ assert_equal 'ITflows', transaction.company_name
45
+ assert_equal 'Coenecoop 750', transaction.address
46
+ assert_equal 'Waddinxveen', transaction.city
47
+ assert_equal 'Zuid-Holland', transaction.state
48
+ assert_equal '2741 PW', transaction.postal_code
49
+ assert_equal 'NL', transaction.country_code
50
+ assert_equal '1234567890', transaction.phone_number
51
+ assert_equal 'youri@itflows.nl', transaction.email
52
+ end
53
+
54
+ def test_empty_transaction
55
+ cardgate_connection = stub_cardgate_connection()
56
+
57
+ Cardgate::Gateway.stubs(:connection).returns(cardgate_connection)
58
+
59
+ assert_raises Cardgate::Exception do
60
+ transaction = Cardgate::Transactions.find(2307826)
61
+ end
62
+ end
63
+
64
+ end
65
+
66
+ end
metadata ADDED
@@ -0,0 +1,165 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cardgate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Youri van der Lans
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-02-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: mocha
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: faraday
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '0.8'
69
+ - !ruby/object:Gem::Dependency
70
+ name: faraday_middleware
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ description: Provides an easy way to communicate with the cardgate REST API
84
+ email:
85
+ - youri@itflows.nl
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - cardgate.gemspec
96
+ - lib/cardgate.rb
97
+ - lib/cardgate/callback.rb
98
+ - lib/cardgate/constants.rb
99
+ - lib/cardgate/creditcard/creditcard.rb
100
+ - lib/cardgate/creditcard/refund.rb
101
+ - lib/cardgate/exception.rb
102
+ - lib/cardgate/gateway.rb
103
+ - lib/cardgate/ideal/ideal.rb
104
+ - lib/cardgate/ideal/issuer.rb
105
+ - lib/cardgate/ideal/issuers.rb
106
+ - lib/cardgate/ideal/payment.rb
107
+ - lib/cardgate/ideal/refund.rb
108
+ - lib/cardgate/payment.rb
109
+ - lib/cardgate/refund.rb
110
+ - lib/cardgate/response.rb
111
+ - lib/cardgate/transaction.rb
112
+ - lib/cardgate/transactions.rb
113
+ - lib/cardgate/version.rb
114
+ - lib/deep_merge.rb
115
+ - test/callback_test.rb
116
+ - test/creditcard/refund_test.rb
117
+ - test/fixtures.rb
118
+ - test/gateway_test.rb
119
+ - test/ideal/issuer_test.rb
120
+ - test/ideal/issuers_test.rb
121
+ - test/ideal/payment_test.rb
122
+ - test/ideal/refund_test.rb
123
+ - test/payment_test.rb
124
+ - test/response_test.rb
125
+ - test/test_helper.rb
126
+ - test/transaction_test.rb
127
+ - test/transactions_test.rb
128
+ homepage: https://github.com/yourivdlans/cardgate
129
+ licenses:
130
+ - MIT
131
+ metadata: {}
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - '>='
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ required_rubygems_version: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '>='
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ requirements: []
147
+ rubyforge_project:
148
+ rubygems_version: 2.4.5
149
+ signing_key:
150
+ specification_version: 4
151
+ summary: Cardgate REST API client
152
+ test_files:
153
+ - test/callback_test.rb
154
+ - test/creditcard/refund_test.rb
155
+ - test/fixtures.rb
156
+ - test/gateway_test.rb
157
+ - test/ideal/issuer_test.rb
158
+ - test/ideal/issuers_test.rb
159
+ - test/ideal/payment_test.rb
160
+ - test/ideal/refund_test.rb
161
+ - test/payment_test.rb
162
+ - test/response_test.rb
163
+ - test/test_helper.rb
164
+ - test/transaction_test.rb
165
+ - test/transactions_test.rb