paypal-express 0.0.1
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.
- data/.document +5 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/README.rdoc +17 -0
- data/Rakefile +20 -0
- data/VERSION +1 -0
- data/lib/cert +3509 -0
- data/lib/paypal.rb +56 -0
- data/lib/paypal/base.rb +19 -0
- data/lib/paypal/exceptions.rb +21 -0
- data/lib/paypal/express.rb +1 -0
- data/lib/paypal/express/request.rb +64 -0
- data/lib/paypal/express/response.rb +19 -0
- data/lib/paypal/nvp/request.rb +59 -0
- data/lib/paypal/nvp/response.rb +145 -0
- data/lib/paypal/payment/recurring.rb +43 -0
- data/lib/paypal/payment/recurring/activation.rb +14 -0
- data/lib/paypal/payment/recurring/billing.rb +37 -0
- data/lib/paypal/payment/recurring/summary.rb +11 -0
- data/lib/paypal/payment/request.rb +24 -0
- data/lib/paypal/payment/response.rb +36 -0
- data/lib/paypal/payment/response/amount.rb +11 -0
- data/lib/paypal/payment/response/info.rb +40 -0
- data/lib/paypal/payment/response/payer.rb +7 -0
- data/lib/paypal/payment/response/ship_to.rb +7 -0
- data/lib/paypal/util.rb +28 -0
- data/lib/restclient_with_ssl_support.rb +16 -0
- data/paypal-express.gemspec +24 -0
- data/spec/fake_response/CreateRecurringPaymentsProfile/failure.txt +1 -0
- data/spec/fake_response/CreateRecurringPaymentsProfile/success.txt +1 -0
- data/spec/fake_response/DoExpressCheckoutPayment/failure.txt +1 -0
- data/spec/fake_response/DoExpressCheckoutPayment/success.txt +1 -0
- data/spec/fake_response/GetExpressCheckoutDetails/failure.txt +1 -0
- data/spec/fake_response/GetExpressCheckoutDetails/success.txt +1 -0
- data/spec/fake_response/GetRecurringPaymentsProfileDetails/failure.txt +1 -0
- data/spec/fake_response/GetRecurringPaymentsProfileDetails/success.txt +1 -0
- data/spec/fake_response/ManageRecurringPaymentsProfileStatus/failure.txt +1 -0
- data/spec/fake_response/ManageRecurringPaymentsProfileStatus/success.txt +1 -0
- data/spec/fake_response/SetExpressCheckout/failure.txt +1 -0
- data/spec/fake_response/SetExpressCheckout/success.txt +1 -0
- data/spec/helpers/fake_response_helper.rb +27 -0
- data/spec/paypal/exception_spec.rb +17 -0
- data/spec/paypal/express/request_spec.rb +223 -0
- data/spec/paypal/express/response_spec.rb +33 -0
- data/spec/paypal/nvp/request_spec.rb +88 -0
- data/spec/paypal/payment/recurring_spec.rb +114 -0
- data/spec/paypal/payment/request_spec.rb +55 -0
- data/spec/paypal/payment/response/amount_spec.rb +36 -0
- data/spec/paypal/payment/response/info_spec.rb +88 -0
- data/spec/paypal/payment/response/payer_spec.rb +26 -0
- data/spec/paypal/payment/response/ship_to_spec.rb +26 -0
- data/spec/paypal/util_spec.rb +32 -0
- data/spec/spec_helper.rb +22 -0
- metadata +267 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Express::Response do
|
4
|
+
before do
|
5
|
+
fake_response 'SetExpressCheckout/success'
|
6
|
+
end
|
7
|
+
|
8
|
+
let :instance do
|
9
|
+
request = Paypal::Express::Request.new(
|
10
|
+
:username => 'nov',
|
11
|
+
:password => 'password',
|
12
|
+
:signature => 'sig',
|
13
|
+
:return_url => 'http://example.com/success',
|
14
|
+
:cancel_url => 'http://example.com/cancel'
|
15
|
+
)
|
16
|
+
request.setup Paypal::Payment::Request.new(
|
17
|
+
:billing_type => :RecurringPayments,
|
18
|
+
:billing_agreement_description => 'Recurring Payment Request'
|
19
|
+
)
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#redirect_uri' do
|
23
|
+
it 'should return express-checkout redirect endpoint with token' do
|
24
|
+
instance.redirect_uri.should == 'https://www.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-5YJ90598G69065317'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'should support sandbox mode' do
|
28
|
+
sandbox_mode do
|
29
|
+
instance.redirect_uri.should == 'https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=EC-5YJ90598G69065317'
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,88 @@
|
|
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 AttrMissing exception' do
|
19
|
+
attributes.keys.each do |missing_key|
|
20
|
+
insufficient_attributes = attributes.reject do |key, value|
|
21
|
+
key == missing_key
|
22
|
+
end
|
23
|
+
lambda do
|
24
|
+
Paypal::NVP::Request.new insufficient_attributes
|
25
|
+
end.should 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
|
+
lambda do
|
33
|
+
Paypal::NVP::Request.new attributes
|
34
|
+
end.should_not raise_error AttrRequired::AttrMissing
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should setup endpoint and version' do
|
38
|
+
client = Paypal::NVP::Request.new attributes
|
39
|
+
client.version.should == Paypal::API_VERSION
|
40
|
+
client.endpoint.should == Paypal::NVP::Request::ENDPOINT[:production]
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'should support sandbox mode' do
|
44
|
+
sandbox_mode do
|
45
|
+
client = Paypal::NVP::Request.new attributes
|
46
|
+
client.endpoint.should == Paypal::NVP::Request::ENDPOINT[:sandbox]
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe '#request' do
|
53
|
+
it 'should POST to NPV endpoint' do
|
54
|
+
lambda do
|
55
|
+
instance.request :RPCMethod
|
56
|
+
end.should request_to Paypal::NVP::Request::ENDPOINT[:production], :post
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'when got API error response' do
|
60
|
+
before do
|
61
|
+
fake_response 'SetExpressCheckout/failure'
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should raise Paypal::APIError' do
|
65
|
+
lambda do
|
66
|
+
instance.request :SetExpressCheckout
|
67
|
+
end.should raise_error(Paypal::APIError)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context 'when got HTTP error response' do
|
72
|
+
before do
|
73
|
+
FakeWeb.register_uri(
|
74
|
+
:post,
|
75
|
+
Paypal::NVP::Request::ENDPOINT[:production],
|
76
|
+
:body => "Invalid Request",
|
77
|
+
:status => ["400", "Bad Request"]
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should raise Paypal::APIError' do
|
82
|
+
lambda do
|
83
|
+
instance.request :SetExpressCheckout
|
84
|
+
end.should raise_error(Paypal::HttpError)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,114 @@
|
|
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 :attributes do
|
9
|
+
{
|
10
|
+
:identifier => '12345',
|
11
|
+
:description => 'Subscription Payment Profile',
|
12
|
+
:status => 'Active',
|
13
|
+
:start_date => '2011-02-03T15:00:00Z',
|
14
|
+
:name => 'Nov Matake',
|
15
|
+
:auto_bill => 'NoAutoBill',
|
16
|
+
:max_fails => '0',
|
17
|
+
:aggregate_amount => '1000',
|
18
|
+
:aggregate_optional_amount => '0',
|
19
|
+
:final_payment_date => '1970-01-01T00:00:00Z',
|
20
|
+
:billing => {
|
21
|
+
:amount => Paypal::Payment::Response::Amount.new(
|
22
|
+
:total => '1000',
|
23
|
+
:shipping => '0',
|
24
|
+
:tax => '0'
|
25
|
+
),
|
26
|
+
:currency_code => 'JPY',
|
27
|
+
:period => 'Month',
|
28
|
+
:frequency => '1',
|
29
|
+
:total_cycles => '0',
|
30
|
+
:trial_amount_paid => '0'
|
31
|
+
},
|
32
|
+
:regular_billing => {
|
33
|
+
:amount => '1000',
|
34
|
+
:shipping_amount => '0',
|
35
|
+
:tax_amount => '0',
|
36
|
+
:currency_code => 'JPY',
|
37
|
+
:period => 'Month',
|
38
|
+
:frequency => '1',
|
39
|
+
:total_cycles => '0',
|
40
|
+
:paid => '1000'
|
41
|
+
},
|
42
|
+
:summary => {
|
43
|
+
:next_billing_date => '2011-03-04T10:00:00Z',
|
44
|
+
:cycles_completed => '1',
|
45
|
+
:cycles_remaining => '18446744073709551615',
|
46
|
+
:outstanding_balance => '0',
|
47
|
+
:failed_count => '0',
|
48
|
+
:last_payment_date => '2011-02-04T10:50:56Z',
|
49
|
+
:last_payment_amount => '1000'
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
let :instance do
|
55
|
+
Paypal::Payment::Recurring.new attributes
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '.new' do
|
59
|
+
it 'should accept all supported attributes' do
|
60
|
+
instance.identifier.should == '12345'
|
61
|
+
instance.description.should == 'Subscription Payment Profile'
|
62
|
+
instance.status.should == 'Active'
|
63
|
+
instance.start_date.should == '2011-02-03T15:00:00Z'
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#to_params' do
|
68
|
+
it 'should handle Recurring Profile parameters' do
|
69
|
+
instance.to_params.should == {
|
70
|
+
:AUTOBILLAMT => 'NoAutoBill',
|
71
|
+
:BILLINGFREQUENCY => 1,
|
72
|
+
:TRIALTOTALBILLINGCYCLES => 0,
|
73
|
+
:SHIPPINGAMT => '0.00',
|
74
|
+
:DESC => 'Subscription Payment Profile',
|
75
|
+
:SUBSCRIBERNAME => 'Nov Matake',
|
76
|
+
:BILLINGPERIOD => 'Month',
|
77
|
+
:AMT => '1000.00',
|
78
|
+
:MAXFAILEDPAYMENTS => 0,
|
79
|
+
:TOTALBILLINGCYCLES => 0,
|
80
|
+
:TRIALBILLINGFREQUENCY => 0,
|
81
|
+
:TAXAMT => '0.00',
|
82
|
+
:TRIALAMT => '0.00',
|
83
|
+
:PROFILESTARTDATE => '2011-02-03T15:00:00Z',
|
84
|
+
:CURRENCYCODE => 'JPY'
|
85
|
+
}
|
86
|
+
end
|
87
|
+
|
88
|
+
context 'when start_date is Time' do
|
89
|
+
it 'should be stringfy' do
|
90
|
+
instance = Paypal::Payment::Recurring.new attributes.merge(
|
91
|
+
:start_date => Time.utc(2011, 2, 8, 15, 0, 0)
|
92
|
+
)
|
93
|
+
instance.start_date.should be_instance_of(Time)
|
94
|
+
instance.to_params[:PROFILESTARTDATE].should == '2011-02-08 15:00:00'
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#numeric_attribute?' do
|
100
|
+
let :numeric_attributes do
|
101
|
+
[:aggregate_amount, :aggregate_optional_amount, :max_fails, :failed_count]
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'should detect numeric attributes' do
|
105
|
+
numeric_attributes.each do |key|
|
106
|
+
instance.numeric_attribute?(key).should be_true
|
107
|
+
end
|
108
|
+
non_numeric_keys = keys - numeric_attributes
|
109
|
+
non_numeric_keys.each do |key|
|
110
|
+
instance.numeric_attribute?(key).should be_false
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Payment::Request do
|
4
|
+
let :instant_request do
|
5
|
+
Paypal::Payment::Request.new(
|
6
|
+
:amount => 10,
|
7
|
+
:currency_code => :JPY,
|
8
|
+
:description => 'Instant Payment Request',
|
9
|
+
:notify_url => 'http://merchant.example.com/notify'
|
10
|
+
)
|
11
|
+
end
|
12
|
+
|
13
|
+
let :recurring_request do
|
14
|
+
Paypal::Payment::Request.new(
|
15
|
+
:currency_code => :JPY,
|
16
|
+
:billing_type => :RecurringPayments,
|
17
|
+
:billing_agreement_description => 'Recurring Payment Request'
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '.new' do
|
22
|
+
it 'should handle Instant Payment parameters' do
|
23
|
+
instant_request.amount.should == 10
|
24
|
+
instant_request.currency_code.should == :JPY
|
25
|
+
instant_request.description.should == 'Instant Payment Request'
|
26
|
+
instant_request.notify_url.should == 'http://merchant.example.com/notify'
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should handle Recurring Payment parameters' do
|
30
|
+
recurring_request.currency_code.should == :JPY
|
31
|
+
recurring_request.billing_type.should == :RecurringPayments
|
32
|
+
recurring_request.billing_agreement_description.should == 'Recurring Payment Request'
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#to_params' do
|
37
|
+
it 'should handle Instant Payment parameters' do
|
38
|
+
instant_request.to_params.should == {
|
39
|
+
:PAYMENTREQUEST_0_AMT => "10.00",
|
40
|
+
:PAYMENTREQUEST_0_CURRENCYCODE => :JPY,
|
41
|
+
:PAYMENTREQUEST_0_DESC => "Instant Payment Request",
|
42
|
+
:PAYMENTREQUEST_0_NOTIFYURL => "http://merchant.example.com/notify"
|
43
|
+
}
|
44
|
+
end
|
45
|
+
|
46
|
+
it 'should handle Recurring Payment parameters' do
|
47
|
+
recurring_request.to_params.should == {
|
48
|
+
:PAYMENTREQUEST_0_AMT => "0.00",
|
49
|
+
:PAYMENTREQUEST_0_CURRENCYCODE => :JPY,
|
50
|
+
:L_BILLINGTYPE0 => :RecurringPayments,
|
51
|
+
:L_BILLINGAGREEMENTDESCRIPTION0 => "Recurring Payment Request"
|
52
|
+
}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Payment::Response::Amount do
|
4
|
+
let :keys do
|
5
|
+
Paypal::Payment::Response::Amount.optional_attributes
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.new' do
|
9
|
+
it 'should not allow nil for attributes' do
|
10
|
+
amount = Paypal::Payment::Response::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::Response::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::Response::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,88 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Payment::Response::Info do
|
4
|
+
let :attribute_mapping do
|
5
|
+
Paypal::Payment::Response::Info.attribute_mapping
|
6
|
+
end
|
7
|
+
|
8
|
+
let :attributes do
|
9
|
+
{
|
10
|
+
:ACK => 'Success',
|
11
|
+
:CURRENCYCODE => 'JPY',
|
12
|
+
:ERRORCODE => 0,
|
13
|
+
:ORDERTIME => '2011-02-08T03:23:54Z',
|
14
|
+
:PAYMENTSTATUS => 'Completed',
|
15
|
+
:PAYMENTTYPE => 'instant',
|
16
|
+
:PENDINGREASON => 'None',
|
17
|
+
:PROTECTIONELIGIBILITY => 'Ineligible',
|
18
|
+
:PROTECTIONELIGIBILITYTYPE => 'None',
|
19
|
+
:REASONCODE => 'None',
|
20
|
+
:TRANSACTIONID => '8NC65222871997739',
|
21
|
+
:TRANSACTIONTYPE => 'expresscheckout',
|
22
|
+
:AMT => '14.00',
|
23
|
+
:FEEAMT => '0.85',
|
24
|
+
:TAXAMT => '0.00'
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.new' do
|
29
|
+
context 'when attribute keys are uppercase Symbol' do
|
30
|
+
it 'should accept all without any warning' do
|
31
|
+
Paypal.logger.should_not_receive(:warn)
|
32
|
+
from_symbol_uppercase = Paypal::Payment::Response::Info.new attributes
|
33
|
+
attribute_mapping.values.each do |key|
|
34
|
+
from_symbol_uppercase.send(key).should_not be_nil
|
35
|
+
end
|
36
|
+
from_symbol_uppercase.amount.should == Paypal::Payment::Response::Amount.new(
|
37
|
+
:total => 14,
|
38
|
+
:fee => 0.85
|
39
|
+
)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context 'when attribute keys are lowercase Symbol' do
|
44
|
+
it 'should ignore them and warn' do
|
45
|
+
_attrs_ = attributes.inject({}) do |_attrs_, (k, v)|
|
46
|
+
_attrs_.merge!(k.to_s.downcase.to_sym => v)
|
47
|
+
end
|
48
|
+
_attrs_.each do |key, value|
|
49
|
+
Paypal.logger.should_receive(:warn).with(
|
50
|
+
"Ignored Parameter (Paypal::Payment::Response::Info): #{key}=#{value}"
|
51
|
+
)
|
52
|
+
end
|
53
|
+
from_symbol_lowercase = Paypal::Payment::Response::Info.new _attrs_
|
54
|
+
attribute_mapping.values.each do |key|
|
55
|
+
from_symbol_lowercase.send(key).should be_nil
|
56
|
+
end
|
57
|
+
from_symbol_lowercase.amount.should == Paypal::Payment::Response::Amount.new
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'when attribute keys are String' do
|
62
|
+
it 'should ignore them and warn' do
|
63
|
+
attributes.stringify_keys.each do |key, value|
|
64
|
+
Paypal.logger.should_receive(:warn).with(
|
65
|
+
"Ignored Parameter (Paypal::Payment::Response::Info): #{key}=#{value}"
|
66
|
+
)
|
67
|
+
end
|
68
|
+
from_string = Paypal::Payment::Response::Info.new attributes.stringify_keys
|
69
|
+
attribute_mapping.values.each do |key|
|
70
|
+
from_string.send(key).should be_nil
|
71
|
+
end
|
72
|
+
from_string.amount.should == Paypal::Payment::Response::Amount.new
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
context 'when non-supported attributes are given' do
|
77
|
+
it 'should ignore them and warn' do
|
78
|
+
_attr_ = attributes.merge(
|
79
|
+
:ignored => 'Ignore me!'
|
80
|
+
)
|
81
|
+
Paypal.logger.should_receive(:warn).with(
|
82
|
+
"Ignored Parameter (Paypal::Payment::Response::Info): ignored=Ignore me!"
|
83
|
+
)
|
84
|
+
Paypal::Payment::Response::Info.new _attr_
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Payment::Response::Payer do
|
4
|
+
let :keys do
|
5
|
+
Paypal::Payment::Response::Payer.optional_attributes
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.new' do
|
9
|
+
it 'should allow nil for attributes' do
|
10
|
+
payer = Paypal::Payment::Response::Payer.new
|
11
|
+
keys.each do |key|
|
12
|
+
payer.send(key).should be_nil
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should treat all attributes as String' do
|
17
|
+
attributes = keys.inject({}) do |attributes, key|
|
18
|
+
attributes.merge!(key => "xyz")
|
19
|
+
end
|
20
|
+
payer = Paypal::Payment::Response::Payer.new attributes
|
21
|
+
keys.each do |key|
|
22
|
+
payer.send(key).should == "xyz"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|