creative-paypal-express 0.8.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +22 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +6 -0
  6. data/Gemfile +7 -0
  7. data/LICENSE +20 -0
  8. data/README.rdoc +34 -0
  9. data/Rakefile +19 -0
  10. data/VERSION +1 -0
  11. data/lib/paypal.rb +84 -0
  12. data/lib/paypal/base.rb +19 -0
  13. data/lib/paypal/exception.rb +4 -0
  14. data/lib/paypal/exception/api_error.rb +94 -0
  15. data/lib/paypal/exception/http_error.rb +12 -0
  16. data/lib/paypal/express.rb +1 -0
  17. data/lib/paypal/express/request.rb +195 -0
  18. data/lib/paypal/express/response.rb +35 -0
  19. data/lib/paypal/ipn.rb +23 -0
  20. data/lib/paypal/nvp/request.rb +64 -0
  21. data/lib/paypal/nvp/response.rb +233 -0
  22. data/lib/paypal/payment/common/amount.rb +13 -0
  23. data/lib/paypal/payment/recurring.rb +43 -0
  24. data/lib/paypal/payment/recurring/activation.rb +14 -0
  25. data/lib/paypal/payment/recurring/billing.rb +39 -0
  26. data/lib/paypal/payment/recurring/summary.rb +11 -0
  27. data/lib/paypal/payment/request.rb +67 -0
  28. data/lib/paypal/payment/request/item.rb +26 -0
  29. data/lib/paypal/payment/response.rb +73 -0
  30. data/lib/paypal/payment/response/address.rb +7 -0
  31. data/lib/paypal/payment/response/info.rb +45 -0
  32. data/lib/paypal/payment/response/item.rb +41 -0
  33. data/lib/paypal/payment/response/payer.rb +7 -0
  34. data/lib/paypal/payment/response/reference.rb +9 -0
  35. data/lib/paypal/payment/response/refund.rb +13 -0
  36. data/lib/paypal/util.rb +28 -0
  37. data/paypal-express.gemspec +23 -0
  38. data/spec/fake_response/BillAgreementUpdate/fetch.txt +1 -0
  39. data/spec/fake_response/BillAgreementUpdate/revoke.txt +1 -0
  40. data/spec/fake_response/CreateBillingAgreement/success.txt +1 -0
  41. data/spec/fake_response/CreateRecurringPaymentsProfile/failure.txt +1 -0
  42. data/spec/fake_response/CreateRecurringPaymentsProfile/success.txt +1 -0
  43. data/spec/fake_response/DoCapture/failure.txt +1 -0
  44. data/spec/fake_response/DoCapture/success.txt +1 -0
  45. data/spec/fake_response/DoExpressCheckoutPayment/failure.txt +1 -0
  46. data/spec/fake_response/DoExpressCheckoutPayment/success.txt +1 -0
  47. data/spec/fake_response/DoExpressCheckoutPayment/success_with_billing_agreement.txt +1 -0
  48. data/spec/fake_response/DoExpressCheckoutPayment/success_with_many_items.txt +1 -0
  49. data/spec/fake_response/DoReferenceTransaction/failure.txt +1 -0
  50. data/spec/fake_response/DoReferenceTransaction/success.txt +1 -0
  51. data/spec/fake_response/DoVoid/success.txt +1 -0
  52. data/spec/fake_response/GetExpressCheckoutDetails/failure.txt +1 -0
  53. data/spec/fake_response/GetExpressCheckoutDetails/success.txt +1 -0
  54. data/spec/fake_response/GetExpressCheckoutDetails/with_billing_accepted_status.txt +1 -0
  55. data/spec/fake_response/GetRecurringPaymentsProfileDetails/failure.txt +1 -0
  56. data/spec/fake_response/GetRecurringPaymentsProfileDetails/success.txt +1 -0
  57. data/spec/fake_response/GetTransactionDetails/failure.txt +1 -0
  58. data/spec/fake_response/GetTransactionDetails/success.txt +1 -0
  59. data/spec/fake_response/IPN/invalid.txt +1 -0
  60. data/spec/fake_response/IPN/valid.txt +1 -0
  61. data/spec/fake_response/ManageRecurringPaymentsProfileStatus/failure.txt +1 -0
  62. data/spec/fake_response/ManageRecurringPaymentsProfileStatus/success.txt +1 -0
  63. data/spec/fake_response/RefundTransaction/full.txt +1 -0
  64. data/spec/fake_response/SetExpressCheckout/failure.txt +1 -0
  65. data/spec/fake_response/SetExpressCheckout/success.txt +1 -0
  66. data/spec/helpers/fake_response_helper.rb +33 -0
  67. data/spec/paypal/exception/api_error_spec.rb +78 -0
  68. data/spec/paypal/exception/http_error_spec.rb +8 -0
  69. data/spec/paypal/express/request_spec.rb +584 -0
  70. data/spec/paypal/express/response_spec.rb +80 -0
  71. data/spec/paypal/ipn_spec.rb +19 -0
  72. data/spec/paypal/nvp/request_spec.rb +116 -0
  73. data/spec/paypal/nvp/response_spec.rb +146 -0
  74. data/spec/paypal/payment/common/amount_spec.rb +36 -0
  75. data/spec/paypal/payment/recurring/activation_spec.rb +19 -0
  76. data/spec/paypal/payment/recurring_spec.rb +170 -0
  77. data/spec/paypal/payment/request/item_spec.rb +27 -0
  78. data/spec/paypal/payment/request_spec.rb +136 -0
  79. data/spec/paypal/payment/response/address_spec.rb +26 -0
  80. data/spec/paypal/payment/response/info_spec.rb +93 -0
  81. data/spec/paypal/payment/response/item_spec.rb +42 -0
  82. data/spec/paypal/payment/response/payer_spec.rb +26 -0
  83. data/spec/paypal/payment/response_spec.rb +16 -0
  84. data/spec/paypal/util_spec.rb +32 -0
  85. data/spec/spec_helper.rb +25 -0
  86. metadata +278 -0
