killbill-paypal-express 5.0.4 → 5.0.5
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
- metadata +2 -36
- data/.gitignore +0 -35
- data/.travis.yml +0 -41
- data/Gemfile +0 -3
- data/Gemfile.head +0 -5
- data/Gemfile.lock +0 -160
- data/Jarfile +0 -12
- data/Jarfile.lock +0 -66
- data/LICENSE +0 -201
- data/NEWS +0 -120
- data/README.md +0 -265
- data/Rakefile +0 -30
- data/VERSION +0 -1
- data/config.ru +0 -4
- data/db/ddl.sql +0 -120
- data/db/migrate/20160326090325_add_indexes.rb +0 -7
- data/db/migrate/20160828090851_enlarge_message.rb +0 -11
- data/db/migrate/20161209090000_add_indexes.rb +0 -7
- data/db/schema.rb +0 -122
- data/killbill-paypal-express.gemspec +0 -53
- data/killbill.properties +0 -3
- data/paypal_express.yml +0 -30
- data/pom.xml +0 -45
- data/release.sh +0 -61
- data/spec/fixtures/DoExpressCheckoutPayment-duplicate.xml +0 -54
- data/spec/fixtures/GetExpressCheckoutDetails-success.xml +0 -102
- data/spec/paypal_express/base_plugin_spec.rb +0 -133
- data/spec/paypal_express/remote/baid_spec.rb +0 -305
- data/spec/paypal_express/remote/baid_spec_helpers.rb +0 -56
- data/spec/paypal_express/remote/browser_helpers.rb +0 -72
- data/spec/paypal_express/remote/build_plugin_helpers.rb +0 -33
- data/spec/paypal_express/remote/hpp_spec.rb +0 -502
- data/spec/paypal_express/remote/hpp_spec_helpers.rb +0 -365
- data/spec/paypal_express/response_spec.rb +0 -79
- data/spec/spec_helper.rb +0 -67
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'selenium-webdriver'
|
2
|
-
|
3
|
-
module Killbill
|
4
|
-
module PaypalExpress
|
5
|
-
module BrowserHelpers
|
6
|
-
def login_and_confirm(url)
|
7
|
-
if ENV['BUYER_USERNAME'].blank? || ENV['BUYER_PASSWORD'].blank?
|
8
|
-
print "\nPlease go to #{url} to proceed and press any key to continue... Note: you need to log-in with a paypal sandbox account (create one here: https://developer.paypal.com/webapps/developer/applications/accounts)\n"
|
9
|
-
$stdin.gets
|
10
|
-
else
|
11
|
-
driver = Selenium::WebDriver.for :firefox
|
12
|
-
# Login page
|
13
|
-
driver.get url
|
14
|
-
|
15
|
-
wait = Selenium::WebDriver::Wait.new(:timeout => 15)
|
16
|
-
wait.until {
|
17
|
-
driver.switch_to.frame('injectedUl') rescue nil
|
18
|
-
}
|
19
|
-
|
20
|
-
email_element, pwd_element, login_element = wait.until {
|
21
|
-
email_element = driver.find_element(:id, 'email') rescue nil
|
22
|
-
pwd_element = driver.find_element(:id, 'password') rescue nil
|
23
|
-
login_element = driver.find_element(:id, 'btnLogin') rescue nil
|
24
|
-
if ready?(email_element, pwd_element, login_element)
|
25
|
-
[email_element, pwd_element, login_element]
|
26
|
-
else
|
27
|
-
# Find the element ids from the old UI
|
28
|
-
old_email_element = driver.find_element(:id, 'login_email') rescue nil
|
29
|
-
old_pwd_element = driver.find_element(:id, 'login_password') rescue nil
|
30
|
-
old_login_element = driver.find_element(:id, 'submitLogin') rescue nil
|
31
|
-
if ready?(old_email_element, old_pwd_element, old_login_element)
|
32
|
-
[old_email_element, old_pwd_element, old_login_element]
|
33
|
-
else
|
34
|
-
false
|
35
|
-
end
|
36
|
-
end
|
37
|
-
}
|
38
|
-
email_element.send_keys(ENV['BUYER_USERNAME'])
|
39
|
-
pwd_element.send_keys(ENV['BUYER_PASSWORD'])
|
40
|
-
login_element.click
|
41
|
-
|
42
|
-
# Confirmation page
|
43
|
-
driver.switch_to.default_content
|
44
|
-
confirm_element = wait.until {
|
45
|
-
confirm_element = driver.find_element(:id, 'confirmButtonTop') rescue nil
|
46
|
-
if ready?(confirm_element)
|
47
|
-
confirm_element
|
48
|
-
else
|
49
|
-
old_confirm_element = driver.find_element(:id, 'continue_abovefold') rescue nil
|
50
|
-
ready?(old_confirm_element) ? old_confirm_element : false
|
51
|
-
end
|
52
|
-
}
|
53
|
-
|
54
|
-
# Wait for page to load. Even if it is displayed and enabled, sometimes the element is still not clickable.
|
55
|
-
sleep 2
|
56
|
-
confirm_element.click
|
57
|
-
|
58
|
-
driver.quit
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
private
|
63
|
-
|
64
|
-
def ready?(*elements)
|
65
|
-
elements.each do |element|
|
66
|
-
return false unless element && element.displayed? && element.enabled?
|
67
|
-
end
|
68
|
-
true
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
end
|
@@ -1,33 +0,0 @@
|
|
1
|
-
module Killbill
|
2
|
-
module PaypalExpress
|
3
|
-
module BuildPluginHelpers
|
4
|
-
def build_start_paypal_plugin(account_id = nil)
|
5
|
-
if account_id.nil?
|
6
|
-
plugin = build_plugin(::Killbill::PaypalExpress::PaymentPlugin, 'paypal_express')
|
7
|
-
start_plugin plugin
|
8
|
-
else
|
9
|
-
config = YAML.load_file('paypal_express.yml')
|
10
|
-
existing_credential = {:account_id => account_id}.merge config[:paypal_express]
|
11
|
-
second_credential = {:account_id => "#{account_id}_duplicate"}.merge config[:paypal_express]
|
12
|
-
config[:paypal_express] = [second_credential, existing_credential]
|
13
|
-
Dir.mktmpdir do |dir|
|
14
|
-
file_name = File.join(dir, 'paypal_express.yml')
|
15
|
-
File.open(file_name, 'w+') do |file|
|
16
|
-
YAML.dump(config, file)
|
17
|
-
end
|
18
|
-
plugin = build_plugin(::Killbill::PaypalExpress::PaymentPlugin, 'paypal_express', File.dirname(file_name))
|
19
|
-
start_plugin plugin
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def start_plugin(plugin)
|
25
|
-
svcs = plugin.kb_apis.proxied_services
|
26
|
-
svcs[:payment_api] = PaypalExpressJavaPaymentApi.new(plugin)
|
27
|
-
plugin.kb_apis = ::Killbill::Plugin::KillbillApi.new('paypal_express', svcs)
|
28
|
-
plugin.start_plugin
|
29
|
-
plugin
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
@@ -1,502 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require_relative 'hpp_spec_helpers'
|
3
|
-
require_relative 'build_plugin_helpers'
|
4
|
-
|
5
|
-
ActiveMerchant::Billing::Base.mode = :test
|
6
|
-
|
7
|
-
shared_examples 'hpp_spec_common' do
|
8
|
-
|
9
|
-
before(:each) do
|
10
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.delete_all
|
11
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.delete_all
|
12
|
-
# clean the payments before each spec to avoid one influences each other
|
13
|
-
@plugin.kb_apis.proxied_services[:payment_api].delete_all_payments
|
14
|
-
end
|
15
|
-
|
16
|
-
it 'should return an empty list of plugin info if payment does not exist' do
|
17
|
-
payment_plugin_info = @plugin.get_payment_info(@pm.kb_account_id, SecureRandom.uuid, [], @call_context)
|
18
|
-
payment_plugin_info.size.should == 0
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'should generate forms correctly' do
|
22
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 0
|
23
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 0
|
24
|
-
|
25
|
-
# Verify the payment cannot go through without the token
|
26
|
-
purchase_with_missing_token
|
27
|
-
|
28
|
-
# Verify multiple payments can be triggered for the same payment method
|
29
|
-
n = 2
|
30
|
-
1.upto(n) do
|
31
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, [], @call_context)
|
32
|
-
validate_form(form)
|
33
|
-
validate_nil_form_property(form, 'kb_payment_id')
|
34
|
-
validate_nil_form_property(form, 'kb_transaction_external_key')
|
35
|
-
token = validate_form_property(form, 'token')
|
36
|
-
|
37
|
-
# Verify no payment was created in Kill Bill
|
38
|
-
@plugin.kb_apis.proxied_services[:payment_api].payments.should be_empty
|
39
|
-
|
40
|
-
properties = []
|
41
|
-
properties << build_property('token', token)
|
42
|
-
|
43
|
-
# Verify the payment cannot go through until the token is validated
|
44
|
-
purchase_with_invalid_token(properties)
|
45
|
-
|
46
|
-
validate_token(form)
|
47
|
-
|
48
|
-
purchase_and_refund(SecureRandom.uuid, SecureRandom.uuid, properties)
|
49
|
-
|
50
|
-
# Verify no extra payment was created in Kill Bill by the plugin
|
51
|
-
@plugin.kb_apis.proxied_services[:payment_api].payments.should be_empty
|
52
|
-
|
53
|
-
# Verify the token cannot be re-used
|
54
|
-
subsequent_purchase(properties)
|
55
|
-
|
56
|
-
# Verify no token/baid was stored
|
57
|
-
verify_payment_method
|
58
|
-
end
|
59
|
-
|
60
|
-
# Each loop triggers one successful purchase and one successful refund
|
61
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 2 * n
|
62
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 1 + 8 * n
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should generate forms with pending payments correctly' do
|
66
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 0
|
67
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 0
|
68
|
-
|
69
|
-
# Verify the payment cannot go through without the token
|
70
|
-
purchase_with_missing_token
|
71
|
-
|
72
|
-
# Verify multiple payments can be triggered for the same payment method
|
73
|
-
n = 2
|
74
|
-
1.upto(n) do |i|
|
75
|
-
payment_external_key = SecureRandom.uuid
|
76
|
-
properties = @plugin.hash_to_properties(
|
77
|
-
:transaction_external_key => payment_external_key,
|
78
|
-
:create_pending_payment => true
|
79
|
-
)
|
80
|
-
|
81
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
82
|
-
validate_form(form)
|
83
|
-
kb_payment_id = validate_form_property(form, 'kb_payment_id')
|
84
|
-
validate_form_property(form, 'kb_transaction_external_key', payment_external_key)
|
85
|
-
token = validate_form_property(form, 'token')
|
86
|
-
|
87
|
-
# Verify the payment was created in Kill Bill
|
88
|
-
@plugin.kb_apis.proxied_services[:payment_api].payments.size.should == i
|
89
|
-
@plugin.kb_apis.proxied_services[:payment_api].get_payment(kb_payment_id).transactions.first.external_key.should == payment_external_key
|
90
|
-
|
91
|
-
# Verify GET API
|
92
|
-
payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, [], @call_context)
|
93
|
-
payment_infos.size.should == 1
|
94
|
-
payment_infos[0].kb_payment_id.should == kb_payment_id
|
95
|
-
payment_infos[0].transaction_type.should == :PURCHASE
|
96
|
-
payment_infos[0].amount.should be_nil
|
97
|
-
payment_infos[0].currency.should be_nil
|
98
|
-
payment_infos[0].status.should == :PENDING
|
99
|
-
payment_infos[0].gateway_error.should == {:payment_plugin_status => 'PENDING',
|
100
|
-
:token_expiration_period => @plugin.class.const_get(:THREE_HOURS_AGO).to_s}.to_json
|
101
|
-
payment_infos[0].gateway_error_code.should be_nil
|
102
|
-
|
103
|
-
properties = []
|
104
|
-
properties << build_property('token', token)
|
105
|
-
|
106
|
-
# Verify the payment cannot go through until the token is validated
|
107
|
-
purchase_with_invalid_token(properties)
|
108
|
-
|
109
|
-
validate_token(form)
|
110
|
-
|
111
|
-
purchase_and_refund(kb_payment_id, payment_external_key, properties)
|
112
|
-
|
113
|
-
# Verify no extra payment was created in Kill Bill by the plugin
|
114
|
-
@plugin.kb_apis.proxied_services[:payment_api].payments.size.should == i
|
115
|
-
|
116
|
-
# Verify the token cannot be re-used
|
117
|
-
subsequent_purchase(properties)
|
118
|
-
|
119
|
-
# Verify no token/baid was stored
|
120
|
-
verify_payment_method
|
121
|
-
end
|
122
|
-
|
123
|
-
# Each loop triggers one successful purchase and one successful refund
|
124
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 2 * n
|
125
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 1 + 9 * n
|
126
|
-
end
|
127
|
-
|
128
|
-
it 'should generate forms and perform auth, capture and refund correctly' do
|
129
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 0
|
130
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 0
|
131
|
-
|
132
|
-
# Verify the authorization cannot go through without the token
|
133
|
-
authorize_with_missing_token
|
134
|
-
|
135
|
-
# Verify multiple payments can be triggered for the same payment method
|
136
|
-
n = 2
|
137
|
-
1.upto(n) do |i|
|
138
|
-
payment_external_key = SecureRandom.uuid
|
139
|
-
is_pending_payment_test = i % 2 == 1 ? false : true
|
140
|
-
properties = @plugin.hash_to_properties(
|
141
|
-
:transaction_external_key => payment_external_key,
|
142
|
-
# test both with and without pending payments
|
143
|
-
:create_pending_payment => is_pending_payment_test,
|
144
|
-
:payment_processor_account_id => @payment_processor_account_id,
|
145
|
-
:auth_mode => true
|
146
|
-
)
|
147
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
148
|
-
validate_form(form)
|
149
|
-
token = validate_form_property(form, 'token')
|
150
|
-
# Verify payments were created when create_pending_payment is true
|
151
|
-
@plugin.kb_apis.proxied_services[:payment_api].payments.size.should == i / 2
|
152
|
-
if is_pending_payment_test
|
153
|
-
kb_payment_id = validate_form_property(form, 'kb_payment_id')
|
154
|
-
validate_form_property(form, 'kb_transaction_external_key', payment_external_key)
|
155
|
-
@plugin.kb_apis.proxied_services[:payment_api].get_payment(kb_payment_id).transactions.first.external_key.should == payment_external_key
|
156
|
-
# Verify GET API
|
157
|
-
payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
|
158
|
-
payment_infos.size.should == 1
|
159
|
-
payment_infos[0].kb_payment_id.should == kb_payment_id
|
160
|
-
payment_infos[0].transaction_type.should == :AUTHORIZE
|
161
|
-
payment_infos[0].amount.should be_nil
|
162
|
-
payment_infos[0].currency.should be_nil
|
163
|
-
payment_infos[0].status.should == :PENDING
|
164
|
-
payment_infos[0].gateway_error.should == {:payment_plugin_status => 'PENDING',
|
165
|
-
:token_expiration_period => @plugin.class.const_get(:THREE_HOURS_AGO).to_s}.to_json
|
166
|
-
payment_infos[0].gateway_error_code.should be_nil
|
167
|
-
find_value_from_properties(payment_infos[0].properties, :payment_processor_account_id).should == @payment_processor_account_id
|
168
|
-
else
|
169
|
-
kb_payment_id = SecureRandom.uuid
|
170
|
-
validate_nil_form_property(form, 'kb_payment_id')
|
171
|
-
validate_nil_form_property(form, 'kb_transaction_external_key')
|
172
|
-
end
|
173
|
-
|
174
|
-
properties = []
|
175
|
-
properties << build_property(:token, token)
|
176
|
-
# Verify the payment cannot be authorized without the token being validated
|
177
|
-
authorize_with_invalid_token(properties)
|
178
|
-
# Go to PayPal to validate the token
|
179
|
-
validate_token(form)
|
180
|
-
|
181
|
-
# Verify auth, capture and refund
|
182
|
-
authorize_capture_and_refund(kb_payment_id, payment_external_key, properties, @payment_processor_account_id)
|
183
|
-
|
184
|
-
# Verify no extra payment was created in Kill Bill by the plugin
|
185
|
-
@plugin.kb_apis.proxied_services[:payment_api].payments.size.should == (i / 2)
|
186
|
-
|
187
|
-
# Verify no token/baid was stored
|
188
|
-
verify_payment_method
|
189
|
-
end
|
190
|
-
|
191
|
-
# Each loop triggers one successful auth, one successful capture and one successful refund
|
192
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 3 * n
|
193
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 1 + 15 * n / 2 + 7 * n % 2
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'should perform auth and void correctly' do
|
197
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 0
|
198
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 0
|
199
|
-
|
200
|
-
# Verify multiple payments can be triggered for the same payment method
|
201
|
-
n = 2
|
202
|
-
1.upto(n) do |i|
|
203
|
-
payment_external_key = SecureRandom.uuid
|
204
|
-
is_pending_payment_test = i % 2 == 1 ? false : true
|
205
|
-
properties = @plugin.hash_to_properties(
|
206
|
-
:transaction_external_key => payment_external_key,
|
207
|
-
:create_pending_payment => is_pending_payment_test,
|
208
|
-
:auth_mode => true,
|
209
|
-
:payment_processor_account_id => @payment_processor_account_id
|
210
|
-
)
|
211
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
212
|
-
validate_form(form)
|
213
|
-
token = validate_form_property(form, 'token')
|
214
|
-
if is_pending_payment_test
|
215
|
-
kb_payment_id = validate_form_property(form, 'kb_payment_id')
|
216
|
-
else
|
217
|
-
kb_payment_id = SecureRandom.uuid
|
218
|
-
end
|
219
|
-
|
220
|
-
# Go to PayPal to validate the token
|
221
|
-
validate_token(form)
|
222
|
-
|
223
|
-
properties = []
|
224
|
-
properties << build_property('token', token)
|
225
|
-
|
226
|
-
authorize_and_void(kb_payment_id, payment_external_key, properties, @payment_processor_account_id)
|
227
|
-
|
228
|
-
# Verify no extra payment was created in Kill Bill by the plugin
|
229
|
-
@plugin.kb_apis.proxied_services[:payment_api].payments.size.should == i / 2
|
230
|
-
end
|
231
|
-
|
232
|
-
# Each loop triggers one successful authorize and void
|
233
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 2 * n
|
234
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 9 * n / 2 + 5 * n % 2
|
235
|
-
end
|
236
|
-
|
237
|
-
it 'should not capture the same transaction twice with full amount' do
|
238
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 0
|
239
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 0
|
240
|
-
|
241
|
-
payment_external_key = SecureRandom.uuid
|
242
|
-
properties = @plugin.hash_to_properties(
|
243
|
-
:transaction_external_key => payment_external_key,
|
244
|
-
:create_pending_payment => true,
|
245
|
-
:auth_mode => true
|
246
|
-
)
|
247
|
-
|
248
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
249
|
-
validate_form(form)
|
250
|
-
kb_payment_id = validate_form_property(form, 'kb_payment_id')
|
251
|
-
validate_form_property(form, 'kb_transaction_external_key', payment_external_key)
|
252
|
-
token = validate_form_property(form, 'token')
|
253
|
-
|
254
|
-
properties = []
|
255
|
-
properties << build_property('token', token)
|
256
|
-
properties << build_property('auth_mode', 'true')
|
257
|
-
|
258
|
-
validate_token(form)
|
259
|
-
|
260
|
-
authorize_and_double_capture(kb_payment_id, payment_external_key, properties)
|
261
|
-
end
|
262
|
-
|
263
|
-
it 'should find the payment processor id from the initial_express_call' do
|
264
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 0
|
265
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 0
|
266
|
-
|
267
|
-
properties = @plugin.hash_to_properties(
|
268
|
-
:transaction_external_key => SecureRandom.uuid,
|
269
|
-
:create_pending_payment => true,
|
270
|
-
:auth_mode => true,
|
271
|
-
:payment_processor_account_id => @payment_processor_account_id
|
272
|
-
)
|
273
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
274
|
-
token = validate_form_property(form, 'token')
|
275
|
-
@plugin.send(:find_payment_processor_id_from_initial_call, @pm.kb_account_id, @call_context.tenant_id, token).should == @payment_processor_account_id
|
276
|
-
|
277
|
-
properties = @plugin.hash_to_properties(
|
278
|
-
:transaction_external_key => SecureRandom.uuid,
|
279
|
-
:auth_mode => true,
|
280
|
-
:payment_processor_account_id => @payment_processor_account_id
|
281
|
-
)
|
282
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
283
|
-
token = validate_form_property(form, 'token')
|
284
|
-
@plugin.send(:find_payment_processor_id_from_initial_call, @pm.kb_account_id, @call_context.tenant_id, token).should == @payment_processor_account_id
|
285
|
-
|
286
|
-
properties = @plugin.hash_to_properties(
|
287
|
-
:transaction_external_key => SecureRandom.uuid,
|
288
|
-
:create_pending_payment => true,
|
289
|
-
:payment_processor_account_id => @payment_processor_account_id
|
290
|
-
)
|
291
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
292
|
-
token = validate_form_property(form, 'token')
|
293
|
-
@plugin.send(:find_payment_processor_id_from_initial_call, @pm.kb_account_id, @call_context.tenant_id, token).should == @payment_processor_account_id
|
294
|
-
|
295
|
-
properties = @plugin.hash_to_properties(
|
296
|
-
:transaction_external_key => SecureRandom.uuid,
|
297
|
-
:payment_processor_account_id => @payment_processor_account_id
|
298
|
-
)
|
299
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
300
|
-
token = validate_form_property(form, 'token')
|
301
|
-
@plugin.send(:find_payment_processor_id_from_initial_call, @pm.kb_account_id, @call_context.tenant_id, token).should == @payment_processor_account_id
|
302
|
-
end
|
303
|
-
|
304
|
-
it 'should cancel the pending payment if the token expires' do
|
305
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 0
|
306
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 0
|
307
|
-
|
308
|
-
expiration_period = 5
|
309
|
-
payment_external_key = SecureRandom.uuid
|
310
|
-
properties = @plugin.hash_to_properties(
|
311
|
-
:transaction_external_key => payment_external_key,
|
312
|
-
:create_pending_payment => true,
|
313
|
-
:token_expiration_period => expiration_period
|
314
|
-
)
|
315
|
-
|
316
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
317
|
-
kb_payment_id = validate_form_property(form, 'kb_payment_id')
|
318
|
-
payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
|
319
|
-
payment_infos.size.should == 1
|
320
|
-
payment_infos[0].kb_payment_id.should == kb_payment_id
|
321
|
-
payment_infos[0].amount.should be_nil
|
322
|
-
payment_infos[0].currency.should be_nil
|
323
|
-
payment_infos[0].status.should == :PENDING
|
324
|
-
payment_infos[0].gateway_error.should == {:payment_plugin_status => 'PENDING',
|
325
|
-
:token_expiration_period => expiration_period.to_s}.to_json
|
326
|
-
payment_infos[0].gateway_error_code.should be_nil
|
327
|
-
|
328
|
-
sleep payment_infos[0].created_date + expiration_period - Time.parse(@plugin.clock.get_clock.get_utc_now.to_s) + 1
|
329
|
-
|
330
|
-
payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
|
331
|
-
# Make sure no extra response is created
|
332
|
-
payment_infos.size.should == 1
|
333
|
-
payment_infos[0].kb_payment_id.should == kb_payment_id
|
334
|
-
payment_infos[0].amount.should be_nil
|
335
|
-
payment_infos[0].currency.should be_nil
|
336
|
-
payment_infos[0].status.should == :CANCELED
|
337
|
-
payment_infos[0].gateway_error.should == 'Token expired. Payment Canceled by Janitor.'
|
338
|
-
payment_infos[0].gateway_error_code.should be_nil
|
339
|
-
end
|
340
|
-
|
341
|
-
it 'should cancel the pending payment if the token expires without passing property' do
|
342
|
-
::Killbill::PaypalExpress::PaypalExpressTransaction.count.should == 0
|
343
|
-
::Killbill::PaypalExpress::PaypalExpressResponse.count.should == 0
|
344
|
-
|
345
|
-
expiration_period = 5
|
346
|
-
@plugin.class.const_set(:THREE_HOURS_AGO, expiration_period)
|
347
|
-
payment_external_key = SecureRandom.uuid
|
348
|
-
properties = @plugin.hash_to_properties(
|
349
|
-
:transaction_external_key => payment_external_key,
|
350
|
-
:create_pending_payment => true
|
351
|
-
)
|
352
|
-
|
353
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
354
|
-
kb_payment_id = validate_form_property(form, 'kb_payment_id')
|
355
|
-
payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
|
356
|
-
payment_infos.size.should == 1
|
357
|
-
payment_infos[0].kb_payment_id.should == kb_payment_id
|
358
|
-
payment_infos[0].amount.should be_nil
|
359
|
-
payment_infos[0].currency.should be_nil
|
360
|
-
payment_infos[0].status.should == :PENDING
|
361
|
-
payment_infos[0].gateway_error.should == {:payment_plugin_status => 'PENDING',
|
362
|
-
:token_expiration_period => expiration_period.to_s}.to_json
|
363
|
-
payment_infos[0].gateway_error_code.should be_nil
|
364
|
-
|
365
|
-
sleep payment_infos[0].created_date + expiration_period - Time.parse(@plugin.clock.get_clock.get_utc_now.to_s) + 1
|
366
|
-
|
367
|
-
payment_infos = @plugin.get_payment_info(@pm.kb_account_id, kb_payment_id, properties, @call_context)
|
368
|
-
# Make sure no extra response is created
|
369
|
-
payment_infos.size.should == 1
|
370
|
-
payment_infos[0].kb_payment_id.should == kb_payment_id
|
371
|
-
payment_infos[0].amount.should be_nil
|
372
|
-
payment_infos[0].currency.should be_nil
|
373
|
-
payment_infos[0].status.should == :CANCELED
|
374
|
-
payment_infos[0].gateway_error.should == 'Token expired. Payment Canceled by Janitor.'
|
375
|
-
payment_infos[0].gateway_error_code.should be_nil
|
376
|
-
end
|
377
|
-
|
378
|
-
it 'should fix the unknown transactions to success' do
|
379
|
-
[:AUTHORIZE, :CAPTURE, :REFUND].each do |type|
|
380
|
-
payment_external_key = SecureRandom.uuid
|
381
|
-
properties = @plugin.hash_to_properties(
|
382
|
-
:transaction_external_key => payment_external_key,
|
383
|
-
:create_pending_payment => true,
|
384
|
-
:payment_processor_account_id => @payment_processor_account_id,
|
385
|
-
:auth_mode => true
|
386
|
-
)
|
387
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
388
|
-
kb_payment_id = validate_form_property(form, 'kb_payment_id')
|
389
|
-
kb_trx_id = validate_form_property(form, 'kb_transaction_id')
|
390
|
-
validate_token(form)
|
391
|
-
|
392
|
-
@plugin.authorize_payment(@pm.kb_account_id, kb_payment_id, kb_trx_id, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
393
|
-
nb_plugin_info = 1
|
394
|
-
if type == :AUTHORIZE
|
395
|
-
verify_janitor_transition nb_plugin_info, type, :PROCESSED, kb_payment_id
|
396
|
-
# Be able to capture
|
397
|
-
payment_response = @plugin.capture_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
398
|
-
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
399
|
-
payment_response.amount.should == @amount
|
400
|
-
payment_response.transaction_type.should == :CAPTURE
|
401
|
-
elsif type == :CAPTURE
|
402
|
-
nb_plugin_info = 2
|
403
|
-
@plugin.capture_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
404
|
-
verify_janitor_transition nb_plugin_info, type, :PROCESSED, kb_payment_id
|
405
|
-
# Be able to refund
|
406
|
-
payment_response = @plugin.refund_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
407
|
-
payment_response.status.should eq(:PROCESSED), payment_response.gateway_error
|
408
|
-
payment_response.amount.should == @amount
|
409
|
-
payment_response.transaction_type.should == :REFUND
|
410
|
-
elsif type == :REFUND
|
411
|
-
nb_plugin_info = 3
|
412
|
-
@plugin.capture_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
413
|
-
@plugin.refund_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
414
|
-
verify_janitor_transition nb_plugin_info, type, :PROCESSED, kb_payment_id
|
415
|
-
end
|
416
|
-
end
|
417
|
-
end
|
418
|
-
|
419
|
-
it 'should fix the unknown transactions to plugin failure' do
|
420
|
-
[:AUTHORIZE, :CAPTURE, :REFUND].each do |type|
|
421
|
-
payment_external_key = SecureRandom.uuid
|
422
|
-
properties = @plugin.hash_to_properties(
|
423
|
-
:transaction_external_key => payment_external_key,
|
424
|
-
:create_pending_payment => true,
|
425
|
-
:payment_processor_account_id => @payment_processor_account_id,
|
426
|
-
:auth_mode => true
|
427
|
-
)
|
428
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
429
|
-
kb_payment_id = validate_form_property(form, 'kb_payment_id')
|
430
|
-
kb_trx_id = validate_form_property(form, 'kb_transaction_id')
|
431
|
-
validate_token(form)
|
432
|
-
|
433
|
-
properties = @plugin.hash_to_properties({:skip_gw => true})
|
434
|
-
@plugin.authorize_payment(@pm.kb_account_id, kb_payment_id, kb_trx_id, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
435
|
-
nb_plugin_info = 1
|
436
|
-
if type == :CAPTURE
|
437
|
-
nb_plugin_info = 2
|
438
|
-
@plugin.capture_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
439
|
-
elsif type == :REFUND
|
440
|
-
nb_plugin_info = 3
|
441
|
-
@plugin.capture_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
442
|
-
@plugin.refund_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
443
|
-
end
|
444
|
-
verify_janitor_transition nb_plugin_info, type, :CANCELED, kb_payment_id
|
445
|
-
end
|
446
|
-
end
|
447
|
-
|
448
|
-
it 'should remain in unknown if cancellation period is not reached' do
|
449
|
-
[:AUTHORIZE, :CAPTURE, :REFUND].each do |type|
|
450
|
-
payment_external_key = SecureRandom.uuid
|
451
|
-
properties = @plugin.hash_to_properties(
|
452
|
-
:transaction_external_key => payment_external_key,
|
453
|
-
:create_pending_payment => true,
|
454
|
-
:payment_processor_account_id => @payment_processor_account_id,
|
455
|
-
:auth_mode => true
|
456
|
-
)
|
457
|
-
form = @plugin.build_form_descriptor(@pm.kb_account_id, @form_fields, properties, @call_context)
|
458
|
-
kb_payment_id = validate_form_property(form, 'kb_payment_id')
|
459
|
-
kb_trx_id = validate_form_property(form, 'kb_transaction_id')
|
460
|
-
validate_token(form)
|
461
|
-
|
462
|
-
properties = @plugin.hash_to_properties({:skip_gw => true})
|
463
|
-
@plugin.authorize_payment(@pm.kb_account_id, kb_payment_id, kb_trx_id, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
464
|
-
nb_plugin_info = 1
|
465
|
-
if type == :CAPTURE
|
466
|
-
nb_plugin_info = 2
|
467
|
-
@plugin.capture_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
468
|
-
elsif type == :REFUND
|
469
|
-
nb_plugin_info = 3
|
470
|
-
@plugin.capture_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
471
|
-
@plugin.refund_payment(@pm.kb_account_id, kb_payment_id, SecureRandom.uuid, @pm.kb_payment_method_id, @amount, @currency, properties, @call_context)
|
472
|
-
end
|
473
|
-
verify_janitor_transition nb_plugin_info, type, :UNDEFINED, kb_payment_id, true, 3600*3
|
474
|
-
end
|
475
|
-
end
|
476
|
-
end
|
477
|
-
|
478
|
-
describe Killbill::PaypalExpress::PaymentPlugin do
|
479
|
-
include ::Killbill::Plugin::ActiveMerchant::RSpec
|
480
|
-
include ::Killbill::PaypalExpress::BuildPluginHelpers
|
481
|
-
include ::Killbill::PaypalExpress::HppSpecHelpers
|
482
|
-
|
483
|
-
context 'hpp test with a single account' do
|
484
|
-
before(:all) do
|
485
|
-
@payment_processor_account_id = 'default'
|
486
|
-
@plugin = build_start_paypal_plugin
|
487
|
-
hpp_setup
|
488
|
-
end
|
489
|
-
|
490
|
-
include_examples 'hpp_spec_common'
|
491
|
-
end
|
492
|
-
|
493
|
-
context 'hpp test with multiple accounts' do
|
494
|
-
before(:all) do
|
495
|
-
@payment_processor_account_id = 'paypal_test_account'
|
496
|
-
@plugin = build_start_paypal_plugin @payment_processor_account_id
|
497
|
-
hpp_setup
|
498
|
-
end
|
499
|
-
|
500
|
-
include_examples 'hpp_spec_common'
|
501
|
-
end
|
502
|
-
end
|