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,80 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Paypal::Express::Response do
4
+ before { fake_response 'SetExpressCheckout/success' }
5
+
6
+ let(:return_url) { 'http://example.com/success' }
7
+ let(:cancel_url) { 'http://example.com/cancel' }
8
+ let :request do
9
+ Paypal::Express::Request.new(
10
+ :username => 'nov',
11
+ :password => 'password',
12
+ :signature => 'sig'
13
+ )
14
+ end
15
+ let :payment_request do
16
+ Paypal::Payment::Request.new(
17
+ :billing_type => :RecurringPayments,
18
+ :billing_agreement_description => 'Recurring Payment Request'
19
+ )
20
+ end
21
+ let(:response) { request.setup payment_request, return_url, cancel_url }
22
+
23
+ describe '#redirect_uri' do
24
+ subject { response.redirect_uri }
25
+ it { should include 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' }
26
+ end
27
+
28
+ describe '#popup_uri' do
29
+ subject { response.popup_uri }
30
+ it { should include 'https://www.paypal.com/incontext?token=' }
31
+ end
32
+
33
+ context 'when pay_on_paypal option is given' do
34
+ let(:response) { request.setup payment_request, return_url, cancel_url, :pay_on_paypal => true }
35
+
36
+ subject { response }
37
+ its(:pay_on_paypal) { should be_true }
38
+ its(:query) { should include(:useraction => 'commit') }
39
+
40
+ describe '#redirect_uri' do
41
+ subject { response.redirect_uri }
42
+ it { should include 'useraction=commit' }
43
+ end
44
+
45
+ describe '#popup_uri' do
46
+ subject { response.popup_uri }
47
+ it { should include 'useraction=commit' }
48
+ end
49
+ end
50
+
51
+ context 'when sandbox mode' do
52
+ before do
53
+ Paypal.sandbox!
54
+ fake_response 'SetExpressCheckout/success'
55
+ end
56
+ after { Paypal.sandbox = false }
57
+
58
+ describe '#redirect_uri' do
59
+ subject { response.redirect_uri }
60
+ it { should include 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=' }
61
+ end
62
+
63
+ describe '#popup_uri' do
64
+ subject { response.popup_uri }
65
+ it { should include 'https://www.sandbox.paypal.com/incontext?token=' }
66
+ end
67
+ end
68
+
69
+ context 'when mobile option is given' do
70
+ let(:response) { request.setup payment_request, return_url, cancel_url, :mobile => true }
71
+
72
+ subject { response }
73
+
74
+ describe '#redirect_uri' do
75
+ subject { response.redirect_uri }
76
+ it { should include 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout-mobile&token=' }
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Paypal::IPN do
4
+ describe '.verify!' do
5
+ context 'when valid' do
6
+ before { fake_response 'IPN/valid', :IPN }
7
+ subject { Paypal::IPN.verify!('raw-post-body') }
8
+ it { should be_true }
9
+ end
10
+
11
+ context 'when invalid' do
12
+ before { fake_response 'IPN/invalid', :IPN }
13
+ subject {}
14
+ it do
15
+ expect { Paypal::IPN.verify!('raw-post-body') }.to raise_error(Paypal::Exception::APIError)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,116 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Paypal::NVP::Request do
4
+ let :attributes do
5
+ {
6
+ :username => 'nov',
7
+ :password => 'password',
8
+ :signature => 'sig'
9
+ }
10
+ end
11
+
12
+ let :instance do
13
+ Paypal::NVP::Request.new attributes
14
+ end
15
+
16
+ describe '.new' do
17
+ context 'when any required parameters are missing' do
18
+ it 'should raise AttrRequired::AttrMissing' do
19
+ attributes.keys.each do |missing_key|
20
+ insufficient_attributes = attributes.reject do |key, value|
21
+ key == missing_key
22
+ end
23
+ expect do
24
+ Paypal::NVP::Request.new insufficient_attributes
25
+ end.to raise_error AttrRequired::AttrMissing
26
+ end
27
+ end
28
+ end
29
+
30
+ context 'when all required parameters are given' do
31
+ it 'should succeed' do
32
+ expect do
33
+ Paypal::NVP::Request.new attributes
34
+ end.not_to raise_error AttrRequired::AttrMissing
35
+ end
36
+
37
+ it 'should setup endpoint and version' do
38
+ client = Paypal::NVP::Request.new attributes
39
+ client.class.endpoint.should == Paypal::NVP::Request::ENDPOINT[:production]
40
+ end
41
+
42
+ it 'should support sandbox mode' do
43
+ sandbox_mode do
44
+ client = Paypal::NVP::Request.new attributes
45
+ client.class.endpoint.should == Paypal::NVP::Request::ENDPOINT[:sandbox]
46
+ end
47
+ end
48
+ end
49
+
50
+ context 'when optional parameters are given' do
51
+ let(:optional_attributes) do
52
+ { :subject => 'user@example.com' }
53
+ end
54
+
55
+ it 'should setup subject' do
56
+ client = Paypal::NVP::Request.new attributes.merge(optional_attributes)
57
+ client.subject.should == 'user@example.com'
58
+ end
59
+ end
60
+ end
61
+
62
+ describe '#common_params' do
63
+ {
64
+ :username => :USER,
65
+ :password => :PWD,
66
+ :signature => :SIGNATURE,
67
+ :subject => :SUBJECT,
68
+ :version => :VERSION
69
+ }.each do |option_key, param_key|
70
+ it "should include :#{param_key}" do
71
+ instance.common_params.should include(param_key)
72
+ end
73
+
74
+ it "should set :#{param_key} as #{option_key}" do
75
+ instance.common_params[param_key].should == instance.send(option_key)
76
+ end
77
+ end
78
+ end
79
+
80
+ describe '#request' do
81
+ it 'should POST to NPV endpoint' do
82
+ expect do
83
+ instance.request :RPCMethod
84
+ end.to request_to Paypal::NVP::Request::ENDPOINT[:production], :post
85
+ end
86
+
87
+ context 'when got API error response' do
88
+ before do
89
+ fake_response 'SetExpressCheckout/failure'
90
+ end
91
+
92
+ it 'should raise Paypal::Exception::APIError' do
93
+ expect do
94
+ instance.request :SetExpressCheckout
95
+ end.to raise_error(Paypal::Exception::APIError)
96
+ end
97
+ end
98
+
99
+ context 'when got HTTP error response' do
100
+ before do
101
+ FakeWeb.register_uri(
102
+ :post,
103
+ Paypal::NVP::Request::ENDPOINT[:production],
104
+ :body => "Invalid Request",
105
+ :status => ["400", "Bad Request"]
106
+ )
107
+ end
108
+
109
+ it 'should raise Paypal::Exception::HttpError' do
110
+ expect do
111
+ instance.request :SetExpressCheckout
112
+ end.to raise_error(Paypal::Exception::HttpError)
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,146 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Paypal::NVP::Response do
4
+ let(:return_url) { 'http://example.com/success' }
5
+ let(:cancel_url) { 'http://example.com/cancel' }
6
+ let :request do
7
+ Paypal::Express::Request.new(
8
+ :username => 'nov',
9
+ :password => 'password',
10
+ :signature => 'sig'
11
+ )
12
+ end
13
+
14
+ let :payment_request do
15
+ Paypal::Payment::Request.new(
16
+ :amount => 1000,
17
+ :description => 'Instant Payment Request'
18
+ )
19
+ end
20
+
21
+ let :recurring_profile do
22
+ Paypal::Payment::Recurring.new(
23
+ :start_date => Time.utc(2011, 2, 8, 9, 0, 0),
24
+ :description => 'Recurring Profile',
25
+ :billing => {
26
+ :period => :Month,
27
+ :frequency => 1,
28
+ :amount => 1000
29
+ }
30
+ )
31
+ end
32
+
33
+ describe '.new' do
34
+ context 'when non-supported attributes are given' do
35
+ it 'should ignore them and warn' do
36
+ Paypal.logger.should_receive(:warn).with(
37
+ "Ignored Parameter (Paypal::NVP::Response): ignored=Ignore me!"
38
+ )
39
+ Paypal::NVP::Response.new(
40
+ :ignored => 'Ignore me!'
41
+ )
42
+ end
43
+ end
44
+
45
+ context 'when SetExpressCheckout response given' do
46
+ before do
47
+ fake_response 'SetExpressCheckout/success'
48
+ end
49
+
50
+ it 'should handle all attributes' do
51
+ Paypal.logger.should_not_receive(:warn)
52
+ response = request.setup payment_request, return_url, cancel_url
53
+ response.token.should == 'EC-5YJ90598G69065317'
54
+ end
55
+ end
56
+
57
+ context 'when GetExpressCheckoutDetails response given' do
58
+ before do
59
+ fake_response 'GetExpressCheckoutDetails/success'
60
+ end
61
+
62
+ it 'should handle all attributes' do
63
+ Paypal.logger.should_not_receive(:warn)
64
+ response = request.details 'token'
65
+ response.payer.identifier.should == '9RWDTMRKKHQ8S'
66
+ response.payment_responses.size.should == 1
67
+ response.payment_info.size.should == 0
68
+ response.payment_responses.first.should be_instance_of(Paypal::Payment::Response)
69
+ end
70
+
71
+ context 'when BILLINGAGREEMENTACCEPTEDSTATUS included' do
72
+ before do
73
+ fake_response 'GetExpressCheckoutDetails/with_billing_accepted_status'
74
+ end
75
+
76
+ it 'should handle all attributes' do
77
+ Paypal.logger.should_not_receive(:warn)
78
+ response = request.details 'token'
79
+ end
80
+ end
81
+ end
82
+
83
+ context 'when DoExpressCheckoutPayment response given' do
84
+ before do
85
+ fake_response 'DoExpressCheckoutPayment/success'
86
+ end
87
+
88
+ it 'should handle all attributes' do
89
+ Paypal.logger.should_not_receive(:warn)
90
+ response = request.checkout! 'token', 'payer_id', payment_request
91
+ response.payment_responses.size.should == 0
92
+ response.payment_info.size.should == 1
93
+ response.payment_info.first.should be_instance_of(Paypal::Payment::Response::Info)
94
+ end
95
+
96
+ context 'when billing_agreement is included' do
97
+ before do
98
+ fake_response 'DoExpressCheckoutPayment/success_with_billing_agreement'
99
+ end
100
+
101
+ it 'should have billing_agreement' do
102
+ Paypal.logger.should_not_receive(:warn)
103
+ response = request.checkout! 'token', 'payer_id', payment_request
104
+ response.billing_agreement.identifier.should == 'B-1XR87946TC504770W'
105
+ end
106
+ end
107
+ end
108
+
109
+ context 'when CreateRecurringPaymentsProfile response given' do
110
+ before do
111
+ fake_response 'CreateRecurringPaymentsProfile/success'
112
+ end
113
+
114
+ it 'should handle all attributes' do
115
+ Paypal.logger.should_not_receive(:warn)
116
+ response = request.subscribe! 'token', recurring_profile
117
+ response.recurring.identifier.should == 'I-L8N58XFUCET3'
118
+ end
119
+ end
120
+
121
+ context 'when GetRecurringPaymentsProfileDetails response given' do
122
+ before do
123
+ fake_response 'GetRecurringPaymentsProfileDetails/success'
124
+ end
125
+
126
+ it 'should handle all attributes' do
127
+ Paypal.logger.should_not_receive(:warn)
128
+ response = request.subscription 'profile_id'
129
+ response.recurring.billing.amount.total.should == 1000
130
+ response.recurring.regular_billing.paid.should == 1000
131
+ response.recurring.summary.next_billing_date.should == '2011-03-04T10:00:00Z'
132
+ end
133
+ end
134
+
135
+ context 'when ManageRecurringPaymentsProfileStatus response given' do
136
+ before do
137
+ fake_response 'ManageRecurringPaymentsProfileStatus/success'
138
+ end
139
+
140
+ it 'should handle all attributes' do
141
+ Paypal.logger.should_not_receive(:warn)
142
+ request.renew! 'profile_id', :Cancel
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Paypal::Payment::Common::Amount do
4
+ let :keys do
5
+ Paypal::Payment::Common::Amount.optional_attributes
6
+ end
7
+
8
+ describe '.new' do
9
+ it 'should not allow nil for attributes' do
10
+ amount = Paypal::Payment::Common::Amount.new
11
+ keys.each do |key|
12
+ amount.send(key).should == 0
13
+ end
14
+ end
15
+
16
+ it 'should treat all attributes as Numeric' do
17
+ # Integer
18
+ attributes = keys.inject({}) do |attributes, key|
19
+ attributes.merge!(key => "100")
20
+ end
21
+ amount = Paypal::Payment::Common::Amount.new attributes
22
+ keys.each do |key|
23
+ amount.send(key).should == 100
24
+ end
25
+
26
+ # Float
27
+ attributes = keys.inject({}) do |attributes, key|
28
+ attributes.merge!(key => "10.25")
29
+ end
30
+ amount = Paypal::Payment::Common::Amount.new attributes
31
+ keys.each do |key|
32
+ amount.send(key).should == 10.25
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe Paypal::Payment::Recurring::Activation do
4
+ let :instance do
5
+ Paypal::Payment::Recurring::Activation.new(
6
+ :initial_amount => 100,
7
+ :failed_action => 'ContinueOnFailure'
8
+ )
9
+ end
10
+
11
+ describe '#to_params' do
12
+ it 'should handle Recurring Profile activation parameters' do
13
+ instance.to_params.should == {
14
+ :INITAMT => '100.00',
15
+ :FAILEDINITAMTACTION => 'ContinueOnFailure'
16
+ }
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,170 @@
1
+ require 'spec_helper.rb'
2
+
3
+ describe Paypal::Payment::Recurring do
4
+ let :keys do
5
+ Paypal::Payment::Recurring.optional_attributes
6
+ end
7
+
8
+ let :trial_attributes do
9
+ {}
10
+ end
11
+
12
+ let :attributes do
13
+ {
14
+ :identifier => '12345',
15
+ :description => 'Subscription Payment Profile',
16
+ :status => 'Active',
17
+ :start_date => '2011-02-03T15:00:00Z',
18
+ :name => 'Nov Matake',
19
+ :auto_bill => 'NoAutoBill',
20
+ :max_fails => '0',
21
+ :aggregate_amount => '1000',
22
+ :aggregate_optional_amount => '0',
23
+ :final_payment_date => '1970-01-01T00:00:00Z',
24
+ :billing => {
25
+ :amount => Paypal::Payment::Common::Amount.new(
26
+ :total => '1000',
27
+ :shipping => '0',
28
+ :tax => '0'
29
+ ),
30
+ :currency_code => 'JPY',
31
+ :period => 'Month',
32
+ :frequency => '1',
33
+ :total_cycles => '0',
34
+ :trial => trial_attributes
35
+ },
36
+ :regular_billing => {
37
+ :amount => '1000',
38
+ :shipping_amount => '0',
39
+ :tax_amount => '0',
40
+ :currency_code => 'JPY',
41
+ :period => 'Month',
42
+ :frequency => '1',
43
+ :total_cycles => '0',
44
+ :paid => '1000'
45
+ },
46
+ :summary => {
47
+ :next_billing_date => '2011-03-04T10:00:00Z',
48
+ :cycles_completed => '1',
49
+ :cycles_remaining => '18446744073709551615',
50
+ :outstanding_balance => '0',
51
+ :failed_count => '0',
52
+ :last_payment_date => '2011-02-04T10:50:56Z',
53
+ :last_payment_amount => '1000'
54
+ }
55
+ }
56
+ end
57
+
58
+ let :instance do
59
+ Paypal::Payment::Recurring.new attributes
60
+ end
61
+
62
+ describe '.new' do
63
+ it 'should accept all supported attributes' do
64
+ instance.identifier.should == '12345'
65
+ instance.description.should == 'Subscription Payment Profile'
66
+ instance.status.should == 'Active'
67
+ instance.start_date.should == '2011-02-03T15:00:00Z'
68
+ instance.billing.trial.should be_nil
69
+ end
70
+
71
+ context 'when optional trial info given' do
72
+ let :trial_attributes do
73
+ {
74
+ :period => 'Month',
75
+ :frequency => '1',
76
+ :total_cycles => '0',
77
+ :currency_code => 'JPY',
78
+ :amount => '1000',
79
+ :shipping_amount => '0',
80
+ :tax_amount => '0'
81
+ }
82
+ end
83
+ it 'should setup trial billing info' do
84
+ instance.billing.trial.should == Paypal::Payment::Recurring::Billing.new(trial_attributes)
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '#to_params' do
90
+ it 'should handle Recurring Profile parameters' do
91
+ instance.to_params.should == {
92
+ :AUTOBILLOUTAMT => 'NoAutoBill',
93
+ :BILLINGFREQUENCY => 1,
94
+ :SHIPPINGAMT => '0.00',
95
+ :DESC => 'Subscription Payment Profile',
96
+ :SUBSCRIBERNAME => 'Nov Matake',
97
+ :BILLINGPERIOD => 'Month',
98
+ :AMT => '1000.00',
99
+ :MAXFAILEDPAYMENTS => 0,
100
+ :TOTALBILLINGCYCLES => 0,
101
+ :TAXAMT => '0.00',
102
+ :PROFILESTARTDATE => '2011-02-03T15:00:00Z',
103
+ :CURRENCYCODE => 'JPY'
104
+ }
105
+ end
106
+
107
+ context 'when start_date is Time' do
108
+ it 'should be stringfy' do
109
+ instance = Paypal::Payment::Recurring.new attributes.merge(
110
+ :start_date => Time.utc(2011, 2, 8, 15, 0, 0)
111
+ )
112
+ instance.start_date.should be_instance_of(Time)
113
+ instance.to_params[:PROFILESTARTDATE].should == '2011-02-08 15:00:00'
114
+ end
115
+ end
116
+
117
+ context 'when optional trial setting given' do
118
+ let :trial_attributes do
119
+ {
120
+ :period => 'Month',
121
+ :frequency => '1',
122
+ :total_cycles => '0',
123
+ :currency_code => 'JPY',
124
+ :amount => '1000',
125
+ :shipping_amount => '0',
126
+ :tax_amount => '0'
127
+ }
128
+ end
129
+ it 'should setup trial billing info' do
130
+ instance.to_params.should == {
131
+ :TRIALBILLINGPERIOD => "Month",
132
+ :TRIALBILLINGFREQUENCY => 1,
133
+ :TRIALTOTALBILLINGCYCLES => 0,
134
+ :TRIALAMT => "1000.00",
135
+ :TRIALCURRENCYCODE => "JPY",
136
+ :TRIALSHIPPINGAMT => "0.00",
137
+ :TRIALTAXAMT => "0.00",
138
+ :BILLINGPERIOD => "Month",
139
+ :BILLINGFREQUENCY => 1,
140
+ :TOTALBILLINGCYCLES => 0,
141
+ :AMT => "1000.00",
142
+ :CURRENCYCODE => "JPY",
143
+ :SHIPPINGAMT => "0.00",
144
+ :TAXAMT => "0.00",
145
+ :DESC => "Subscription Payment Profile",
146
+ :MAXFAILEDPAYMENTS => 0,
147
+ :AUTOBILLOUTAMT => "NoAutoBill",
148
+ :PROFILESTARTDATE => "2011-02-03T15:00:00Z",
149
+ :SUBSCRIBERNAME => "Nov Matake"
150
+ }
151
+ end
152
+ end
153
+ end
154
+
155
+ describe '#numeric_attribute?' do
156
+ let :numeric_attributes do
157
+ [:aggregate_amount, :aggregate_optional_amount, :max_fails, :failed_count]
158
+ end
159
+
160
+ it 'should detect numeric attributes' do
161
+ numeric_attributes.each do |key|
162
+ instance.numeric_attribute?(key).should be_true
163
+ end
164
+ non_numeric_keys = keys - numeric_attributes
165
+ non_numeric_keys.each do |key|
166
+ instance.numeric_attribute?(key).should be_false
167
+ end
168
+ end
169
+ end
170
+ end