dfg-paypal 0.8.2

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.
Files changed (84) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/.gitignore +25 -0
  4. data/.rspec +2 -0
  5. data/.travis.yml +18 -0
  6. data/Gemfile +13 -0
  7. data/Rakefile +19 -0
  8. data/VERSION +1 -0
  9. data/dfg-paypal.gemspec +28 -0
  10. data/lib/paypal.rb +84 -0
  11. data/lib/paypal/base.rb +19 -0
  12. data/lib/paypal/exception.rb +4 -0
  13. data/lib/paypal/exception/api_error.rb +94 -0
  14. data/lib/paypal/exception/http_error.rb +12 -0
  15. data/lib/paypal/express.rb +1 -0
  16. data/lib/paypal/express/request.rb +207 -0
  17. data/lib/paypal/express/response.rb +35 -0
  18. data/lib/paypal/ipn.rb +23 -0
  19. data/lib/paypal/nvp/request.rb +64 -0
  20. data/lib/paypal/nvp/response.rb +234 -0
  21. data/lib/paypal/payment/common/amount.rb +13 -0
  22. data/lib/paypal/payment/recurring.rb +43 -0
  23. data/lib/paypal/payment/recurring/activation.rb +14 -0
  24. data/lib/paypal/payment/recurring/billing.rb +39 -0
  25. data/lib/paypal/payment/recurring/summary.rb +11 -0
  26. data/lib/paypal/payment/request.rb +67 -0
  27. data/lib/paypal/payment/request/item.rb +26 -0
  28. data/lib/paypal/payment/response.rb +73 -0
  29. data/lib/paypal/payment/response/address.rb +7 -0
  30. data/lib/paypal/payment/response/info.rb +45 -0
  31. data/lib/paypal/payment/response/item.rb +41 -0
  32. data/lib/paypal/payment/response/payer.rb +7 -0
  33. data/lib/paypal/payment/response/reference.rb +9 -0
  34. data/lib/paypal/payment/response/refund.rb +13 -0
  35. data/lib/paypal/util.rb +28 -0
  36. data/spec/fake_response/BillAgreementUpdate/fetch.txt +1 -0
  37. data/spec/fake_response/BillAgreementUpdate/revoke.txt +1 -0
  38. data/spec/fake_response/CreateBillingAgreement/success.txt +1 -0
  39. data/spec/fake_response/CreateRecurringPaymentsProfile/failure.txt +1 -0
  40. data/spec/fake_response/CreateRecurringPaymentsProfile/success.txt +1 -0
  41. data/spec/fake_response/DoCapture/failure.txt +1 -0
  42. data/spec/fake_response/DoCapture/success.txt +1 -0
  43. data/spec/fake_response/DoExpressCheckoutPayment/failure.txt +1 -0
  44. data/spec/fake_response/DoExpressCheckoutPayment/success.txt +1 -0
  45. data/spec/fake_response/DoExpressCheckoutPayment/success_with_billing_agreement.txt +1 -0
  46. data/spec/fake_response/DoExpressCheckoutPayment/success_with_many_items.txt +1 -0
  47. data/spec/fake_response/DoReferenceTransaction/failure.txt +1 -0
  48. data/spec/fake_response/DoReferenceTransaction/success.txt +1 -0
  49. data/spec/fake_response/DoVoid/success.txt +1 -0
  50. data/spec/fake_response/GetExpressCheckoutDetails/failure.txt +1 -0
  51. data/spec/fake_response/GetExpressCheckoutDetails/success.txt +1 -0
  52. data/spec/fake_response/GetExpressCheckoutDetails/with_billing_accepted_status.txt +1 -0
  53. data/spec/fake_response/GetRecurringPaymentsProfileDetails/failure.txt +1 -0
  54. data/spec/fake_response/GetRecurringPaymentsProfileDetails/success.txt +1 -0
  55. data/spec/fake_response/GetTransactionDetails/failure.txt +1 -0
  56. data/spec/fake_response/GetTransactionDetails/success.txt +1 -0
  57. data/spec/fake_response/IPN/invalid.txt +1 -0
  58. data/spec/fake_response/IPN/valid.txt +1 -0
  59. data/spec/fake_response/ManageRecurringPaymentsProfileStatus/failure.txt +1 -0
  60. data/spec/fake_response/ManageRecurringPaymentsProfileStatus/success.txt +1 -0
  61. data/spec/fake_response/RefundTransaction/full.txt +1 -0
  62. data/spec/fake_response/SetExpressCheckout/failure.txt +1 -0
  63. data/spec/fake_response/SetExpressCheckout/success.txt +1 -0
  64. data/spec/helpers/fake_response_helper.rb +33 -0
  65. data/spec/paypal/exception/api_error_spec.rb +78 -0
  66. data/spec/paypal/exception/http_error_spec.rb +8 -0
  67. data/spec/paypal/express/request_spec.rb +602 -0
  68. data/spec/paypal/express/response_spec.rb +80 -0
  69. data/spec/paypal/ipn_spec.rb +19 -0
  70. data/spec/paypal/nvp/request_spec.rb +116 -0
  71. data/spec/paypal/nvp/response_spec.rb +146 -0
  72. data/spec/paypal/payment/common/amount_spec.rb +36 -0
  73. data/spec/paypal/payment/recurring/activation_spec.rb +19 -0
  74. data/spec/paypal/payment/recurring_spec.rb +170 -0
  75. data/spec/paypal/payment/request/item_spec.rb +27 -0
  76. data/spec/paypal/payment/request_spec.rb +136 -0
  77. data/spec/paypal/payment/response/address_spec.rb +26 -0
  78. data/spec/paypal/payment/response/info_spec.rb +93 -0
  79. data/spec/paypal/payment/response/item_spec.rb +42 -0
  80. data/spec/paypal/payment/response/payer_spec.rb +26 -0
  81. data/spec/paypal/payment/response_spec.rb +16 -0
  82. data/spec/paypal/util_spec.rb +32 -0
  83. data/spec/spec_helper.rb +25 -0
  84. metadata +225 -0
