spree_paypal_express 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/.gitignore +7 -0
  2. data/.travis.yml +14 -0
  3. data/Gemfile +3 -0
  4. data/LICENSE +23 -0
  5. data/README.markdown +146 -0
  6. data/Rakefile +13 -0
  7. data/Versionfile +5 -0
  8. data/app/assets/images/paypal.png +0 -0
  9. data/app/assets/javascripts/admin/spree_paypal_express.js +0 -0
  10. data/app/assets/javascripts/store/spree_paypal_express.js +0 -0
  11. data/app/assets/stylesheets/admin/spree_paypal_express.css +0 -0
  12. data/app/assets/stylesheets/store/spree_paypal_express.css +0 -0
  13. data/app/controllers/spree/checkout_controller_decorator.rb +384 -0
  14. data/app/controllers/spree/paypal_express_callbacks_controller.rb +44 -0
  15. data/app/helpers/spree/checkout_helper_decorator.rb +7 -0
  16. data/app/models/spree/billing_integration/paypal_express.rb +3 -0
  17. data/app/models/spree/billing_integration/paypal_express_base.rb +62 -0
  18. data/app/models/spree/billing_integration/paypal_express_uk.rb +3 -0
  19. data/app/models/spree/log_entry_decorator.rb +3 -0
  20. data/app/models/spree/payment_decorator.rb +3 -0
  21. data/app/models/spree/paypal_account.rb +36 -0
  22. data/app/overrides/spree/shared/_order_details/add_paypal_details.html.erb.deface +16 -0
  23. data/app/views/spree/admin/payments/source_forms/_paypalexpress.html.erb +9 -0
  24. data/app/views/spree/admin/payments/source_forms/_paypalexpressuk.html.erb +9 -0
  25. data/app/views/spree/admin/payments/source_views/_paypalexpress.html.erb +110 -0
  26. data/app/views/spree/admin/payments/source_views/_paypalexpressuk.html.erb +110 -0
  27. data/app/views/spree/admin/paypal_payments/refund.html.erb +15 -0
  28. data/app/views/spree/checkout/payment/_paypalexpress.html.erb +3 -0
  29. data/app/views/spree/checkout/payment/_paypalexpressuk.html.erb +3 -0
  30. data/app/views/spree/shared/_paypal_express_checkout.html.erb +3 -0
  31. data/app/views/spree/shared/paypal_express_confirm.html.erb +23 -0
  32. data/capture-notes +28 -0
  33. data/config/initializers/paypal_express.rb +1 -0
  34. data/config/locales/en-GB.yml +30 -0
  35. data/config/locales/en.yml +32 -0
  36. data/config/routes.rb +25 -0
  37. data/db/migrate/20100224133156_create_paypal_accounts.rb +14 -0
  38. data/db/migrate/20120117182027_namespace_paypal_accounts.rb +5 -0
  39. data/lib/generators/spree_paypal_express/install/install_generator.rb +18 -0
  40. data/lib/spree/paypal_express_configuration.rb +5 -0
  41. data/lib/spree_paypal_express.rb +3 -0
  42. data/lib/spree_paypal_express/engine.rb +38 -0
  43. data/response-example-one +55 -0
  44. data/response-xml-one +137 -0
  45. data/spec/controllers/checkout_controller_spec.rb +323 -0
  46. data/spec/factories/address_factory.rb +13 -0
  47. data/spec/factories/order_factory.rb +11 -0
  48. data/spec/factories/ppx_factory.rb +5 -0
  49. data/spec/factories/state_factory.rb +5 -0
  50. data/spec/models/billing_integration/paypal_express_base_spec.rb +135 -0
  51. data/spec/requests/paypal_express_spec.rb +40 -0
  52. data/spec/spec_helper.rb +37 -0
  53. data/spec/support/authentication_helpers.rb +13 -0
  54. data/spec/support/controller_hacks.rb +33 -0
  55. data/spec/support/shared_connection.rb +12 -0
  56. data/spec/support/url_helpers.rb +7 -0
  57. data/spree_paypal_express.gemspec +24 -0
  58. metadata +224 -0