@@ -0,0 +1 @@
1
+ TIMESTAMP=2011%2d02%2d02T02%3a16%3a50Z&CORRELATIONID=379d1b7f97afb&ACK=Failure&L_ERRORCODE0=10001&L_SHORTMESSAGE0=Internal%20Error&L_LONGMESSAGE0=Timeout%20processing%20request
@@ -0,0 +1 @@
1
+ ACK=Success&BUILD=1721431&CORRELATIONID=5549ea3a78af1&TIMESTAMP=2011-02-02T02%3A02%3A18Z&TOKEN=EC-5YJ90598G69065317&VERSION=66.0
@@ -0,0 +1,33 @@
1
+ require 'fakeweb'
2
+
3
+ module FakeResponseHelper
4
+
5
+ def fake_response(file_path, api = :NVP, options = {})
6
+ endpoint = case api
7
+ when :NVP
8
+ Paypal::NVP::Request.endpoint
9
+ when :IPN
10
+ Paypal::IPN.endpoint
11
+ else
12
+ raise "Non-supported API: #{api}"
13
+ end
14
+ FakeWeb.register_uri(
15
+ :post,
16
+ endpoint,
17
+ options.merge(
18
+ :body => File.read(File.join(File.dirname(__FILE__), '../fake_response', "#{file_path}.txt"))
19
+ )
20
+ )
21
+ end
22
+
23
+ def request_to(endpoint, method = :get)
24
+ raise_error(
25
+ FakeWeb::NetConnectNotAllowedError,
26
+ "Real HTTP connections are disabled. Unregistered request: #{method.to_s.upcase} #{endpoint}"
27
+ )
28
+ end
29
+
30
+ end
31
+
32
+ FakeWeb.allow_net_connect = false
33
+ include FakeResponseHelper
@@ -0,0 +1,78 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Paypal::Exception::APIError do
4
+ let(:error) { Paypal::Exception::APIError.new(params) }
5
+
6
+ context 'when Hash is given' do
7
+ let :params do
8
+ {
9
+ :VERSION=>"66.0",
10
+ :TIMESTAMP=>"2011-03-03T06:33:51Z",
11
+ :CORRELATIONID=>"758ebdc546b9c",
12
+ :BUILD=>"1741654",
13
+ :ACK=>"Failure",
14
+ :L_SEVERITYCODE0=>"Error",
15
+ :L_ERRORCODE0=>"10411",
16
+ :L_LONGMESSAGE0=>"This Express Checkout session has expired. Token value is no longer valid.",
17
+ :L_SHORTMESSAGE0=>"This Express Checkout session has expired.",
18
+ :L_SEVERITYCODE1=>"Error",
19
+ :L_ERRORCODE1=>"2468",
20
+ :L_LONGMESSAGE1=>"Sample of a long message for the second item.",
21
+ :L_SHORTMESSAGE1=>"Second short message.",
22
+ }
23
+ end
24
+
25
+ describe "#message" do
26
+ it "aggregates short messages" do
27
+ error.message.should ==
28
+ "PayPal API Error: 'This Express Checkout session has expired.', 'Second short message.'"
29
+ end
30
+ end
31
+
32
+ describe '#subject' do
33
+ subject { error.response }
34
+ its(:raw) { should == params }
35
+ Paypal::Exception::APIError::Response.attribute_mapping.each do |key, attribute|
36
+ its(attribute) { should == params[key] }
37
+ end
38
+
39
+ describe '#details' do
40
+ subject { error.response.details.first }
41
+ Paypal::Exception::APIError::Response::Detail.attribute_mapping.each do |key, attribute|
42
+ its(attribute) { should == params[:"L_#{key}0"] }
43
+ end
44
+ end
45
+ end
46
+ end
47
+
48
+ context 'when unknown params given' do
49
+ let :params do
50
+ {
51
+ :UNKNOWN => 'Unknown',
52
+ :L_UNKNOWN0 => 'Unknown Detail'
53
+ }
54
+ end
55
+
56
+ it 'should warn' do
57
+ Paypal.logger.should_receive(:warn).with(
58
+ "Ignored Parameter (Paypal::Exception::APIError::Response): UNKNOWN=Unknown"
59
+ )
60
+ Paypal.logger.should_receive(:warn).with(
61
+ "Ignored Parameter (Paypal::Exception::APIError::Response::Detail): UNKNOWN=Unknown Detail"
62
+ )
63
+ error
64
+ end
65
+ describe '#response' do
66
+ subject { error.response }
67
+ its(:raw) { should == params }
68
+ end
69
+ its(:message) { should == "PayPal API Error" }
70
+ end
71
+
72
+ context 'otherwise' do
73
+ subject { error }
74
+ let(:params) { 'Failure' }
75
+ its(:response) { should == params }
76
+ its(:message) { should == "PayPal API Error" }
77
+ end
78
+ end
@@ -0,0 +1,8 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Paypal::Exception::HttpError do
4
+ subject { Paypal::Exception::HttpError.new(400, 'BadRequest', 'You are bad man!') }
5
+ its(:code) { should == 400 }
6
+ its(:message) { should == 'BadRequest' }
7
+ its(:body) { should == 'You are bad man!' }
8
+ end
@@ -0,0 +1,584 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Paypal::Express::Request do
4
+ class Paypal::Express::Request
5
+ attr_accessor :_sent_params_, :_method_
6
+ def post_with_logging(method, params)
7
+ self._method_ = method
8
+ self._sent_params_ = params
9
+ post_without_logging method, params
10
+ end
11
+ alias_method_chain :post, :logging
12
+ end
13
+
14
+ let(:return_url) { 'http://example.com/success' }
15
+ let(:cancel_url) { 'http://example.com/cancel' }
16
+ let(:nvp_endpoint) { Paypal::NVP::Request::ENDPOINT[:production] }
17
+ let :attributes do
18
+ {
19
+ :username => 'nov',
20
+ :password => 'password',
21
+ :signature => 'sig'
22
+ }
23
+ end
24
+
25
+ let :instance do
26
+ Paypal::Express::Request.new attributes
27
+ end
28
+
29
+ let :instant_payment_request do
30
+ Paypal::Payment::Request.new(
31
+ :amount => 1000,
32
+ :description => 'Instant Payment Request'
33
+ )
34
+ end
35
+
36
+ let :many_items do
37
+ items = Array.new
38
+ (1..20).each do |index|
39
+ items << Paypal::Payment::Request::Item.new(
40
+ :name => "Item#{index.to_s}",
41
+ :description => "A new Item #{index.to_s}",
42
+ :amount => 50.00,
43
+ :quantity => 1
44
+ )
45
+ end
46
+ end
47
+
48
+ let :instant_payment_request_with_many_items do
49
+ Paypal::Payment::Request.new(
50
+ :amount => 1000,
51
+ :description => 'Instant Payment Request',
52
+ :items => many_items
53
+ )
54
+ end
55
+
56
+ let :recurring_payment_request do
57
+ Paypal::Payment::Request.new(
58
+ :billing_type => :RecurringPayments,
59
+ :billing_agreement_description => 'Recurring Payment Request'
60
+ )
61
+ end
62
+
63
+ let :recurring_profile do
64
+ Paypal::Payment::Recurring.new(
65
+ :start_date => Time.utc(2011, 2, 8, 9, 0, 0),
66
+ :description => 'Recurring Profile',
67
+ :billing => {
68
+ :period => :Month,
69
+ :frequency => 1,
70
+ :amount => 1000
71
+ }
72
+ )
73
+ end
74
+
75
+ let :reference_transaction_request do
76
+ Paypal::Payment::Request.new(
77
+ :billing_type => :MerchantInitiatedBilling,
78
+ :billing_agreement_description => 'Billing Agreement Request'
79
+ )
80
+ end
81
+
82
+ describe '.new' do
83
+ context 'when any required parameters are missing' do
84
+ it 'should raise AttrRequired::AttrMissing' do
85
+ attributes.keys.each do |missing_key|
86
+ insufficient_attributes = attributes.reject do |key, value|
87
+ key == missing_key
88
+ end
89
+ expect do
90
+ Paypal::Express::Request.new insufficient_attributes
91
+ end.to raise_error AttrRequired::AttrMissing
92
+ end
93
+ end
94
+ end
95
+
96
+ context 'when all required parameters are given' do
97
+ it 'should succeed' do
98
+ expect do
99
+ Paypal::Express::Request.new attributes
100
+ end.not_to raise_error AttrRequired::AttrMissing
101
+ end
102
+ end
103
+ end
104
+
105
+ describe '#setup' do
106
+ it 'should return Paypal::Express::Response' do
107
+ fake_response 'SetExpressCheckout/success'
108
+ response = instance.setup recurring_payment_request, return_url, cancel_url
109
+ response.should be_instance_of Paypal::Express::Response
110
+ end
111
+
112
+ it 'should support no_shipping option' do
113
+ expect do
114
+ instance.setup instant_payment_request, return_url, cancel_url, :no_shipping => true
115
+ end.to request_to nvp_endpoint, :post
116
+ instance._method_.should == :SetExpressCheckout
117
+ instance._sent_params_.should == {
118
+ :PAYMENTREQUEST_0_DESC => 'Instant Payment Request',
119
+ :RETURNURL => return_url,
120
+ :CANCELURL => cancel_url,
121
+ :PAYMENTREQUEST_0_AMT => '1000.00',
122
+ :PAYMENTREQUEST_0_TAXAMT => "0.00",
123
+ :PAYMENTREQUEST_0_SHIPPINGAMT => "0.00",
124
+ :REQCONFIRMSHIPPING => 0,
125
+ :NOSHIPPING => 1
126
+ }
127
+ end
128
+
129
+ it 'should support allow_note=false option' do
130
+ expect do
131
+ instance.setup instant_payment_request, return_url, cancel_url, :allow_note => false
132
+ end.to request_to nvp_endpoint, :post
133
+ instance._method_.should == :SetExpressCheckout
134
+ instance._sent_params_.should == {
135
+ :PAYMENTREQUEST_0_DESC => 'Instant Payment Request',
136
+ :RETURNURL => return_url,
137
+ :CANCELURL => cancel_url,
138
+ :PAYMENTREQUEST_0_AMT => '1000.00',
139
+ :PAYMENTREQUEST_0_TAXAMT => "0.00",
140
+ :PAYMENTREQUEST_0_SHIPPINGAMT => "0.00",
141
+ :ALLOWNOTE => 0
142
+ }
143
+ end
144
+
145
+ {
146
+ :solution_type => :SOLUTIONTYPE,
147
+ :landing_page => :LANDINGPAGE,
148
+ :email => :EMAIL,
149
+ :brand => :BRANDNAME,
150
+ :locale => :LOCALECODE,
151
+ :logo => :LOGOIMG,
152
+ :cart_border_color => :CARTBORDERCOLOR,
153
+ :payflow_color => :PAYFLOWCOLOR
154
+ }.each do |option_key, param_key|
155
+ it "should support #{option_key} option" do
156
+ expect do
157
+ instance.setup instant_payment_request, return_url, cancel_url, option_key => 'some value'
158
+ end.to request_to nvp_endpoint, :post
159
+ instance._method_.should == :SetExpressCheckout
160
+ instance._sent_params_.should include param_key
161
+ instance._sent_params_[param_key].should == 'some value'
162
+ end
163
+ end
164
+
165
+ context 'when instance payment request given' do
166
+ it 'should call SetExpressCheckout' do
167
+ expect do
168
+ instance.setup instant_payment_request, return_url, cancel_url
169
+ end.to request_to nvp_endpoint, :post
170
+ instance._method_.should == :SetExpressCheckout
171
+ instance._sent_params_.should == {
172
+ :PAYMENTREQUEST_0_DESC => 'Instant Payment Request',
173
+ :RETURNURL => return_url,
174
+ :CANCELURL => cancel_url,
175
+ :PAYMENTREQUEST_0_AMT => '1000.00',
176
+ :PAYMENTREQUEST_0_TAXAMT => "0.00",
177
+ :PAYMENTREQUEST_0_SHIPPINGAMT => "0.00"
178
+ }
179
+ end
180
+ end
181
+
182
+ context 'when recurring payment request given' do
183
+ it 'should call SetExpressCheckout' do
184
+ expect do
185
+ instance.setup recurring_payment_request, return_url, cancel_url
186
+ end.to request_to nvp_endpoint, :post
187
+ instance._method_.should == :SetExpressCheckout
188
+ instance._sent_params_.should == {
189
+ :L_BILLINGTYPE0 => :RecurringPayments,
190
+ :L_BILLINGAGREEMENTDESCRIPTION0 => 'Recurring Payment Request',
191
+ :RETURNURL => return_url,
192
+ :CANCELURL => cancel_url,
193
+ :PAYMENTREQUEST_0_AMT => '0.00',
194
+ :PAYMENTREQUEST_0_TAXAMT => "0.00",
195
+ :PAYMENTREQUEST_0_SHIPPINGAMT => "0.00"
196
+ }
197
+ end
198
+ end
199
+
200
+ context 'when reference transaction request given' do
201
+ it 'should call SetExpressCheckout' do
202
+ expect do
203
+ instance.setup reference_transaction_request, return_url, cancel_url
204
+ end.to request_to nvp_endpoint, :post
205
+ instance._method_.should == :SetExpressCheckout
206
+ instance._sent_params_.should == {
207
+ :L_BILLINGTYPE0 => :MerchantInitiatedBilling,
208
+ :L_BILLINGAGREEMENTDESCRIPTION0 => 'Billing Agreement Request',
209
+ :RETURNURL => return_url,
210
+ :CANCELURL => cancel_url,
211
+ :PAYMENTREQUEST_0_AMT => '0.00',
212
+ :PAYMENTREQUEST_0_TAXAMT => "0.00",
213
+ :PAYMENTREQUEST_0_SHIPPINGAMT => "0.00"
214
+ }
215
+ end
216
+ end
217
+ end
218
+
219
+ describe '#details' do
220
+ it 'should return Paypal::Express::Response' do
221
+ fake_response 'GetExpressCheckoutDetails/success'
222
+ response = instance.details 'token'
223
+ response.should be_instance_of Paypal::Express::Response
224
+ end
225
+
226
+ it 'should call GetExpressCheckoutDetails' do
227
+ expect do
228
+ instance.details 'token'
229
+ end.to request_to nvp_endpoint, :post
230
+ instance._method_.should == :GetExpressCheckoutDetails
231
+ instance._sent_params_.should == {
232
+ :TOKEN => 'token'
233
+ }
234
+ end
235
+ end
236
+
237
+ describe '#transaction_details' do
238
+ it 'should return Paypal::Express::Response' do
239
+ fake_response 'GetTransactionDetails/success'
240
+ response = instance.transaction_details 'transaction_id'
241
+ response.should be_instance_of Paypal::Express::Response
242
+ end
243
+
244
+ it 'should call GetTransactionDetails' do
245
+ expect do
246
+ instance.transaction_details 'transaction_id'
247
+ end.to request_to nvp_endpoint, :post
248
+ instance._method_.should == :GetTransactionDetails
249
+ instance._sent_params_.should == {
250
+ :TRANSACTIONID=> 'transaction_id'
251
+ }
252
+ end
253
+
254
+ it 'should fail with bad transaction id' do
255
+ expect do
256
+ fake_response 'GetTransactionDetails/failure'
257
+ response = instance.transaction_details 'bad_transaction_id'
258
+ end.to raise_error(Paypal::Exception::APIError)
259
+ end
260
+
261
+ it 'should handle all attributes' do
262
+ Paypal.logger.should_not_receive(:warn)
263
+ fake_response 'GetTransactionDetails/success'
264
+ response = instance.transaction_details 'transaction_id'
265
+ end
266
+ end
267
+
268
+ describe "#capture!" do
269
+ it 'should return Paypal::Express::Response' do
270
+ fake_response 'DoCapture/success'
271
+ response = instance.capture! 'authorization_id', 181.98, :BRL
272
+ response.should be_instance_of Paypal::Express::Response
273
+ end
274
+
275
+ it 'should call DoExpressCheckoutPayment' do
276
+ expect do
277
+ instance.capture! 'authorization_id', 181.98, :BRL
278
+ end.to request_to nvp_endpoint, :post
279
+
280
+ instance._method_.should == :DoCapture
281
+ instance._sent_params_.should == {
282
+ :AUTHORIZATIONID => 'authorization_id',
283
+ :COMPLETETYPE => 'Complete',
284
+ :AMT => 181.98,
285
+ :CURRENCYCODE => :BRL
286
+ }
287
+ end
288
+
289
+ it 'should call DoExpressCheckoutPayment with NotComplete capture parameter' do
290
+ expect do
291
+ instance.capture! 'authorization_id', 181.98, :BRL, 'NotComplete'
292
+ end.to request_to nvp_endpoint, :post
293
+
294
+ instance._method_.should == :DoCapture
295
+ instance._sent_params_.should == {
296
+ :AUTHORIZATIONID => 'authorization_id',
297
+ :COMPLETETYPE => 'NotComplete',
298
+ :AMT => 181.98,
299
+ :CURRENCYCODE => :BRL
300
+ }
301
+ end
302
+ end
303
+
304
+ describe "#void!" do
305
+ it 'should return Paypal::Express::Response' do
306
+ fake_response 'DoVoid/success'
307
+ response = instance.void! 'authorization_id', note: "note"
308
+ response.should be_instance_of Paypal::Express::Response
309
+ end
310
+
311
+ it 'should call DoVoid' do
312
+ expect do
313
+ instance.void! 'authorization_id', note: "note"
314
+ end.to request_to nvp_endpoint, :post
315
+
316
+ instance._method_.should == :DoVoid
317
+ instance._sent_params_.should == {
318
+ :AUTHORIZATIONID => 'authorization_id',
319
+ :NOTE => "note"
320
+ }
321
+ end
322
+ end
323
+
324
+ describe '#checkout!' do
325
+ it 'should return Paypal::Express::Response' do
326
+ fake_response 'DoExpressCheckoutPayment/success'
327
+ response = instance.checkout! 'token', 'payer_id', instant_payment_request
328
+ response.should be_instance_of Paypal::Express::Response
329
+ end
330
+
331
+ it 'should call DoExpressCheckoutPayment' do
332
+ expect do
333
+ instance.checkout! 'token', 'payer_id', instant_payment_request
334
+ end.to request_to nvp_endpoint, :post
335
+ instance._method_.should == :DoExpressCheckoutPayment
336
+ instance._sent_params_.should == {
337
+ :PAYERID => 'payer_id',
338
+ :TOKEN => 'token',
339
+ :PAYMENTREQUEST_0_DESC => 'Instant Payment Request',
340
+ :PAYMENTREQUEST_0_AMT => '1000.00',
341
+ :PAYMENTREQUEST_0_TAXAMT => "0.00",
342
+ :PAYMENTREQUEST_0_SHIPPINGAMT => "0.00"
343
+ }
344
+ end
345
+
346
+ context "with many items" do
347
+ before do
348
+ fake_response 'DoExpressCheckoutPayment/success_with_many_items'
349
+ end
350
+
351
+ it 'should handle all attributes' do
352
+ Paypal.logger.should_not_receive(:warn)
353
+ response = instance.checkout! 'token', 'payer_id', instant_payment_request_with_many_items
354
+ end
355
+
356
+ it 'should return Paypal::Express::Response' do
357
+ response = instance.checkout! 'token', 'payer_id', instant_payment_request_with_many_items
358
+ response.should be_instance_of Paypal::Express::Response
359
+ end
360
+
361
+ it 'should return twenty items' do
362
+ response = instance.checkout! 'token', 'payer_id', instant_payment_request_with_many_items
363
+ instance._method_.should == :DoExpressCheckoutPayment
364
+ response.items.count.should == 20
365
+ end
366
+ end
367
+ end
368
+
369
+ describe '#subscribe!' do
370
+ it 'should return Paypal::Express::Response' do
371
+ fake_response 'CreateRecurringPaymentsProfile/success'
372
+ response = instance.subscribe! 'token', recurring_profile
373
+ response.should be_instance_of Paypal::Express::Response
374
+ end
375
+
376
+ it 'should call CreateRecurringPaymentsProfile' do
377
+ expect do
378
+ instance.subscribe! 'token', recurring_profile
379
+ end.to request_to nvp_endpoint, :post
380
+ instance._method_.should == :CreateRecurringPaymentsProfile
381
+ instance._sent_params_.should == {
382
+ :DESC => 'Recurring Profile',
383
+ :TOKEN => 'token',
384
+ :SHIPPINGAMT => '0.00',
385
+ :AMT => '1000.00',
386
+ :BILLINGFREQUENCY => 1,
387
+ :MAXFAILEDPAYMENTS => 0,
388
+ :BILLINGPERIOD => :Month,
389
+ :TAXAMT => '0.00',
390
+ :PROFILESTARTDATE => '2011-02-08 09:00:00',
391
+ :TOTALBILLINGCYCLES => 0
392
+ }
393
+ end
394
+ end
395
+
396
+ describe '#subscription' do
397
+ it 'should return Paypal::Express::Response' do
398
+ fake_response 'GetRecurringPaymentsProfileDetails/success'
399
+ response = instance.subscription 'profile_id'
400
+ response.should be_instance_of(Paypal::Express::Response)
401
+ end
402
+
403
+ it 'should call GetRecurringPaymentsProfileDetails' do
404
+ expect do
405
+ instance.subscription 'profile_id'
406
+ end.to request_to nvp_endpoint, :post
407
+ instance._method_.should == :GetRecurringPaymentsProfileDetails
408
+ instance._sent_params_.should == {
409
+ :PROFILEID => 'profile_id'
410
+ }
411
+ end
412
+ end
413
+
414
+ describe '#renew!' do
415
+ it 'should return Paypal::Express::Response' do
416
+ fake_response 'ManageRecurringPaymentsProfileStatus/success'
417
+ response = instance.renew! 'profile_id', :Cancel
418
+ response.should be_instance_of Paypal::Express::Response
419
+ end
420
+
421
+ it 'should call ManageRecurringPaymentsProfileStatus' do
422
+ expect do
423
+ instance.renew! 'profile_id', :Cancel
424
+ end.to request_to nvp_endpoint, :post
425
+ instance._method_.should == :ManageRecurringPaymentsProfileStatus
426
+ instance._sent_params_.should == {
427
+ :ACTION => :Cancel,
428
+ :PROFILEID => 'profile_id'
429
+ }
430
+ end
431
+ end
432
+
433
+ describe '#cancel!' do
434
+ it 'should return Paypal::Express::Response' do
435
+ fake_response 'ManageRecurringPaymentsProfileStatus/success'
436
+ response = instance.cancel! 'profile_id'
437
+ response.should be_instance_of(Paypal::Express::Response)
438
+ end
439
+
440
+ it 'should call ManageRecurringPaymentsProfileStatus' do
441
+ expect do
442
+ instance.cancel! 'profile_id'
443
+ end.to request_to nvp_endpoint, :post
444
+ instance._method_.should == :ManageRecurringPaymentsProfileStatus
445
+ instance._sent_params_.should == {
446
+ :ACTION => :Cancel,
447
+ :PROFILEID => 'profile_id'
448
+ }
449
+ end
450
+ end
451
+
452
+ describe '#suspend!' do
453
+ it 'should return Paypal::Express::Response' do
454
+ fake_response 'ManageRecurringPaymentsProfileStatus/success'
455
+ response = instance.cancel! 'profile_id'
456
+ response.should be_instance_of Paypal::Express::Response
457
+ end
458
+
459
+ it 'should call ManageRecurringPaymentsProfileStatus' do
460
+ expect do
461
+ instance.suspend! 'profile_id'
462
+ end.to request_to nvp_endpoint, :post
463
+ instance._method_.should == :ManageRecurringPaymentsProfileStatus
464
+ instance._sent_params_.should == {
465
+ :ACTION => :Suspend,
466
+ :PROFILEID => 'profile_id'
467
+ }
468
+ end
469
+ end
470
+
471
+ describe '#reactivate!' do
472
+ it 'should return Paypal::Express::Response' do
473
+ fake_response 'ManageRecurringPaymentsProfileStatus/success'
474
+ response = instance.cancel! 'profile_id'
475
+ response.should be_instance_of Paypal::Express::Response
476
+ end
477
+
478
+ it 'should call ManageRecurringPaymentsProfileStatus' do
479
+ expect do
480
+ instance.reactivate! 'profile_id'
481
+ end.to request_to nvp_endpoint, :post
482
+ instance._method_.should == :ManageRecurringPaymentsProfileStatus
483
+ instance._sent_params_.should == {
484
+ :ACTION => :Reactivate,
485
+ :PROFILEID => 'profile_id'
486
+ }
487
+ end
488
+ end
489
+
490
+ describe '#agree!' do
491
+ it 'should return Paypal::Express::Response' do
492
+ fake_response 'CreateBillingAgreement/success'
493
+ response = instance.agree! 'token'
494
+ response.should be_instance_of Paypal::Express::Response
495
+ end
496
+
497
+ it 'should call CreateBillingAgreement' do
498
+ expect do
499
+ instance.agree! 'token'
500
+ end.to request_to nvp_endpoint, :post
501
+ instance._method_.should == :CreateBillingAgreement
502
+ instance._sent_params_.should == {
503
+ :TOKEN => 'token'
504
+ }
505
+ end
506
+ end
507
+
508
+ describe '#agreement' do
509
+ it 'should return Paypal::Express::Response' do
510
+ fake_response 'BillAgreementUpdate/fetch'
511
+ response = instance.agreement 'reference_id'
512
+ response.should be_instance_of Paypal::Express::Response
513
+ end
514
+
515
+ it 'should call BillAgreementUpdate' do
516
+ expect do
517
+ instance.agreement 'reference_id'
518
+ end.to request_to nvp_endpoint, :post
519
+ instance._method_.should == :BillAgreementUpdate
520
+ instance._sent_params_.should == {
521
+ :REFERENCEID => 'reference_id'
522
+ }
523
+ end
524
+ end
525
+
526
+ describe '#charge!' do
527
+ it 'should return Paypal::Express::Response' do
528
+ fake_response 'DoReferenceTransaction/success'
529
+ response = instance.charge! 'billing_agreement_id', 1000
530
+ response.should be_instance_of Paypal::Express::Response
531
+ end
532
+
533
+ it 'should call DoReferenceTransaction' do
534
+ expect do
535
+ instance.charge! 'billing_agreement_id', 1000, :currency_code => :JPY
536
+ end.to request_to nvp_endpoint, :post
537
+ instance._method_.should == :DoReferenceTransaction
538
+ instance._sent_params_.should == {
539
+ :REFERENCEID => 'billing_agreement_id',
540
+ :AMT => '1000.00',
541
+ :PAYMENTACTION => :Sale,
542
+ :CURRENCYCODE => :JPY
543
+ }
544
+ end
545
+ end
546
+
547
+ describe '#revoke!' do
548
+ it 'should return Paypal::Express::Response' do
549
+ fake_response 'BillAgreementUpdate/revoke'
550
+ response = instance.revoke! 'reference_id'
551
+ response.should be_instance_of Paypal::Express::Response
552
+ end
553
+
554
+ it 'should call BillAgreementUpdate' do
555
+ expect do
556
+ instance.revoke! 'reference_id'
557
+ end.to request_to nvp_endpoint, :post
558
+ instance._method_.should == :BillAgreementUpdate
559
+ instance._sent_params_.should == {
560
+ :REFERENCEID => 'reference_id',
561
+ :BillingAgreementStatus => :Canceled
562
+ }
563
+ end
564
+ end
565
+
566
+ describe '#refund!' do
567
+ it 'should return Paypal::Express::Response' do
568
+ fake_response 'RefundTransaction/full'
569
+ response = instance.refund! 'transaction_id'
570
+ response.should be_instance_of Paypal::Express::Response
571
+ end
572
+
573
+ it 'should call RefundTransaction' do
574
+ expect do
575
+ instance.refund! 'transaction_id'
576
+ end.to request_to nvp_endpoint, :post
577
+ instance._method_.should == :RefundTransaction
578
+ instance._sent_params_.should == {
579
+ :TRANSACTIONID => 'transaction_id',
580
+ :REFUNDTYPE => :Full
581
+ }
582
+ end
583
+ end
584
+ end