@@ -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,602 @@
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
+ :version => Paypal.api_version
127
+ }
128
+ end
129
+
130
+ it 'should support allow_note=false option' do
131
+ expect do
132
+ instance.setup instant_payment_request, return_url, cancel_url, :allow_note => false
133
+ end.to request_to nvp_endpoint, :post
134
+ instance._method_.should == :SetExpressCheckout
135
+ instance._sent_params_.should == {
136
+ :PAYMENTREQUEST_0_DESC => 'Instant Payment Request',
137
+ :RETURNURL => return_url,
138
+ :CANCELURL => cancel_url,
139
+ :PAYMENTREQUEST_0_AMT => '1000.00',
140
+ :PAYMENTREQUEST_0_TAXAMT => "0.00",
141
+ :PAYMENTREQUEST_0_SHIPPINGAMT => "0.00",
142
+ :ALLOWNOTE => 0,
143
+ :version => Paypal.api_version
144
+ }
145
+ end
146
+
147
+ {
148
+ :solution_type => :SOLUTIONTYPE,
149
+ :landing_page => :LANDINGPAGE,
150
+ :email => :EMAIL,
151
+ :brand => :BRANDNAME,
152
+ :locale => :LOCALECODE,
153
+ :logo => :LOGOIMG,
154
+ :cart_border_color => :CARTBORDERCOLOR,
155
+ :payflow_color => :PAYFLOWCOLOR
156
+ }.each do |option_key, param_key|
157
+ it "should support #{option_key} option" do
158
+ expect do
159
+ instance.setup instant_payment_request, return_url, cancel_url, option_key => 'some value'
160
+ end.to request_to nvp_endpoint, :post
161
+ instance._method_.should == :SetExpressCheckout
162
+ instance._sent_params_.should include param_key
163
+ instance._sent_params_[param_key].should == 'some value'
164
+ end
165
+ end
166
+
167
+ context 'when instance payment request given' do
168
+ it 'should call SetExpressCheckout' do
169
+ expect do
170
+ instance.setup instant_payment_request, return_url, cancel_url
171
+ end.to request_to nvp_endpoint, :post
172
+ instance._method_.should == :SetExpressCheckout
173
+ instance._sent_params_.should == {
174
+ :PAYMENTREQUEST_0_DESC => 'Instant Payment Request',
175
+ :RETURNURL => return_url,
176
+ :CANCELURL => cancel_url,
177
+ :PAYMENTREQUEST_0_AMT => '1000.00',
178
+ :PAYMENTREQUEST_0_TAXAMT => "0.00",
179
+ :PAYMENTREQUEST_0_SHIPPINGAMT => "0.00",
180
+ :version => Paypal.api_version
181
+ }
182
+ end
183
+ end
184
+
185
+ context 'when recurring payment request given' do
186
+ it 'should call SetExpressCheckout' do
187
+ expect do
188
+ instance.setup recurring_payment_request, return_url, cancel_url
189
+ end.to request_to nvp_endpoint, :post
190
+ instance._method_.should == :SetExpressCheckout
191
+ instance._sent_params_.should == {
192
+ :L_BILLINGTYPE0 => :RecurringPayments,
193
+ :L_BILLINGAGREEMENTDESCRIPTION0 => 'Recurring Payment Request',
194
+ :RETURNURL => return_url,
195
+ :CANCELURL => cancel_url,
196
+ :PAYMENTREQUEST_0_AMT => '0.00',
197
+ :PAYMENTREQUEST_0_TAXAMT => "0.00",
198
+ :PAYMENTREQUEST_0_SHIPPINGAMT => "0.00",
199
+ :version => Paypal.api_version
200
+ }
201
+ end
202
+ end
203
+
204
+ context 'when reference transaction request given' do
205
+ it 'should call SetExpressCheckout' do
206
+ expect do
207
+ instance.setup reference_transaction_request, return_url, cancel_url
208
+ end.to request_to nvp_endpoint, :post
209
+ instance._method_.should == :SetExpressCheckout
210
+ instance._sent_params_.should == {
211
+ :L_BILLINGTYPE0 => :MerchantInitiatedBilling,
212
+ :L_BILLINGAGREEMENTDESCRIPTION0 => 'Billing Agreement Request',
213
+ :RETURNURL => return_url,
214
+ :CANCELURL => cancel_url,
215
+ :PAYMENTREQUEST_0_AMT => '0.00',
216
+ :PAYMENTREQUEST_0_TAXAMT => "0.00",
217
+ :PAYMENTREQUEST_0_SHIPPINGAMT => "0.00",
218
+ :version => Paypal.api_version
219
+ }
220
+ end
221
+ end
222
+ end
223
+
224
+ describe '#details' do
225
+ it 'should return Paypal::Express::Response' do
226
+ fake_response 'GetExpressCheckoutDetails/success'
227
+ response = instance.details 'token'
228
+ response.should be_instance_of Paypal::Express::Response
229
+ end
230
+
231
+ it 'should call GetExpressCheckoutDetails' do
232
+ expect do
233
+ instance.details 'token'
234
+ end.to request_to nvp_endpoint, :post
235
+ instance._method_.should == :GetExpressCheckoutDetails
236
+ instance._sent_params_.should == {
237
+ :TOKEN => 'token',
238
+ :version => Paypal.api_version
239
+ }
240
+ end
241
+ end
242
+
243
+ describe '#transaction_details' do
244
+ it 'should return Paypal::Express::Response' do
245
+ fake_response 'GetTransactionDetails/success'
246
+ response = instance.transaction_details 'transaction_id'
247
+ response.should be_instance_of Paypal::Express::Response
248
+ end
249
+
250
+ it 'should call GetTransactionDetails' do
251
+ expect do
252
+ instance.transaction_details 'transaction_id'
253
+ end.to request_to nvp_endpoint, :post
254
+ instance._method_.should == :GetTransactionDetails
255
+ instance._sent_params_.should == {
256
+ :TRANSACTIONID=> 'transaction_id'
257
+ }
258
+ end
259
+
260
+ it 'should fail with bad transaction id' do
261
+ expect do
262
+ fake_response 'GetTransactionDetails/failure'
263
+ response = instance.transaction_details 'bad_transaction_id'
264
+ end.to raise_error(Paypal::Exception::APIError)
265
+ end
266
+
267
+ it 'should handle all attributes' do
268
+ Paypal.logger.should_not_receive(:warn)
269
+ fake_response 'GetTransactionDetails/success'
270
+ response = instance.transaction_details 'transaction_id'
271
+ end
272
+ end
273
+
274
+ describe "#capture!" do
275
+ it 'should return Paypal::Express::Response' do
276
+ fake_response 'DoCapture/success'
277
+ response = instance.capture! 'authorization_id', 181.98, :BRL
278
+ response.should be_instance_of Paypal::Express::Response
279
+ end
280
+
281
+ it 'should call DoExpressCheckoutPayment' do
282
+ expect do
283
+ instance.capture! 'authorization_id', 181.98, :BRL
284
+ end.to request_to nvp_endpoint, :post
285
+
286
+ instance._method_.should == :DoCapture
287
+ instance._sent_params_.should == {
288
+ :AUTHORIZATIONID => 'authorization_id',
289
+ :COMPLETETYPE => 'Complete',
290
+ :AMT => 181.98,
291
+ :CURRENCYCODE => :BRL
292
+ }
293
+ end
294
+
295
+ it 'should call DoExpressCheckoutPayment with NotComplete capture parameter' do
296
+ expect do
297
+ instance.capture! 'authorization_id', 181.98, :BRL, 'NotComplete'
298
+ end.to request_to nvp_endpoint, :post
299
+
300
+ instance._method_.should == :DoCapture
301
+ instance._sent_params_.should == {
302
+ :AUTHORIZATIONID => 'authorization_id',
303
+ :COMPLETETYPE => 'NotComplete',
304
+ :AMT => 181.98,
305
+ :CURRENCYCODE => :BRL
306
+ }
307
+ end
308
+ end
309
+
310
+ describe "#void!" do
311
+ it 'should return Paypal::Express::Response' do
312
+ fake_response 'DoVoid/success'
313
+ response = instance.void! 'authorization_id', note: "note"
314
+ response.should be_instance_of Paypal::Express::Response
315
+ end
316
+
317
+ it 'should call DoVoid' do
318
+ expect do
319
+ instance.void! 'authorization_id', note: "note"
320
+ end.to request_to nvp_endpoint, :post
321
+
322
+ instance._method_.should == :DoVoid
323
+ instance._sent_params_.should == {
324
+ :AUTHORIZATIONID => 'authorization_id',
325
+ :NOTE => "note"
326
+ }
327
+ end
328
+ end
329
+
330
+ describe '#checkout!' do
331
+ it 'should return Paypal::Express::Response' do
332
+ fake_response 'DoExpressCheckoutPayment/success'
333
+ response = instance.checkout! 'token', 'payer_id', instant_payment_request
334
+ response.should be_instance_of Paypal::Express::Response
335
+ end
336
+
337
+ it 'should call DoExpressCheckoutPayment' do
338
+ expect do
339
+ instance.checkout! 'token', 'payer_id', instant_payment_request
340
+ end.to request_to nvp_endpoint, :post
341
+ instance._method_.should == :DoExpressCheckoutPayment
342
+ instance._sent_params_.should == {
343
+ :PAYERID => 'payer_id',
344
+ :TOKEN => 'token',
345
+ :PAYMENTREQUEST_0_DESC => 'Instant Payment Request',
346
+ :PAYMENTREQUEST_0_AMT => '1000.00',
347
+ :PAYMENTREQUEST_0_TAXAMT => "0.00",
348
+ :PAYMENTREQUEST_0_SHIPPINGAMT => "0.00",
349
+ :version => Paypal.api_version
350
+ }
351
+ end
352
+
353
+ context "with many items" do
354
+ before do
355
+ fake_response 'DoExpressCheckoutPayment/success_with_many_items'
356
+ end
357
+
358
+ it 'should handle all attributes' do
359
+ Paypal.logger.should_not_receive(:warn)
360
+ response = instance.checkout! 'token', 'payer_id', instant_payment_request_with_many_items
361
+ end
362
+
363
+ it 'should return Paypal::Express::Response' do
364
+ response = instance.checkout! 'token', 'payer_id', instant_payment_request_with_many_items
365
+ response.should be_instance_of Paypal::Express::Response
366
+ end
367
+
368
+ it 'should return twenty items' do
369
+ response = instance.checkout! 'token', 'payer_id', instant_payment_request_with_many_items
370
+ instance._method_.should == :DoExpressCheckoutPayment
371
+ response.items.count.should == 20
372
+ end
373
+ end
374
+ end
375
+
376
+ describe '#subscribe!' do
377
+ it 'should return Paypal::Express::Response' do
378
+ fake_response 'CreateRecurringPaymentsProfile/success'
379
+ response = instance.subscribe! 'token', recurring_profile
380
+ response.should be_instance_of Paypal::Express::Response
381
+ end
382
+
383
+ it 'should call CreateRecurringPaymentsProfile' do
384
+ expect do
385
+ instance.subscribe! 'token', recurring_profile
386
+ end.to request_to nvp_endpoint, :post
387
+ instance._method_.should == :CreateRecurringPaymentsProfile
388
+ instance._sent_params_.should == {
389
+ :DESC => 'Recurring Profile',
390
+ :TOKEN => 'token',
391
+ :SHIPPINGAMT => '0.00',
392
+ :AMT => '1000.00',
393
+ :BILLINGFREQUENCY => 1,
394
+ :MAXFAILEDPAYMENTS => 0,
395
+ :BILLINGPERIOD => :Month,
396
+ :TAXAMT => '0.00',
397
+ :PROFILESTARTDATE => '2011-02-08 09:00:00',
398
+ :TOTALBILLINGCYCLES => 0,
399
+ :version => Paypal.api_version
400
+ }
401
+ end
402
+ end
403
+
404
+ describe '#subscription' do
405
+ it 'should return Paypal::Express::Response' do
406
+ fake_response 'GetRecurringPaymentsProfileDetails/success'
407
+ response = instance.subscription 'profile_id'
408
+ response.should be_instance_of(Paypal::Express::Response)
409
+ end
410
+
411
+ it 'should call GetRecurringPaymentsProfileDetails' do
412
+ expect do
413
+ instance.subscription 'profile_id'
414
+ end.to request_to nvp_endpoint, :post
415
+ instance._method_.should == :GetRecurringPaymentsProfileDetails
416
+ instance._sent_params_.should == {
417
+ :PROFILEID => 'profile_id',
418
+ :version => Paypal.api_version
419
+ }
420
+ end
421
+ end
422
+
423
+ describe '#renew!' do
424
+ it 'should return Paypal::Express::Response' do
425
+ fake_response 'ManageRecurringPaymentsProfileStatus/success'
426
+ response = instance.renew! 'profile_id', :Cancel
427
+ response.should be_instance_of Paypal::Express::Response
428
+ end
429
+
430
+ it 'should call ManageRecurringPaymentsProfileStatus' do
431
+ expect do
432
+ instance.renew! 'profile_id', :Cancel
433
+ end.to request_to nvp_endpoint, :post
434
+ instance._method_.should == :ManageRecurringPaymentsProfileStatus
435
+ instance._sent_params_.should == {
436
+ :ACTION => :Cancel,
437
+ :PROFILEID => 'profile_id',
438
+ :version => Paypal.api_version
439
+ }
440
+ end
441
+ end
442
+
443
+ describe '#cancel!' do
444
+ it 'should return Paypal::Express::Response' do
445
+ fake_response 'ManageRecurringPaymentsProfileStatus/success'
446
+ response = instance.cancel! 'profile_id'
447
+ response.should be_instance_of(Paypal::Express::Response)
448
+ end
449
+
450
+ it 'should call ManageRecurringPaymentsProfileStatus' do
451
+ expect do
452
+ instance.cancel! 'profile_id'
453
+ end.to request_to nvp_endpoint, :post
454
+ instance._method_.should == :ManageRecurringPaymentsProfileStatus
455
+ instance._sent_params_.should == {
456
+ :ACTION => :Cancel,
457
+ :PROFILEID => 'profile_id',
458
+ :version => Paypal.api_version
459
+ }
460
+ end
461
+ end
462
+
463
+ describe '#suspend!' do
464
+ it 'should return Paypal::Express::Response' do
465
+ fake_response 'ManageRecurringPaymentsProfileStatus/success'
466
+ response = instance.cancel! 'profile_id'
467
+ response.should be_instance_of Paypal::Express::Response
468
+ end
469
+
470
+ it 'should call ManageRecurringPaymentsProfileStatus' do
471
+ expect do
472
+ instance.suspend! 'profile_id'
473
+ end.to request_to nvp_endpoint, :post
474
+ instance._method_.should == :ManageRecurringPaymentsProfileStatus
475
+ instance._sent_params_.should == {
476
+ :ACTION => :Suspend,
477
+ :PROFILEID => 'profile_id',
478
+ :version => Paypal.api_version
479
+ }
480
+ end
481
+ end
482
+
483
+ describe '#reactivate!' do
484
+ it 'should return Paypal::Express::Response' do
485
+ fake_response 'ManageRecurringPaymentsProfileStatus/success'
486
+ response = instance.cancel! 'profile_id'
487
+ response.should be_instance_of Paypal::Express::Response
488
+ end
489
+
490
+ it 'should call ManageRecurringPaymentsProfileStatus' do
491
+ expect do
492
+ instance.reactivate! 'profile_id'
493
+ end.to request_to nvp_endpoint, :post
494
+ instance._method_.should == :ManageRecurringPaymentsProfileStatus
495
+ instance._sent_params_.should == {
496
+ :ACTION => :Reactivate,
497
+ :PROFILEID => 'profile_id',
498
+ :version => Paypal.api_version
499
+ }
500
+ end
501
+ end
502
+
503
+ describe '#agree!' do
504
+ it 'should return Paypal::Express::Response' do
505
+ fake_response 'CreateBillingAgreement/success'
506
+ response = instance.agree! 'token'
507
+ response.should be_instance_of Paypal::Express::Response
508
+ end
509
+
510
+ it 'should call CreateBillingAgreement' do
511
+ expect do
512
+ instance.agree! 'token'
513
+ end.to request_to nvp_endpoint, :post
514
+ instance._method_.should == :CreateBillingAgreement
515
+ instance._sent_params_.should == {
516
+ :TOKEN => 'token',
517
+ :version => Paypal.api_version
518
+ }
519
+ end
520
+ end
521
+
522
+ describe '#agreement' do
523
+ it 'should return Paypal::Express::Response' do
524
+ fake_response 'BillAgreementUpdate/fetch'
525
+ response = instance.agreement 'reference_id'
526
+ response.should be_instance_of Paypal::Express::Response
527
+ end
528
+
529
+ it 'should call BillAgreementUpdate' do
530
+ expect do
531
+ instance.agreement 'reference_id'
532
+ end.to request_to nvp_endpoint, :post
533
+ instance._method_.should == :BillAgreementUpdate
534
+ instance._sent_params_.should == {
535
+ :REFERENCEID => 'reference_id',
536
+ :version => Paypal.api_version
537
+ }
538
+ end
539
+ end
540
+
541
+ describe '#charge!' do
542
+ it 'should return Paypal::Express::Response' do
543
+ fake_response 'DoReferenceTransaction/success'
544
+ response = instance.charge! 'billing_agreement_id', 1000
545
+ response.should be_instance_of Paypal::Express::Response
546
+ end
547
+
548
+ it 'should call DoReferenceTransaction' do
549
+ expect do
550
+ instance.charge! 'billing_agreement_id', 1000, :currency_code => :JPY
551
+ end.to request_to nvp_endpoint, :post
552
+ instance._method_.should == :DoReferenceTransaction
553
+ instance._sent_params_.should == {
554
+ :REFERENCEID => 'billing_agreement_id',
555
+ :AMT => '1000.00',
556
+ :PAYMENTACTION => :Sale,
557
+ :CURRENCYCODE => :JPY,
558
+ :version => Paypal.api_version
559
+ }
560
+ end
561
+ end
562
+
563
+ describe '#revoke!' do
564
+ it 'should return Paypal::Express::Response' do
565
+ fake_response 'BillAgreementUpdate/revoke'
566
+ response = instance.revoke! 'reference_id'
567
+ response.should be_instance_of Paypal::Express::Response
568
+ end
569
+
570
+ it 'should call BillAgreementUpdate' do
571
+ expect do
572
+ instance.revoke! 'reference_id'
573
+ end.to request_to nvp_endpoint, :post
574
+ instance._method_.should == :BillAgreementUpdate
575
+ instance._sent_params_.should == {
576
+ :REFERENCEID => 'reference_id',
577
+ :BillingAgreementStatus => :Canceled,
578
+ :version => Paypal.api_version
579
+ }
580
+ end
581
+ end
582
+
583
+ describe '#refund!' do
584
+ it 'should return Paypal::Express::Response' do
585
+ fake_response 'RefundTransaction/full'
586
+ response = instance.refund! 'transaction_id'
587
+ response.should be_instance_of Paypal::Express::Response
588
+ end
589
+
590
+ it 'should call RefundTransaction' do
591
+ expect do
592
+ instance.refund! 'transaction_id'
593
+ end.to request_to nvp_endpoint, :post
594
+ instance._method_.should == :RefundTransaction
595
+ instance._sent_params_.should == {
596
+ :TRANSACTIONID => 'transaction_id',
597
+ :REFUNDTYPE => :Full,
598
+ :version => Paypal.api_version
599
+ }
600
+ end
601
+ end
602
+ end