killbill-paypal-express 4.0.0 → 4.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 +4 -4
- data/Gemfile.lock +28 -19
- data/Jarfile.lock +48 -48
- data/NEWS +3 -0
- data/README.md +123 -0
- data/VERSION +1 -1
- data/db/ddl.sql +1 -1
- data/db/schema.rb +2 -2
- data/killbill-paypal-express.gemspec +3 -3
- data/lib/paypal_express.rb +3 -0
- data/lib/paypal_express/api.rb +177 -49
- data/lib/paypal_express/application.rb +1 -0
- data/lib/paypal_express/ext/active_merchant/active_merchant.rb +18 -0
- data/lib/paypal_express/models/response.rb +8 -0
- data/lib/paypal_express/private_api.rb +9 -9
- data/pom.xml +1 -1
- data/release.sh +0 -0
- data/spec/paypal_express/base_plugin_spec.rb +0 -17
- data/spec/paypal_express/remote/baid_spec.rb +287 -0
- data/spec/paypal_express/remote/hpp_spec.rb +256 -0
- data/spec/spec_helper.rb +20 -0
- metadata +27 -5
- data/spec/paypal_express/remote/integration_spec.rb +0 -135
@@ -0,0 +1,256 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
ActiveMerchant::Billing::Base.mode = :test
|
4
|
+
|
5
|
+
describe Killbill::PaypalExpress::PaymentPlugin do
|
6
|
+
|
7
|
+
include ::Killbill::Plugin::ActiveMerchant::RSpec
|
8
|
+
|
9
|
+
before(:all) do
|
10
|
+
@plugin = build_plugin(::Killbill::PaypalExpress::PaymentPlugin, 'paypal_express')
|
11
|
+
svcs = @plugin.kb_apis.proxied_services
|
12
|
+
svcs[:payment_api] = PaypalExpressJavaPaymentApi.new(@plugin)
|
13
|
+
@plugin.kb_apis = ::Killbill::Plugin::KillbillApi.new('paypal_express', svcs)
|
14
|
+
@plugin.start_plugin
|
15
|
+
|
16
|
+
@call_context = build_call_context
|
17
|
+
|
18
|
+
@amount = BigDecimal.new('100')
|
19
|
+
@currency = 'USD'
|
20
|
+
@form_fields = @plugin.hash_to_properties(
|
21
|
+
:order_id => '1234',
|
22
|
+
:amount => @amount,
|
23
|
+
:currency => @currency
|
24
|
+
)
|
25
|
+
|
26
|
+
kb_account_id = SecureRandom.uuid
|
27
|
+
create_kb_account(kb_account_id, @plugin.kb_apis.proxied_services[:account_user_api])
|
28
|
+
|
29
|
+
@pm = create_payment_method(::Killbill::PaypalExpress::PaypalExpressPaymentMethod, kb_account_id, @call_context.tenant_id)
|
30
|
+
verify_payment_method
|
31
|
+
end
|
32
|
+
|
33
|
+
before(:each) do
|
34
|
+
::Killbill::PaypalExpress::PaypalExpressTransaction.delete_all
|
35
|
+
::Killbill::PaypalExpress::PaypalExpressResponse.delete_all
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should generate forms correctly' do
|
39
|
+
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 0
|
40
|
+
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 0
|
41
|
+
|
42
|
+
# Verify the payment cannot go through without the token
|
43
|
+
purchase_with_missing_token
|
44
|
+
|
45
|
+
# Verify multiple payments can be triggered for the same payment method
|
46
|
+
n = 2
|
47
|
+
1.upto(n) do
|
48
|
+
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, [], @call_context)
|
49
|
+
validate_form(form)
|
50
|
+
validate_nil_form_property(form, 'kb_payment_id')
|
51
|
+
validate_nil_form_property(form, 'kb_transaction_external_key')
|
52
|
+
token = validate_form_property(form, 'token')
|
53
|
+
|
54
|
+
# Verify no payment was created in Kill Bill
|
55
|
+
@plugin.kb_apis.proxied_services[:payment_api].payments.should be_empty
|
56
|
+
|
57
|
+
properties = []
|
58
|
+
properties << build_property('token', token)
|
59
|
+
|
60
|
+
# Verify the payment cannot go through until the token is validated
|
61
|
+
purchase_with_invalid_token(properties)
|
62
|
+
|
63
|
+
validate_token(form)
|
64
|
+
|
65
|
+
purchase_and_refund(SecureRandom.uuid, SecureRandom.uuid, properties)
|
66
|
+
|
67
|
+
# Verify no extra payment was created in Kill Bill by the plugin
|
68
|
+
@plugin.kb_apis.proxied_services[:payment_api].payments.should be_empty
|
69
|
+
|
70
|
+
# Verify the token cannot be re-used
|
71
|
+
subsequent_purchase(properties)
|
72
|
+
|
73
|
+
# Verify no token/baid was stored
|
74
|
+
verify_payment_method
|
75
|
+
end
|
76
|
+
|
77
|
+
# Each loop triggers one successful purchase and one successful refund
|
78
|
+
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 2 * n
|
79
|
+
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 1 + 8 * n
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should generate forms with pending payments correctly' do
|
83
|
+
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 0
|
84
|
+
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 0
|
85
|
+
|
86
|
+
# Verify the payment cannot go through without the token
|
87
|
+
purchase_with_missing_token
|
88
|
+
|
89
|
+
# Verify multiple payments can be triggered for the same payment method
|
90
|
+
n = 2
|
91
|
+
1.upto(n) do |i|
|
92
|
+
payment_external_key = SecureRandom.uuid
|
93
|
+
properties = @plugin.hash_to_properties(
|
94
|
+
:transaction_external_key => payment_external_key,
|
95
|
+
:create_pending_payment => true
|
96
|
+
)
|
97
|
+
|
98
|
+
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
99
|
+
validate_form(form)
|
100
|
+
kb_payment_id = validate_form_property(form, 'kb_payment_id')
|
101
|
+
validate_form_property(form, 'kb_transaction_external_key', payment_external_key)
|
102
|
+
token = validate_form_property(form, 'token')
|
103
|
+
|
104
|
+
# Verify the payment was created in Kill Bill
|
105
|
+
@plugin.kb_apis.proxied_services[:payment_api].payments.size.should == i
|
106
|
+
@plugin.kb_apis.proxied_services[:payment_api].get_payment(kb_payment_id).transactions.first.external_key.should == payment_external_key
|
107
|
+
|
108
|
+
# Verify GET API
|
109
|
+
payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, [], @call_context)
|
110
|
+
payment_infos.size.should == 1
|
111
|
+
payment_infos[0].kb_payment_id.should == kb_payment_id
|
112
|
+
payment_infos[0].transaction_type.should == :PURCHASE
|
113
|
+
payment_infos[0].amount.should be_nil
|
114
|
+
payment_infos[0].currency.should be_nil
|
115
|
+
payment_infos[0].status.should == :PENDING
|
116
|
+
payment_infos[0].gateway_error.should == '{"payment_plugin_status":"PENDING"}'
|
117
|
+
payment_infos[0].gateway_error_code.should be_nil
|
118
|
+
|
119
|
+
properties = []
|
120
|
+
properties << build_property('token', token)
|
121
|
+
|
122
|
+
# Verify the payment cannot go through until the token is validated
|
123
|
+
purchase_with_invalid_token(properties)
|
124
|
+
|
125
|
+
validate_token(form)
|
126
|
+
|
127
|
+
purchase_and_refund(kb_payment_id, payment_external_key, properties)
|
128
|
+
|
129
|
+
# Verify no extra payment was created in Kill Bill by the plugin
|
130
|
+
@plugin.kb_apis.proxied_services[:payment_api].payments.size.should == i
|
131
|
+
|
132
|
+
# Verify the token cannot be re-used
|
133
|
+
subsequent_purchase(properties)
|
134
|
+
|
135
|
+
# Verify no token/baid was stored
|
136
|
+
verify_payment_method
|
137
|
+
end
|
138
|
+
|
139
|
+
# Each loop triggers one successful purchase and one successful refund
|
140
|
+
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 2 * n
|
141
|
+
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 1 + 9 * n
|
142
|
+
end
|
143
|
+
|
144
|
+
private
|
145
|
+
|
146
|
+
def validate_form(form)
|
147
|
+
form.kb_account_id.should == @pm.kb_account_id
|
148
|
+
form.form_url.should start_with('https://www.sandbox.paypal.com/cgi-bin/webscr')
|
149
|
+
form.form_method.should == 'GET'
|
150
|
+
end
|
151
|
+
|
152
|
+
def validate_nil_form_property(form, key)
|
153
|
+
key_properties = form.properties.select { |prop| prop.key == key }
|
154
|
+
key_properties.size.should == 0
|
155
|
+
end
|
156
|
+
|
157
|
+
def validate_form_property(form, key, value=nil)
|
158
|
+
key_properties = form.properties.select { |prop| prop.key == key }
|
159
|
+
key_properties.size.should == 1
|
160
|
+
key = key_properties.first.value
|
161
|
+
value.nil? ? key.should_not(be_nil) : key.should == value
|
162
|
+
key
|
163
|
+
end
|
164
|
+
|
165
|
+
def validate_token(form)
|
166
|
+
print "\nPlease go to #{form.form_url} to proceed and press any key to continue...
|
167
|
+
Note: you need to log-in with a paypal sandbox account (create one here: https://developer.paypal.com/webapps/developer/applications/accounts)\n"
|
168
|
+
$stdin.gets
|
169
|
+
end
|
170
|
+
|
171
|
+
def purchase_and_refund(kb_payment_id, purchase_payment_external_key, purchase_properties)
|
172
|
+
# Trigger the purchase
|
173
|
+
payment_response = @plugin.purchase_payment(@pm.kb_account_id, kb_payment_id, purchase_payment_external_key, @pm.kb_payment_method_id, @amount, @currency, purchase_properties, @call_context)
|
174
|
+
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
175
|
+
payment_response.amount.should == @amount
|
176
|
+
payment_response.transaction_type.should == :PURCHASE
|
177
|
+
|
178
|
+
# Verify GET API
|
179
|
+
payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, [], @call_context)
|
180
|
+
payment_infos.size.should == 1
|
181
|
+
payment_infos[0].kb_payment_id.should == kb_payment_id
|
182
|
+
payment_infos[0].transaction_type.should == :PURCHASE
|
183
|
+
payment_infos[0].amount.should == @amount
|
184
|
+
payment_infos[0].currency.should == @currency
|
185
|
+
payment_infos[0].status.should == :PROCESSED
|
186
|
+
payment_infos[0].gateway_error.should == 'Success'
|
187
|
+
payment_infos[0].gateway_error_code.should be_nil
|
188
|
+
|
189
|
+
# Try a full refund
|
190
|
+
refund_response = @plugin.refund_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, [], @call_context)
|
191
|
+
refund_response.status.should eq(:PROCESSED), refund_response.gateway_error
|
192
|
+
refund_response.amount.should == @amount
|
193
|
+
refund_response.transaction_type.should == :REFUND
|
194
|
+
|
195
|
+
# Verify GET API
|
196
|
+
payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, [], @call_context)
|
197
|
+
payment_infos.size.should == 2
|
198
|
+
payment_infos[0].kb_payment_id.should == kb_payment_id
|
199
|
+
payment_infos[0].transaction_type.should == :PURCHASE
|
200
|
+
payment_infos[0].amount.should == @amount
|
201
|
+
payment_infos[0].currency.should == @currency
|
202
|
+
payment_infos[0].status.should == :PROCESSED
|
203
|
+
payment_infos[0].gateway_error.should == 'Success'
|
204
|
+
payment_infos[0].gateway_error_code.should be_nil
|
205
|
+
payment_infos[1].kb_payment_id.should.should == kb_payment_id
|
206
|
+
payment_infos[1].transaction_type.should == :REFUND
|
207
|
+
payment_infos[1].amount.should == @amount
|
208
|
+
payment_infos[1].currency.should == @currency
|
209
|
+
payment_infos[1].status.should == :PROCESSED
|
210
|
+
payment_infos[1].gateway_error.should == 'Success'
|
211
|
+
payment_infos[1].gateway_error_code.should be_nil
|
212
|
+
end
|
213
|
+
|
214
|
+
def purchase_with_missing_token
|
215
|
+
failed_purchase([], :CANCELED, 'Could not find the payer_id: the token is missing', 'RuntimeError')
|
216
|
+
end
|
217
|
+
|
218
|
+
def purchase_with_invalid_token(purchase_properties)
|
219
|
+
failed_purchase(purchase_properties, :CANCELED, "Could not find the payer_id for token #{properties_to_hash(purchase_properties)[:token]}", 'RuntimeError')
|
220
|
+
end
|
221
|
+
|
222
|
+
def subsequent_purchase(purchase_properties)
|
223
|
+
failed_purchase(purchase_properties, :ERROR, 'A successful transaction has already been completed for this token.')
|
224
|
+
end
|
225
|
+
|
226
|
+
def failed_purchase(purchase_properties, status, msg, gateway_error_code=nil)
|
227
|
+
kb_payment_id = SecureRandom.uuid
|
228
|
+
|
229
|
+
payment_response = @plugin.purchase_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, purchase_properties, @call_context)
|
230
|
+
payment_response.status.should eq(status), payment_response.gateway_error
|
231
|
+
payment_response.amount.should be_nil
|
232
|
+
payment_response.transaction_type.should == :PURCHASE
|
233
|
+
|
234
|
+
# Verify GET API
|
235
|
+
payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, [], @call_context)
|
236
|
+
payment_infos.size.should == 1
|
237
|
+
payment_infos[0].kb_payment_id.should == kb_payment_id
|
238
|
+
payment_infos[0].transaction_type.should == :PURCHASE
|
239
|
+
payment_infos[0].amount.should be_nil
|
240
|
+
payment_infos[0].currency.should be_nil
|
241
|
+
payment_infos[0].status.should == status
|
242
|
+
payment_infos[0].gateway_error.should == msg
|
243
|
+
payment_infos[0].gateway_error_code.should == gateway_error_code
|
244
|
+
end
|
245
|
+
|
246
|
+
def verify_payment_method
|
247
|
+
# Verify our table directly
|
248
|
+
payment_methods = ::Killbill::PaypalExpress::PaypalExpressPaymentMethod.from_kb_account_id(@pm.kb_account_id, @call_context.tenant_id)
|
249
|
+
payment_methods.size.should == 1
|
250
|
+
payment_method = payment_methods.first
|
251
|
+
payment_method.should_not be_nil
|
252
|
+
payment_method.paypal_express_payer_id.should be_nil
|
253
|
+
payment_method.token.should be_nil
|
254
|
+
payment_method.kb_payment_method_id.should == @pm.kb_payment_method_id
|
255
|
+
end
|
256
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -22,3 +22,23 @@ ActiveRecord::Base.establish_connection(
|
|
22
22
|
# Create the schema
|
23
23
|
require File.expand_path(File.dirname(__FILE__) + '../../db/schema.rb')
|
24
24
|
|
25
|
+
class PaypalExpressJavaPaymentApi < ::Killbill::Plugin::ActiveMerchant::RSpec::FakeJavaPaymentApi
|
26
|
+
|
27
|
+
def initialize(plugin)
|
28
|
+
super()
|
29
|
+
@plugin = plugin
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_account_payment_methods(kb_account_id, plugin_info, properties, context)
|
33
|
+
[OpenStruct.new(:plugin_name => 'killbill-paypal-express', :id => SecureRandom.uuid)]
|
34
|
+
end
|
35
|
+
|
36
|
+
def create_purchase(kb_account, kb_payment_method_id, kb_payment_id, amount, currency, payment_external_key, payment_transaction_external_key, properties, context)
|
37
|
+
kb_payment = add_payment(kb_payment_id || SecureRandom.uuid, SecureRandom.uuid, payment_transaction_external_key, :PURCHASE)
|
38
|
+
|
39
|
+
rcontext = context.to_ruby(context)
|
40
|
+
@plugin.purchase_payment(kb_account.id, kb_payment.id, kb_payment.transactions.last.id, kb_payment_method_id, amount, currency, properties, rcontext)
|
41
|
+
|
42
|
+
kb_payment
|
43
|
+
end
|
44
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: killbill-paypal-express
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kill Bill core team
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-02-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: killbill
|
@@ -87,11 +87,17 @@ dependencies:
|
|
87
87
|
- - ~>
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '1.3'
|
90
|
+
- - <
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '1.5'
|
90
93
|
requirement: !ruby/object:Gem::Requirement
|
91
94
|
requirements:
|
92
95
|
- - ~>
|
93
96
|
- !ruby/object:Gem::Version
|
94
97
|
version: '1.3'
|
98
|
+
- - <
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '1.5'
|
95
101
|
prerelease: false
|
96
102
|
type: :runtime
|
97
103
|
- !ruby/object:Gem::Dependency
|
@@ -100,12 +106,12 @@ dependencies:
|
|
100
106
|
requirements:
|
101
107
|
- - ~>
|
102
108
|
- !ruby/object:Gem::Version
|
103
|
-
version: 0.9.
|
109
|
+
version: 0.9.11
|
104
110
|
requirement: !ruby/object:Gem::Requirement
|
105
111
|
requirements:
|
106
112
|
- - ~>
|
107
113
|
- !ruby/object:Gem::Version
|
108
|
-
version: 0.9.
|
114
|
+
version: 0.9.11
|
109
115
|
prerelease: false
|
110
116
|
type: :runtime
|
111
117
|
- !ruby/object:Gem::Dependency
|
@@ -262,6 +268,20 @@ dependencies:
|
|
262
268
|
version: '1.1'
|
263
269
|
prerelease: false
|
264
270
|
type: :development
|
271
|
+
- !ruby/object:Gem::Dependency
|
272
|
+
name: jdbc-postgres
|
273
|
+
version_requirements: !ruby/object:Gem::Requirement
|
274
|
+
requirements:
|
275
|
+
- - ~>
|
276
|
+
- !ruby/object:Gem::Version
|
277
|
+
version: '9.4'
|
278
|
+
requirement: !ruby/object:Gem::Requirement
|
279
|
+
requirements:
|
280
|
+
- - ~>
|
281
|
+
- !ruby/object:Gem::Version
|
282
|
+
version: '9.4'
|
283
|
+
prerelease: false
|
284
|
+
type: :development
|
265
285
|
description: Kill Bill payment plugin for Paypal Express Checkout.
|
266
286
|
email: killbilling-users@googlegroups.com
|
267
287
|
executables: []
|
@@ -288,6 +308,7 @@ files:
|
|
288
308
|
- lib/paypal_express.rb
|
289
309
|
- lib/paypal_express/api.rb
|
290
310
|
- lib/paypal_express/application.rb
|
311
|
+
- lib/paypal_express/ext/active_merchant/active_merchant.rb
|
291
312
|
- lib/paypal_express/models/payment_method.rb
|
292
313
|
- lib/paypal_express/models/response.rb
|
293
314
|
- lib/paypal_express/models/transaction.rb
|
@@ -297,7 +318,8 @@ files:
|
|
297
318
|
- pom.xml
|
298
319
|
- release.sh
|
299
320
|
- spec/paypal_express/base_plugin_spec.rb
|
300
|
-
- spec/paypal_express/remote/
|
321
|
+
- spec/paypal_express/remote/baid_spec.rb
|
322
|
+
- spec/paypal_express/remote/hpp_spec.rb
|
301
323
|
- spec/spec_helper.rb
|
302
324
|
homepage: http://killbill.io
|
303
325
|
licenses:
|
@@ -1,135 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
ActiveMerchant::Billing::Base.mode = :test
|
4
|
-
|
5
|
-
describe Killbill::PaypalExpress::PaymentPlugin do
|
6
|
-
|
7
|
-
include ::Killbill::Plugin::ActiveMerchant::RSpec
|
8
|
-
|
9
|
-
# Share the BAID
|
10
|
-
before(:all) do
|
11
|
-
@plugin = build_plugin(::Killbill::PaypalExpress::PaymentPlugin, 'paypal_express')
|
12
|
-
@plugin.start_plugin
|
13
|
-
|
14
|
-
@call_context = build_call_context
|
15
|
-
|
16
|
-
@properties = []
|
17
|
-
@amount = BigDecimal.new('100')
|
18
|
-
@currency = 'USD'
|
19
|
-
|
20
|
-
kb_account_id = SecureRandom.uuid
|
21
|
-
external_key, kb_account_id = create_kb_account(kb_account_id, @plugin.kb_apis.proxied_services[:account_user_api])
|
22
|
-
|
23
|
-
# Initiate the setup process
|
24
|
-
response = create_token(kb_account_id, @call_context.tenant_id)
|
25
|
-
token = response.token
|
26
|
-
print "\nPlease go to #{@plugin.to_express_checkout_url(response, @call_context.tenant_id)} to proceed and press any key to continue...
|
27
|
-
Note: you need to log-in with a paypal sandbox account (create one here: https://developer.paypal.com/webapps/developer/applications/accounts)\n"
|
28
|
-
$stdin.gets
|
29
|
-
|
30
|
-
# Complete the setup process
|
31
|
-
@properties << build_property('token', token)
|
32
|
-
@pm = create_payment_method(::Killbill::PaypalExpress::PaypalExpressPaymentMethod, kb_account_id, @call_context.tenant_id, @properties)
|
33
|
-
|
34
|
-
# Verify our table directly. Note that @pm.token is the baid
|
35
|
-
payment_methods = ::Killbill::PaypalExpress::PaypalExpressPaymentMethod.from_kb_account_id_and_token(@pm.token, kb_account_id, @call_context.tenant_id)
|
36
|
-
payment_methods.size.should == 1
|
37
|
-
payment_method = payment_methods.first
|
38
|
-
payment_method.should_not be_nil
|
39
|
-
payment_method.paypal_express_payer_id.should_not be_nil
|
40
|
-
payment_method.token.should == @pm.token
|
41
|
-
payment_method.kb_payment_method_id.should == @pm.kb_payment_method_id
|
42
|
-
end
|
43
|
-
|
44
|
-
before(:each) do
|
45
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.delete_all
|
46
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.delete_all
|
47
|
-
|
48
|
-
kb_payment_id = SecureRandom.uuid
|
49
|
-
1.upto(6) do
|
50
|
-
@kb_payment = @plugin.kb_apis.proxied_services[:payment_api].add_payment(kb_payment_id)
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
after(:each) do
|
55
|
-
@plugin.stop_plugin
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'should be able to charge and refund' do
|
59
|
-
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)
|
60
|
-
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
61
|
-
payment_response.amount.should == @amount
|
62
|
-
payment_response.transaction_type.should == :PURCHASE
|
63
|
-
|
64
|
-
# Try a full refund
|
65
|
-
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)
|
66
|
-
refund_response.status.should eq(:PROCESSED), refund_response.gateway_error
|
67
|
-
refund_response.amount.should == @amount
|
68
|
-
refund_response.transaction_type.should == :REFUND
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'should be able to auth, capture and refund' do
|
72
|
-
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)
|
73
|
-
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
74
|
-
payment_response.amount.should == @amount
|
75
|
-
payment_response.transaction_type.should == :AUTHORIZE
|
76
|
-
|
77
|
-
# Try multiple partial captures
|
78
|
-
partial_capture_amount = BigDecimal.new('10')
|
79
|
-
1.upto(3) do |i|
|
80
|
-
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)
|
81
|
-
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
82
|
-
payment_response.amount.should == partial_capture_amount
|
83
|
-
payment_response.transaction_type.should == :CAPTURE
|
84
|
-
end
|
85
|
-
|
86
|
-
# Try a partial refund
|
87
|
-
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)
|
88
|
-
refund_response.status.should eq(:PROCESSED), refund_response.gateway_error
|
89
|
-
refund_response.amount.should == partial_capture_amount
|
90
|
-
refund_response.transaction_type.should == :REFUND
|
91
|
-
|
92
|
-
# Try to capture again
|
93
|
-
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)
|
94
|
-
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
95
|
-
payment_response.amount.should == partial_capture_amount
|
96
|
-
payment_response.transaction_type.should == :CAPTURE
|
97
|
-
end
|
98
|
-
|
99
|
-
it 'should be able to auth and void' do
|
100
|
-
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)
|
101
|
-
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
102
|
-
payment_response.amount.should == @amount
|
103
|
-
payment_response.transaction_type.should == :AUTHORIZE
|
104
|
-
|
105
|
-
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)
|
106
|
-
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
107
|
-
payment_response.transaction_type.should == :VOID
|
108
|
-
end
|
109
|
-
|
110
|
-
it 'should be able to auth, partial capture and void' do
|
111
|
-
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)
|
112
|
-
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
113
|
-
payment_response.amount.should == @amount
|
114
|
-
payment_response.transaction_type.should == :AUTHORIZE
|
115
|
-
|
116
|
-
partial_capture_amount = BigDecimal.new('10')
|
117
|
-
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)
|
118
|
-
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
119
|
-
payment_response.amount.should == partial_capture_amount
|
120
|
-
payment_response.transaction_type.should == :CAPTURE
|
121
|
-
|
122
|
-
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)
|
123
|
-
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
124
|
-
payment_response.transaction_type.should == :VOID
|
125
|
-
end
|
126
|
-
|
127
|
-
private
|
128
|
-
|
129
|
-
def create_token(kb_account_id, kb_tenant_id)
|
130
|
-
private_plugin = ::Killbill::PaypalExpress::PrivatePaymentPlugin.new
|
131
|
-
response = private_plugin.initiate_express_checkout(kb_account_id, kb_tenant_id)
|
132
|
-
response.success.should be_true
|
133
|
-
response
|
134
|
-
end
|
135
|
-
end
|