@@ -0,0 +1,323 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ module Spree
4
+ describe CheckoutController do
5
+ render_views
6
+ let(:token) { "EC-2OPN7UJGFWK9OYFV" }
7
+ let(:order) { FactoryGirl.create(:ppx_order_with_totals, :state => "payment", :shipping_method => shipping_method) }
8
+ let(:shipping_method) { FactoryGirl.create(:shipping_method, :zone => Spree::Zone.find_by_name('North America')) }
9
+ let(:order_total) { (order.total * 100).to_i }
10
+ let(:gateway_provider) { mock(ActiveMerchant::Billing::PaypalExpressGateway) }
11
+ let(:paypal_gateway) { mock(BillingIntegration::PaypalExpress, :id => 123, :preferred_review => false, :preferred_no_shipping => true, :provider => gateway_provider, :preferred_currency => "US", :preferred_allow_guest_checkout => true
12
+ ) }
13
+
14
+ let(:details_for_response) { mock(ActiveMerchant::Billing::PaypalExpressResponse, :success? => true,
15
+ :params => {"payer" => order.user.email, "payer_id" => "FWRVKNRRZ3WUC"}, :address => {}) }
16
+
17
+ let(:purchase_response) { mock(ActiveMerchant::Billing::PaypalExpressResponse, :success? => true, :authorization => 'ABC123456789',
18
+ :params => {"payer" => order.user.email, "payer_id" => "FWRVKNRRZ3WUC", "gross_amount" => order_total, "payment_status" => "Completed"},
19
+ :avs_result => "F",
20
+ :to_yaml => "fake") }
21
+
22
+
23
+ before do
24
+ Spree::Auth::Config.set(:registration_step => false)
25
+ controller.stub(:current_order => order, :check_authorization => true, :current_user => order.user)
26
+ order.stub(:checkout_allowed? => true, :completed? => false)
27
+ order.update!
28
+ end
29
+
30
+ it "should understand paypal routes" do
31
+ pending("Unknown how to make this work within the scope of an engine again")
32
+
33
+ assert_routing("/orders/#{order.number}/checkout/paypal_payment", {:controller => "checkout", :action => "paypal_payment", :order_id => order.number })
34
+ assert_routing("/orders/#{order.number}/checkout/paypal_confirm", {:controller => "checkout", :action => "paypal_confirm", :order_id => order.number })
35
+ end
36
+
37
+ context "paypal_checkout" do
38
+ #feature not implemented
39
+ end
40
+
41
+ context "paypal_payment without auto_capture" do
42
+ let(:redirect_url) { "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=#{token}&useraction=commit" }
43
+
44
+ before { Spree::Config.set(:auto_capture => false) }
45
+
46
+ it "should setup an authorize transaction and redirect to sandbox" do
47
+ PaymentMethod.should_receive(:find).at_least(1).with('123').and_return(paypal_gateway)
48
+
49
+ gateway_provider.should_receive(:redirect_url_for).with(token, {:review => false}).and_return redirect_url
50
+ paypal_gateway.provider.should_receive(:setup_authorization).with(order_total, anything()).and_return(mock(:success? => true, :token => token))
51
+
52
+ get :paypal_payment, {:order_id => order.number, :payment_method_id => "123" }
53
+
54
+ response.should redirect_to "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=#{assigns[:ppx_response].token}&useraction=commit"
55
+ end
56
+
57
+ end
58
+
59
+ context "paypal_payment with auto_capture" do
60
+ let(:redirect_url) { "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=#{token}&useraction=commit" }
61
+
62
+ before { Spree::Config.set(:auto_capture => true) }
63
+
64
+ it "should setup a purchase transaction and redirect to sandbox" do
65
+ PaymentMethod.should_receive(:find).at_least(1).with("123").and_return(paypal_gateway)
66
+
67
+ gateway_provider.should_receive(:redirect_url_for).with(token, {:review => false}).and_return redirect_url
68
+ paypal_gateway.provider.should_receive(:setup_purchase).with(order_total, anything()).and_return(mock(:success? => true, :token => token))
69
+
70
+ get :paypal_payment, {:order_id => order.number, :payment_method_id => "123" }
71
+
72
+ response.should redirect_to "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=#{assigns[:ppx_response].token}&useraction=commit"
73
+ end
74
+
75
+ end
76
+
77
+ context "paypal_confirm" do
78
+ before do
79
+ PaymentMethod.should_receive(:find).at_least(1).with("123").and_return(paypal_gateway)
80
+ order.stub!(:payment_method).and_return paypal_gateway
81
+ end
82
+
83
+ context "with auto_capture and no review" do
84
+ before do
85
+ Spree::Config.set(:auto_capture => true)
86
+ paypal_gateway.stub(:preferred_review => false)
87
+ end
88
+
89
+ it "should capture payment" do
90
+ paypal_gateway.provider.should_receive(:details_for).with(token).and_return(details_for_response)
91
+
92
+ paypal_gateway.provider.should_receive(:purchase).with(order_total, anything()).and_return(purchase_response)
93
+
94
+ get :paypal_confirm, {:order_id => order.number, :payment_method_id => "123", :token => token, :PayerID => "FWRVKNRRZ3WUC" }
95
+
96
+ response.should redirect_to spree.order_path(order)
97
+
98
+ order.reload
99
+ order.state.should == "complete"
100
+ order.completed_at.should_not be_nil
101
+ order.payments.size.should == 1
102
+ order.payment_state.should == "paid"
103
+ end
104
+ end
105
+
106
+ context "with review" do
107
+ before do
108
+ paypal_gateway.stub(:preferred_review => true, :payment_profiles_supported? => true)
109
+ order.stub_chain(:payment, :payment_method, :payment_profiles_supported? => true)
110
+ order.stub_chain(:payment, :source, :type => 'Spree:PaypalAccount')
111
+ end
112
+
113
+ it "should render review" do
114
+ paypal_gateway.provider.should_receive(:details_for).with(token).and_return(details_for_response)
115
+
116
+ get :paypal_confirm, {:order_id => order.number, :payment_method_id => "123", :token => token, :PayerID => "FWRVKNRRZ3WUC" }
117
+
118
+ response.should render_template("shared/paypal_express_confirm")
119
+ order.state.should == "confirm"
120
+ end
121
+
122
+ it "order state should not change on multiple call" do
123
+ paypal_gateway.provider.should_receive(:details_for).twice.with(token).and_return(details_for_response)
124
+
125
+ get :paypal_confirm, {:order_id => order.number, :payment_method_id => "123", :token => token, :PayerID => "FWRVKNRRZ3WUC" }
126
+ get :paypal_confirm, {:order_id => order.number, :payment_method_id => "123", :token => token, :PayerID => "FWRVKNRRZ3WUC" }
127
+ order.state.should == "confirm"
128
+ end
129
+ end
130
+
131
+ context "with review and shipping update" do
132
+ before do
133
+ paypal_gateway.stub(:preferred_review => true)
134
+ paypal_gateway.stub(:preferred_no_shipping => false)
135
+ paypal_gateway.stub(:payment_profiles_supported? => true)
136
+ order.stub_chain(:payment, :payment_method, :payment_profiles_supported? => true)
137
+ order.stub_chain(:payment, :source, :type => 'Spree:PaypalAccount')
138
+ details_for_response.stub(:params => details_for_response.params.merge({'first_name' => 'Dr.', 'last_name' => 'Evil'}),
139
+ :address => {'address1' => 'Apt. 187', 'address2'=> 'Some Str.', 'city' => 'Chevy Chase', 'country' => 'US', 'zip' => '20815', 'state' => 'MD' })
140
+
141
+ end
142
+
143
+ it "should update ship_address and render review" do
144
+ paypal_gateway.provider.should_receive(:details_for).with(token).and_return(details_for_response)
145
+
146
+ get :paypal_confirm, {:order_id => order.number, :payment_method_id => "123", :token => token, :PayerID => "FWRVKNRRZ3WUC" }
147
+
148
+ order.ship_address.address1.should == "Apt. 187"
149
+ order.state.should == "confirm"
150
+ response.should render_template("shared/paypal_express_confirm")
151
+ end
152
+ end
153
+
154
+ context "with un-successful repsonse" do
155
+ before { details_for_response.stub(:success? => false) }
156
+
157
+ it "should log error and redirect to payment step" do
158
+ paypal_gateway.provider.should_receive(:details_for).with(token).and_return(details_for_response)
159
+
160
+ controller.should_receive(:gateway_error).with(details_for_response)
161
+
162
+ get :paypal_confirm, {:order_id => order.number, :payment_method_id => "123", :token => token, :PayerID => "FWRVKNRRZ3WUC" }
163
+
164
+ response.should redirect_to spree.edit_order_checkout_path(order, :state => 'payment')
165
+ end
166
+ end
167
+
168
+ end
169
+
170
+ context "paypal_finish" do
171
+ let(:paypal_account) { stub_model(PaypalAccount, :payer_id => "FWRVKNRRZ3WUC", :email => order.email ) }
172
+ let(:authorize_response) { mock(ActiveMerchant::Billing::PaypalExpressResponse, :success? => true, :authorization => 'ABC123456789',
173
+ :params => {"payer" => order.user.email, "payer_id" => "FWRVKNRRZ3WUC", "gross_amount" => order_total, "payment_status" => "Pending"},
174
+ :avs_result => "F",
175
+ :to_yaml => "fake") }
176
+
177
+ before do
178
+ PaymentMethod.should_receive(:find).at_least(1).with("123").and_return(paypal_gateway)
179
+ PaypalAccount.should_receive(:find_by_payer_id).with("FWRVKNRRZ3WUC").and_return(paypal_account)
180
+ end
181
+
182
+ context "with auto_capture" do
183
+ before { Spree::Config.set(:auto_capture => true) }
184
+
185
+ it "should capture payment" do
186
+
187
+ paypal_gateway.provider.should_receive(:purchase).with(order_total, anything()).and_return(purchase_response)
188
+
189
+ get :paypal_finish, {:order_id => order.number, :payment_method_id => "123", :token => token, :PayerID => "FWRVKNRRZ3WUC" }
190
+
191
+ response.should redirect_to spree.order_path(order)
192
+
193
+ order.reload
194
+ order.update!
195
+ order.payments.size.should == 1
196
+ order.payment_state.should == "paid"
197
+ end
198
+ end
199
+
200
+ context "with auto_capture and pending(echeck) response" do
201
+ before do
202
+ Spree::Config.set(:auto_capture => true)
203
+ purchase_response.params["payment_status"] = "pending"
204
+ end
205
+
206
+ it "should authorize payment" do
207
+
208
+ paypal_gateway.provider.should_receive(:purchase).with(order_total, anything()).and_return(purchase_response)
209
+
210
+ get :paypal_finish, {:order_id => order.number, :payment_method_id => "123", :token => token, :PayerID => "FWRVKNRRZ3WUC" }
211
+
212
+ response.should redirect_to spree.order_path(order)
213
+
214
+ order.reload
215
+ order.update!
216
+ order.payments.size.should == 1
217
+ order.payment_state.should == "balance_due"
218
+ order.payment.state.should == "pending"
219
+ end
220
+ end
221
+
222
+ context "without auto_capture" do
223
+ before { Spree::Config.set(:auto_capture => false) }
224
+
225
+ it "should authorize payment" do
226
+
227
+ paypal_gateway.provider.should_receive(:authorize).with(order_total, anything()).and_return(authorize_response)
228
+
229
+ get :paypal_finish, {:order_id => order.number, :payment_method_id => "123", :token => token, :PayerID => "FWRVKNRRZ3WUC" }
230
+
231
+ response.should redirect_to spree.order_path(order)
232
+
233
+ order.reload
234
+ order.update!
235
+ order.payments.size.should == 1
236
+ order.payment_state.should == "balance_due"
237
+ order.payment.state.should == "pending"
238
+ end
239
+ end
240
+
241
+ context "with un-successful repsonse" do
242
+ before do
243
+ Spree::Config.set(:auto_capture => true)
244
+ purchase_response.stub(:success? => false)
245
+ end
246
+
247
+ it "should log error and redirect to payment step" do
248
+ paypal_gateway.provider.should_receive(:purchase).with(order_total, anything()).and_return(purchase_response)
249
+
250
+ controller.should_receive(:gateway_error).with(purchase_response)
251
+
252
+ get :paypal_finish, {:order_id => order.number, :payment_method_id => "123", :token => token, :PayerID => "FWRVKNRRZ3WUC" }
253
+
254
+ response.should redirect_to spree.edit_order_checkout_path(order, :state => 'payment')
255
+
256
+ order.reload
257
+ order.update!
258
+ order.payments.size.should == 1
259
+ order.payment_state.should == "failed"
260
+ order.payment.state.should == "failed"
261
+ end
262
+ end
263
+
264
+ end
265
+
266
+ context "#fixed_opts" do
267
+
268
+ it "returns hash containing basic settings" do
269
+ I18n.locale = :fr
270
+ opts = controller.send(:fixed_opts)
271
+ opts[:header_image].should == "http://demo.spreecommerce.com/assets/admin/bg/spree_50.png"
272
+ opts[:locale].should == "fr"
273
+ end
274
+
275
+ end
276
+
277
+ context "order_opts" do
278
+
279
+ it "should return hash containing basic order details" do
280
+ opts = controller.send(:order_opts, order, paypal_gateway.id, 'payment')
281
+
282
+ opts.class.should == Hash
283
+ opts[:money].should == order_total
284
+ opts[:subtotal].should == (order.item_total * 100).to_i
285
+ opts[:order_id].should == order.number
286
+ opts[:custom].should == order.number
287
+ opts[:handling].should == 0
288
+ opts[:shipping].should == (order.ship_total * 100).to_i
289
+
290
+ opts[:return_url].should == spree.paypal_confirm_order_checkout_url(order, :payment_method_id => paypal_gateway.id, :host => "test.host")
291
+ opts[:cancel_return_url].should == spree.edit_order_checkout_url(order, :state => 'payment', :host => "test.host")
292
+
293
+ opts[:items].size.should > 0
294
+ opts[:items].size.should == order.line_items.count
295
+ end
296
+
297
+ it "should include credits in returned hash" do
298
+ order_total #need here so variable is set before credit is created.
299
+ order.adjustments.create(:label => "Credit", :amount => -1)
300
+ order.update!
301
+
302
+ opts = controller.send(:order_opts, order, paypal_gateway.id, 'payment')
303
+
304
+ opts.class.should == Hash
305
+ opts[:money].should == order_total - 100
306
+ opts[:subtotal].should == ((order.item_total * 100) + (order.adjustments.select{|c| c.amount < 0}.sum(&:amount) * 100)).to_i
307
+
308
+ opts[:items].size.should == order.line_items.count + 1
309
+ end
310
+
311
+
312
+ end
313
+
314
+ describe "#paypal_site_opts" do
315
+ it "returns opts to allow guest checkout" do
316
+ controller.should_receive(:payment_method).at_least(1).and_return(paypal_gateway)
317
+
318
+ opts = controller.send(:paypal_site_opts)
319
+ opts[:allow_guest_checkout].should be_true
320
+ end
321
+ end
322
+ end
323
+ end
@@ -0,0 +1,13 @@
1
+ Factory.define :ppx_address do |f|
2
+ f.firstname 'John'
3
+ f.lastname 'Doe'
4
+ f.address1 '10 Lovely Street'
5
+ f.address2 'Northwest'
6
+ f.city "Herndon"
7
+ f.state { |state| state.association(:ppx_state) }
8
+ f.zipcode '20170'
9
+ f.country { |country| country.association(:country) }
10
+ f.phone '123-456-7890'
11
+ f.state_name "maryland"
12
+ f.alternative_phone "123-456-7899"
13
+ end
@@ -0,0 +1,11 @@
1
+ Factory.define(:ppx_order) do |record|
2
+ # associations:
3
+ record.association(:user, :factory => :user)
4
+ record.association(:bill_address, :factory => :address)
5
+ record.association(:shipping_method, :factory => :shipping_method)
6
+ record.ship_address { |ship_address| Factory(:ppx_address, :city => "Chevy Chase", :zipcode => "20815") }
7
+ end
8
+
9
+ Factory.define :ppx_order_with_totals, :parent => :order do |f|
10
+ f.after_create { |order| FactoryGirl.create(:line_item, :order => order, :price => 10) and order.line_items.reload }
11
+ end
@@ -0,0 +1,5 @@
1
+ FactoryGirl.define do
2
+ factory :ppx, :class => Spree::BillingIntegration::PaypalExpress, :parent => :payment_method do
3
+ name 'Paypal'
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ Factory.define :md_state do |f|
2
+ f.name 'Maryland'
3
+ f.abbr 'MD'
4
+ f.country { |country| country.association(:country) }
5
+ end
@@ -0,0 +1,135 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::BillingIntegration::PaypalExpressBase do
4
+ let(:order) do
5
+ order = Spree::Order.new(:bill_address => Spree::Address.new,
6
+ :ship_address => Spree::Address.new)
7
+ end
8
+
9
+ let(:gateway) do
10
+ gateway = Spree::BillingIntegration::PaypalExpressBase.new({:environment => 'test', :active => true, :preferred_currency => "EUR"}, :without_protection => true)
11
+ gateway.stub :source_required => true
12
+ gateway.stub :provider => mock('paypal provider')
13
+ gateway.stub :find_authorization => mock('authorization', :params => authorization_params)
14
+ gateway
15
+ end
16
+
17
+ let(:authorization_params) { {'transaction_id' => '123'} }
18
+ let(:provider) { gateway.provider }
19
+
20
+ let(:account) do
21
+ stub_model(Spree::PaypalAccount)
22
+ end
23
+
24
+ let(:payment) do
25
+ payment = Spree::Payment.new
26
+ payment.source = account
27
+ payment.order = order
28
+ payment.payment_method = gateway
29
+ payment.amount = 10.0
30
+ payment
31
+ end
32
+
33
+ let(:amount_in_cents) { payment.amount.to_f * 100 }
34
+
35
+ let!(:success_response) do
36
+ mock('success_response', :success? => true,
37
+ :authorization => '123',
38
+ :avs_result => { 'code' => 'avs-code' })
39
+ end
40
+
41
+ let(:failed_response) { mock('gateway_response', :success? => false) }
42
+
43
+ before(:each) do
44
+ # So it doesn't create log entries every time a processing method is called
45
+ payment.log_entries.stub(:create)
46
+ end
47
+
48
+ describe "#capture" do
49
+ before { payment.state = 'pending' }
50
+
51
+ context "when payment_profiles_supported = true" do
52
+ before { gateway.stub :payment_profiles_supported? => true }
53
+
54
+ context "if sucessful" do
55
+ before do
56
+ provider.should_receive(:capture).with(amount_in_cents, '123', :currency => 'EUR').and_return(success_response)
57
+ end
58
+
59
+ it "should store the response_code" do
60
+ payment.capture!
61
+ payment.response_code.should == '123'
62
+ end
63
+ end
64
+
65
+ context "if unsucessful" do
66
+ before do
67
+ gateway.should_receive(:capture).with(payment, account, anything).and_return(failed_response)
68
+ end
69
+
70
+ it "should not make payment complete" do
71
+ lambda { payment.capture! }.should raise_error(Spree::Core::GatewayError)
72
+ payment.state.should == "failed"
73
+ end
74
+ end
75
+ end
76
+
77
+ context "when payment_profiles_supported = false" do
78
+ before do
79
+ payment.stub :response_code => '123'
80
+ gateway.stub :payment_profiles_supported? => false
81
+ end
82
+
83
+ context "if sucessful" do
84
+ before do
85
+ provider.should_receive(:capture).with(amount_in_cents, '123', anything).and_return(success_response)
86
+ end
87
+
88
+ it "should store the response_code" do
89
+ payment.capture!
90
+ payment.response_code.should == '123'
91
+ end
92
+ end
93
+
94
+ context "if unsucessful" do
95
+ before do
96
+ provider.should_receive(:capture).with(amount_in_cents, '123', anything).and_return(failed_response)
97
+ end
98
+
99
+ it "should not make payment complete" do
100
+ lambda { payment.capture! }.should raise_error(Spree::Core::GatewayError)
101
+ payment.state.should == "failed"
102
+ end
103
+ end
104
+
105
+ end
106
+ end
107
+
108
+ describe "#credit" do
109
+ before { payment.stub :response_code => '123' }
110
+ context "when payment_profiles_supported = true" do
111
+ before { gateway.stub :payment_profiles_supported? => true }
112
+
113
+
114
+ it "should receive correct params" do
115
+ provider.should_receive(:credit).with(1000, '123', :currency => 'EUR').and_return(success_response)
116
+ payment.credit!(10.0)
117
+ payment.response_code.should == '123'
118
+ end
119
+ end
120
+
121
+ context "when payment_profiles_supported = false" do
122
+ before do
123
+ payment.stub :response_code => '123'
124
+ gateway.stub :payment_profiles_supported? => false
125
+ end
126
+
127
+ it "should receive correct params" do
128
+ provider.should_receive(:credit).with(amount_in_cents, '123', :currency => 'EUR').and_return(success_response)
129
+ payment.credit!(10.0)
130
+ payment.response_code.should == '123'
131
+ end
132
+
133
+ end
134
+ end
135
+ end