killbill-stripe 4.1.0 → 4.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,193 +0,0 @@
1
- require 'spec_helper'
2
-
3
- ActiveMerchant::Billing::Base.mode = :test
4
-
5
- describe Killbill::Stripe::PaymentPlugin do
6
-
7
- include ::Killbill::Plugin::ActiveMerchant::RSpec
8
-
9
- before(:each) do
10
- @plugin = build_plugin(::Killbill::Stripe::PaymentPlugin, 'stripe')
11
- @plugin.start_plugin
12
-
13
- ::Killbill::Stripe::StripePaymentMethod.delete_all
14
- ::Killbill::Stripe::StripeResponse.delete_all
15
- ::Killbill::Stripe::StripeTransaction.delete_all
16
-
17
- @call_context = build_call_context
18
-
19
- @properties = []
20
- @pm = create_payment_method(::Killbill::Stripe::StripePaymentMethod, nil, @call_context.tenant_id, @properties)
21
- @amount = BigDecimal.new('100')
22
- @currency = 'USD'
23
-
24
- kb_payment_id = SecureRandom.uuid
25
- 1.upto(6) do
26
- @kb_payment = @plugin.kb_apis.proxied_services[:payment_api].add_payment(kb_payment_id)
27
- end
28
- end
29
-
30
- after(:each) do
31
- @plugin.stop_plugin
32
- end
33
-
34
- it 'should be able to create and retrieve payment methods' do
35
- # Override default payment method params to make sure we store the data returned by Stripe (see https://github.com/killbill/killbill-stripe-plugin/issues/8)
36
- pm = create_payment_method(::Killbill::Stripe::StripePaymentMethod, nil, @call_context.tenant_id, [], { :cc_type => '', :cc_last_4 => '' })
37
-
38
- pms = @plugin.get_payment_methods(pm.kb_account_id, false, [], @call_context)
39
- pms.size.should == 1
40
- pms.first.external_payment_method_id.should == pm.token
41
-
42
- pm_details = @plugin.get_payment_method_detail(pm.kb_account_id, pms.first.payment_method_id, [], @call_context)
43
- pm_props = properties_to_hash(pm_details.properties)
44
- pm_props[:ccFirstName].should == 'John'
45
- pm_props[:ccLastName].should == 'Doe'
46
- pm_props[:ccType].should == 'Visa'
47
- pm_props[:ccExpirationMonth].should == '12'
48
- pm_props[:ccExpirationYear].should == '2017'
49
- pm_props[:ccLast4].should == '4242'
50
- pm_props[:address1].should == '5, oakriu road'
51
- pm_props[:address2].should == 'apt. 298'
52
- pm_props[:city].should == 'Gdio Foia'
53
- pm_props[:state].should == 'FL'
54
- pm_props[:zip].should == '49302'
55
- pm_props[:country].should == 'US'
56
-
57
- pm_details = @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id, [], @call_context)
58
- pm_details.external_payment_method_id.should == pm.token
59
-
60
- pms_found = @plugin.search_payment_methods pm.cc_last_4, 0, 10, [], @call_context
61
- pms_found = pms_found.iterator.to_a
62
- pms_found.size.should == 2
63
- pms_found[1].external_payment_method_id.should == pm_details.external_payment_method_id
64
-
65
- @plugin.delete_payment_method(pm.kb_account_id, pm.kb_payment_method_id, [], @call_context)
66
-
67
- @plugin.get_payment_methods(pm.kb_account_id, false, [], @call_context).size.should == 0
68
- lambda { @plugin.get_payment_method_detail(pm.kb_account_id, pm.kb_payment_method_id, [], @call_context) }.should raise_error RuntimeError
69
-
70
- # Verify we can add multiple payment methods
71
- pm1 = create_payment_method(::Killbill::Stripe::StripePaymentMethod, pm.kb_account_id, @call_context.tenant_id)
72
- pm2 = create_payment_method(::Killbill::Stripe::StripePaymentMethod, pm.kb_account_id, @call_context.tenant_id)
73
-
74
- pms = @plugin.get_payment_methods(pm.kb_account_id, false, [], @call_context)
75
- pms.size.should == 2
76
- pms[0].external_payment_method_id.should == pm1.token
77
- pms[1].external_payment_method_id.should == pm2.token
78
-
79
- # Update the default payment method in Stripe (we cannot easily verify the result unfortunately)
80
- @plugin.set_default_payment_method(pm.kb_account_id, pm2.kb_payment_method_id, [], @call_context)
81
- response = Killbill::Stripe::StripeResponse.last
82
- response.api_call.should == 'set_default_payment_method'
83
- response.message.should == 'Transaction approved'
84
- response.success.should be_true
85
- end
86
-
87
- it 'should be able to charge a Credit Card directly' do
88
- properties = build_pm_properties
89
-
90
- # We created the payment methods, hence the rows
91
- nb_responses = Killbill::Stripe::StripeResponse.count
92
- Killbill::Stripe::StripeTransaction.all.size.should == 0
93
-
94
- payment_response = @plugin.purchase_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
95
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
96
- payment_response.amount.should == @amount
97
- payment_response.transaction_type.should == :PURCHASE
98
-
99
- responses = Killbill::Stripe::StripeResponse.all
100
- responses.size.should == nb_responses + 1
101
- responses[nb_responses].api_call.should == 'purchase'
102
- responses[nb_responses].message.should == 'Transaction approved'
103
- transactions = Killbill::Stripe::StripeTransaction.all
104
- transactions.size.should == 1
105
- transactions[0].api_call.should == 'purchase'
106
- end
107
-
108
- it 'should be able to charge and refund' do
109
- payment_response = @plugin.purchase_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
110
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
111
- payment_response.amount.should == @amount
112
- payment_response.transaction_type.should == :PURCHASE
113
-
114
- # Try a full refund
115
- refund_response = @plugin.refund_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[1].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
116
- refund_response.status.should eq(:PROCESSED), refund_response.gateway_error
117
- refund_response.amount.should == @amount
118
- refund_response.transaction_type.should == :REFUND
119
- end
120
-
121
- it 'prevents double payments' do
122
- payment_response = @plugin.purchase_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
123
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
124
- payment_response.amount.should == @amount
125
- payment_response.transaction_type.should == :PURCHASE
126
-
127
- payment_response = @plugin.purchase_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
128
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
129
- payment_response.amount.should == @amount
130
- payment_response.transaction_type.should == :PURCHASE
131
-
132
- responses = Killbill::Stripe::StripeResponse.all
133
- responses.size.should == 2 + 1
134
- responses[1].params_id.should == responses[2].params_id
135
- end
136
-
137
- # It doesn't look like Stripe supports multiple partial captures
138
- #it 'should be able to auth, capture and refund' do
139
- # payment_response = @plugin.authorize_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
140
- # payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
141
- # payment_response.amount.should == @amount
142
- # payment_response.transaction_type.should == :AUTHORIZE
143
- #
144
- # # Try multiple partial captures
145
- # partial_capture_amount = BigDecimal.new('10')
146
- # 1.upto(3) do |i|
147
- # payment_response = @plugin.capture_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[i].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context)
148
- # payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
149
- # payment_response.amount.should == partial_capture_amount
150
- # payment_response.transaction_type.should == :CAPTURE
151
- # end
152
- #
153
- # # Try a partial refund
154
- # refund_response = @plugin.refund_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[4].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context)
155
- # refund_response.status.should eq(:PROCESSED), refund_response.gateway_error
156
- # refund_response.amount.should == partial_capture_amount
157
- # refund_response.transaction_type.should == :REFUND
158
- #
159
- # # Try to capture again
160
- # payment_response = @plugin.capture_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[5].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context)
161
- # payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
162
- # payment_response.amount.should == partial_capture_amount
163
- # payment_response.transaction_type.should == :CAPTURE
164
- #end
165
-
166
- it 'should be able to auth and void' do
167
- payment_response = @plugin.authorize_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
168
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
169
- payment_response.amount.should == @amount
170
- payment_response.transaction_type.should == :AUTHORIZE
171
-
172
- payment_response = @plugin.void_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[1].id, @pm.kb_payment_method_id, @properties, @call_context)
173
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
174
- payment_response.transaction_type.should == :VOID
175
- end
176
-
177
- it 'should be able to auth, partial capture and void' do
178
- payment_response = @plugin.authorize_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[0].id, @pm.kb_payment_method_id, @amount, @currency, @properties, @call_context)
179
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
180
- payment_response.amount.should == @amount
181
- payment_response.transaction_type.should == :AUTHORIZE
182
-
183
- partial_capture_amount = BigDecimal.new('10')
184
- payment_response = @plugin.capture_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[1].id, @pm.kb_payment_method_id, partial_capture_amount, @currency, @properties, @call_context)
185
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
186
- payment_response.amount.should == partial_capture_amount
187
- payment_response.transaction_type.should == :CAPTURE
188
-
189
- payment_response = @plugin.void_payment(@pm.kb_account_id, @kb_payment.id, @kb_payment.transactions[2].id, @pm.kb_payment_method_id, @properties, @call_context)
190
- payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
191
- payment_response.transaction_type.should == :VOID
192
- end
193
- end
data/stripe.yml DELETED
@@ -1,32 +0,0 @@
1
- :stripe:
2
- :api_secret_key: <%= ENV['API_SECRET_KEY'] %>
3
- :api_publishable_key: <%= ENV['API_PUBLISHABLE_KEY'] %>
4
- :test: true
5
-
6
- :database:
7
- # SQLite (development)
8
- :adapter: sqlite3
9
- :database: test.db
10
- # For PostgreSQL
11
- # :adapter: postgresql
12
- # :database: 'killbill'
13
- # For MySQL
14
- # :adapter: mysql
15
- # :username: 'killbill'
16
- # :password: 'killbill'
17
- # :database: 'killbill' # or set the URL :
18
- # #:url: jdbc:mysql://127.0.0.1:3306/killbill
19
- # :driver: org.mariadb.jdbc.Driver # as in KB
20
- # :pool: 30 # AR's default is max 5 connections
21
- # In Kill Bill
22
- # :adapter: mysql
23
- # :jndi: 'killbill/osgi/jdbc'
24
- # :pool: false # false-pool (JNDI pool's max)
25
- # # uncomment if pool does not support JDBC4 :
26
- # #:connection_alive_sql: 'select 1'
27
- # # MySQL adapter #configure_connection defaults :
28
- # # @@SESSION.sql_auto_is_null = 0,
29
- # # @@SESSION.wait_timeout = 2147483,
30
- # # @@SESSION.sql_mode = 'STRICT_ALL_TABLES'
31
- # # ... can be disabled (on AR-JDBC 1.4) using :
32
- # :configure_connection: false