creative-paypal-express 0.8.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +22 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/Gemfile +7 -0
- data/LICENSE +20 -0
- data/README.rdoc +34 -0
- data/Rakefile +19 -0
- data/VERSION +1 -0
- data/lib/paypal.rb +84 -0
- data/lib/paypal/base.rb +19 -0
- data/lib/paypal/exception.rb +4 -0
- data/lib/paypal/exception/api_error.rb +94 -0
- data/lib/paypal/exception/http_error.rb +12 -0
- data/lib/paypal/express.rb +1 -0
- data/lib/paypal/express/request.rb +195 -0
- data/lib/paypal/express/response.rb +35 -0
- data/lib/paypal/ipn.rb +23 -0
- data/lib/paypal/nvp/request.rb +64 -0
- data/lib/paypal/nvp/response.rb +233 -0
- data/lib/paypal/payment/common/amount.rb +13 -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 +39 -0
- data/lib/paypal/payment/recurring/summary.rb +11 -0
- data/lib/paypal/payment/request.rb +67 -0
- data/lib/paypal/payment/request/item.rb +26 -0
- data/lib/paypal/payment/response.rb +73 -0
- data/lib/paypal/payment/response/address.rb +7 -0
- data/lib/paypal/payment/response/info.rb +45 -0
- data/lib/paypal/payment/response/item.rb +41 -0
- data/lib/paypal/payment/response/payer.rb +7 -0
- data/lib/paypal/payment/response/reference.rb +9 -0
- data/lib/paypal/payment/response/refund.rb +13 -0
- data/lib/paypal/util.rb +28 -0
- data/paypal-express.gemspec +23 -0
- data/spec/fake_response/BillAgreementUpdate/fetch.txt +1 -0
- data/spec/fake_response/BillAgreementUpdate/revoke.txt +1 -0
- data/spec/fake_response/CreateBillingAgreement/success.txt +1 -0
- data/spec/fake_response/CreateRecurringPaymentsProfile/failure.txt +1 -0
- data/spec/fake_response/CreateRecurringPaymentsProfile/success.txt +1 -0
- data/spec/fake_response/DoCapture/failure.txt +1 -0
- data/spec/fake_response/DoCapture/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/DoExpressCheckoutPayment/success_with_billing_agreement.txt +1 -0
- data/spec/fake_response/DoExpressCheckoutPayment/success_with_many_items.txt +1 -0
- data/spec/fake_response/DoReferenceTransaction/failure.txt +1 -0
- data/spec/fake_response/DoReferenceTransaction/success.txt +1 -0
- data/spec/fake_response/DoVoid/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/GetExpressCheckoutDetails/with_billing_accepted_status.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/GetTransactionDetails/failure.txt +1 -0
- data/spec/fake_response/GetTransactionDetails/success.txt +1 -0
- data/spec/fake_response/IPN/invalid.txt +1 -0
- data/spec/fake_response/IPN/valid.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/RefundTransaction/full.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 +33 -0
- data/spec/paypal/exception/api_error_spec.rb +78 -0
- data/spec/paypal/exception/http_error_spec.rb +8 -0
- data/spec/paypal/express/request_spec.rb +584 -0
- data/spec/paypal/express/response_spec.rb +80 -0
- data/spec/paypal/ipn_spec.rb +19 -0
- data/spec/paypal/nvp/request_spec.rb +116 -0
- data/spec/paypal/nvp/response_spec.rb +146 -0
- data/spec/paypal/payment/common/amount_spec.rb +36 -0
- data/spec/paypal/payment/recurring/activation_spec.rb +19 -0
- data/spec/paypal/payment/recurring_spec.rb +170 -0
- data/spec/paypal/payment/request/item_spec.rb +27 -0
- data/spec/paypal/payment/request_spec.rb +136 -0
- data/spec/paypal/payment/response/address_spec.rb +26 -0
- data/spec/paypal/payment/response/info_spec.rb +93 -0
- data/spec/paypal/payment/response/item_spec.rb +42 -0
- data/spec/paypal/payment/response/payer_spec.rb +26 -0
- data/spec/paypal/payment/response_spec.rb +16 -0
- data/spec/paypal/util_spec.rb +32 -0
- data/spec/spec_helper.rb +25 -0
- metadata +278 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Payment::Request::Item do
|
4
|
+
let :instance do
|
5
|
+
Paypal::Payment::Request::Item.new(
|
6
|
+
:name => 'Name',
|
7
|
+
:description => 'Description',
|
8
|
+
:amount => 10,
|
9
|
+
:quantity => 5,
|
10
|
+
:category => :Digital,
|
11
|
+
:number => '1'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#to_params' do
|
16
|
+
it 'should handle Recurring Profile activation parameters' do
|
17
|
+
instance.to_params(1).should == {
|
18
|
+
:L_PAYMENTREQUEST_1_NAME0 => 'Name',
|
19
|
+
:L_PAYMENTREQUEST_1_DESC0 => 'Description',
|
20
|
+
:L_PAYMENTREQUEST_1_AMT0 => '10.00',
|
21
|
+
:L_PAYMENTREQUEST_1_QTY0 => 5,
|
22
|
+
:L_PAYMENTREQUEST_1_ITEMCATEGORY0 => :Digital,
|
23
|
+
:L_PAYMENTREQUEST_1_NUMBER0 => '1'
|
24
|
+
}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,136 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Payment::Request do
|
4
|
+
let :instant_request do
|
5
|
+
Paypal::Payment::Request.new(
|
6
|
+
:amount => 25.7,
|
7
|
+
:tax_amount => 0.4,
|
8
|
+
:shipping_amount => 1.5,
|
9
|
+
:currency_code => :JPY,
|
10
|
+
:description => 'Instant Payment Request',
|
11
|
+
:notify_url => 'http://merchant.example.com/notify',
|
12
|
+
:invoice_number => 'ABC123',
|
13
|
+
:custom => 'Custom',
|
14
|
+
:items => [{
|
15
|
+
:quantity => 2,
|
16
|
+
:name => 'Item1',
|
17
|
+
:description => 'Awesome Item 1!',
|
18
|
+
:amount => 10.25
|
19
|
+
}, {
|
20
|
+
:quantity => 3,
|
21
|
+
:name => 'Item2',
|
22
|
+
:description => 'Awesome Item 2!',
|
23
|
+
:amount => 1.1
|
24
|
+
}],
|
25
|
+
:custom_fields => {
|
26
|
+
"l_surveychoice{n}" => 'abcd' # The '{n}' will be replaced with the index
|
27
|
+
}
|
28
|
+
)
|
29
|
+
end
|
30
|
+
|
31
|
+
let :recurring_request do
|
32
|
+
Paypal::Payment::Request.new(
|
33
|
+
:currency_code => :JPY,
|
34
|
+
:billing_type => :RecurringPayments,
|
35
|
+
:billing_agreement_description => 'Recurring Payment Request'
|
36
|
+
)
|
37
|
+
end
|
38
|
+
|
39
|
+
let :reference_transaction_request do
|
40
|
+
Paypal::Payment::Request.new(
|
41
|
+
:currency_code => :JPY,
|
42
|
+
:billing_type => :MerchantInitiatedBillingSingleAgreement,
|
43
|
+
:billing_agreement_description => 'Reference Transaction Request'
|
44
|
+
)
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '.new' do
|
48
|
+
it 'should handle Instant Payment parameters' do
|
49
|
+
instant_request.amount.total.should == 25.7
|
50
|
+
instant_request.amount.tax.should == 0.4
|
51
|
+
instant_request.amount.shipping.should == 1.5
|
52
|
+
instant_request.currency_code.should == :JPY
|
53
|
+
instant_request.description.should == 'Instant Payment Request'
|
54
|
+
instant_request.notify_url.should == 'http://merchant.example.com/notify'
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should handle Recurring Payment parameters' do
|
58
|
+
recurring_request.currency_code.should == :JPY
|
59
|
+
recurring_request.billing_type.should == :RecurringPayments
|
60
|
+
recurring_request.billing_agreement_description.should == 'Recurring Payment Request'
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'should handle Recurring Payment parameters' do
|
64
|
+
reference_transaction_request.currency_code.should == :JPY
|
65
|
+
reference_transaction_request.billing_type.should == :MerchantInitiatedBillingSingleAgreement
|
66
|
+
reference_transaction_request.billing_agreement_description.should == 'Reference Transaction Request'
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe '#to_params' do
|
71
|
+
it 'should handle Instant Payment parameters' do
|
72
|
+
instant_request.to_params.should == {
|
73
|
+
:PAYMENTREQUEST_0_AMT => "25.70",
|
74
|
+
:PAYMENTREQUEST_0_TAXAMT => "0.40",
|
75
|
+
:PAYMENTREQUEST_0_SHIPPINGAMT => "1.50",
|
76
|
+
:PAYMENTREQUEST_0_CURRENCYCODE => :JPY,
|
77
|
+
:PAYMENTREQUEST_0_DESC => "Instant Payment Request",
|
78
|
+
:PAYMENTREQUEST_0_NOTIFYURL => "http://merchant.example.com/notify",
|
79
|
+
:PAYMENTREQUEST_0_ITEMAMT => "23.80",
|
80
|
+
:PAYMENTREQUEST_0_INVNUM => "ABC123",
|
81
|
+
:PAYMENTREQUEST_0_CUSTOM => "Custom",
|
82
|
+
:L_PAYMENTREQUEST_0_NAME0 => "Item1",
|
83
|
+
:L_PAYMENTREQUEST_0_DESC0 => "Awesome Item 1!",
|
84
|
+
:L_PAYMENTREQUEST_0_AMT0 => "10.25",
|
85
|
+
:L_PAYMENTREQUEST_0_QTY0 => 2,
|
86
|
+
:L_PAYMENTREQUEST_0_NAME1 => "Item2",
|
87
|
+
:L_PAYMENTREQUEST_0_DESC1 => "Awesome Item 2!",
|
88
|
+
:L_PAYMENTREQUEST_0_AMT1 => "1.10",
|
89
|
+
:L_PAYMENTREQUEST_0_QTY1 => 3,
|
90
|
+
:L_SURVEYCHOICE0 => 'abcd' # Note the 'n' was replaced by the index
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'should handle Recurring Payment parameters' do
|
95
|
+
recurring_request.to_params.should == {
|
96
|
+
:PAYMENTREQUEST_0_AMT => "0.00",
|
97
|
+
:PAYMENTREQUEST_0_TAXAMT => "0.00",
|
98
|
+
:PAYMENTREQUEST_0_SHIPPINGAMT => "0.00",
|
99
|
+
:PAYMENTREQUEST_0_CURRENCYCODE => :JPY,
|
100
|
+
:L_BILLINGTYPE0 => :RecurringPayments,
|
101
|
+
:L_BILLINGAGREEMENTDESCRIPTION0 => "Recurring Payment Request"
|
102
|
+
}
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should handle Reference Transactions parameters' do
|
106
|
+
reference_transaction_request.to_params.should == {
|
107
|
+
:PAYMENTREQUEST_0_AMT => "0.00",
|
108
|
+
:PAYMENTREQUEST_0_TAXAMT => "0.00",
|
109
|
+
:PAYMENTREQUEST_0_SHIPPINGAMT => "0.00",
|
110
|
+
:PAYMENTREQUEST_0_CURRENCYCODE => :JPY,
|
111
|
+
:L_BILLINGTYPE0 => :MerchantInitiatedBillingSingleAgreement,
|
112
|
+
:L_BILLINGAGREEMENTDESCRIPTION0 => "Reference Transaction Request"
|
113
|
+
}
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
describe '#items_amount' do
|
118
|
+
context 'when BigDecimal'
|
119
|
+
let(:instance) do
|
120
|
+
Paypal::Payment::Request.new(
|
121
|
+
:items => [{
|
122
|
+
:quantity => 3,
|
123
|
+
:name => 'Item1',
|
124
|
+
:description => 'Awesome Item 1!',
|
125
|
+
:amount => 130.45
|
126
|
+
}]
|
127
|
+
)
|
128
|
+
end
|
129
|
+
|
130
|
+
# NOTE:
|
131
|
+
# 130.45 * 3 => 391.34999999999997 (in ruby 1.9)
|
132
|
+
it 'should calculate total amount correctly' do
|
133
|
+
instance.items_amount.should == 391.35
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Payment::Response::Address do
|
4
|
+
let :keys do
|
5
|
+
Paypal::Payment::Response::Address.optional_attributes
|
6
|
+
end
|
7
|
+
|
8
|
+
describe '.new' do
|
9
|
+
it 'should allow nil for attributes' do
|
10
|
+
payer = Paypal::Payment::Response::Address.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::Address.new attributes
|
21
|
+
keys.each do |key|
|
22
|
+
payer.send(key).should == "xyz"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,93 @@
|
|
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
|
+
:RECEIPTID => '12345',
|
26
|
+
:SECUREMERCHANTACCOUNTID => '123456789',
|
27
|
+
:PAYMENTREQUESTID => '12345',
|
28
|
+
:SELLERPAYPALACCOUNTID => 'seller@shop.example.com',
|
29
|
+
:EXCHANGERATE => '0.811965'
|
30
|
+
}
|
31
|
+
end
|
32
|
+
|
33
|
+
describe '.new' do
|
34
|
+
context 'when attribute keys are uppercase Symbol' do
|
35
|
+
it 'should accept all without any warning' do
|
36
|
+
Paypal.logger.should_not_receive(:warn)
|
37
|
+
from_symbol_uppercase = Paypal::Payment::Response::Info.new attributes
|
38
|
+
attribute_mapping.values.each do |key|
|
39
|
+
from_symbol_uppercase.send(key).should_not be_nil
|
40
|
+
end
|
41
|
+
from_symbol_uppercase.amount.should == Paypal::Payment::Common::Amount.new(
|
42
|
+
:total => 14,
|
43
|
+
:fee => 0.85
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'when attribute keys are lowercase Symbol' do
|
49
|
+
it 'should ignore them and warn' do
|
50
|
+
_attrs_ = attributes.inject({}) do |_attrs_, (k, v)|
|
51
|
+
_attrs_.merge!(k.to_s.downcase.to_sym => v)
|
52
|
+
end
|
53
|
+
_attrs_.each do |key, value|
|
54
|
+
Paypal.logger.should_receive(:warn).with(
|
55
|
+
"Ignored Parameter (Paypal::Payment::Response::Info): #{key}=#{value}"
|
56
|
+
)
|
57
|
+
end
|
58
|
+
from_symbol_lowercase = Paypal::Payment::Response::Info.new _attrs_
|
59
|
+
attribute_mapping.values.each do |key|
|
60
|
+
from_symbol_lowercase.send(key).should be_nil
|
61
|
+
end
|
62
|
+
from_symbol_lowercase.amount.should == Paypal::Payment::Common::Amount.new
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when attribute keys are String' do
|
67
|
+
it 'should ignore them and warn' do
|
68
|
+
attributes.stringify_keys.each do |key, value|
|
69
|
+
Paypal.logger.should_receive(:warn).with(
|
70
|
+
"Ignored Parameter (Paypal::Payment::Response::Info): #{key}=#{value}"
|
71
|
+
)
|
72
|
+
end
|
73
|
+
from_string = Paypal::Payment::Response::Info.new attributes.stringify_keys
|
74
|
+
attribute_mapping.values.each do |key|
|
75
|
+
from_string.send(key).should be_nil
|
76
|
+
end
|
77
|
+
from_string.amount.should == Paypal::Payment::Common::Amount.new
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'when non-supported attributes are given' do
|
82
|
+
it 'should ignore them and warn' do
|
83
|
+
_attr_ = attributes.merge(
|
84
|
+
:ignored => 'Ignore me!'
|
85
|
+
)
|
86
|
+
Paypal.logger.should_receive(:warn).with(
|
87
|
+
"Ignored Parameter (Paypal::Payment::Response::Info): ignored=Ignore me!"
|
88
|
+
)
|
89
|
+
Paypal::Payment::Response::Info.new _attr_
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Payment::Response::Info do
|
4
|
+
let :attributes do
|
5
|
+
{
|
6
|
+
:NAME => 'Item Name',
|
7
|
+
:DESC => 'Item Description',
|
8
|
+
:QTY => '1',
|
9
|
+
:NUMBER => '1',
|
10
|
+
:ITEMCATEGORY => 'Digital',
|
11
|
+
:ITEMWIDTHVALUE => '1.0',
|
12
|
+
:ITEMHEIGHTVALUE => '2.0',
|
13
|
+
:ITEMLENGTHVALUE => '3.0',
|
14
|
+
:ITEMWEIGHTVALUE => '4.0'
|
15
|
+
}
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.new' do
|
19
|
+
subject { Paypal::Payment::Response::Item.new(attributes) }
|
20
|
+
its(:name) { should == 'Item Name' }
|
21
|
+
its(:description) { should == 'Item Description' }
|
22
|
+
its(:quantity) { should == 1 }
|
23
|
+
its(:category) { should == 'Digital' }
|
24
|
+
its(:width) { should == '1.0' }
|
25
|
+
its(:height) { should == '2.0' }
|
26
|
+
its(:length) { should == '3.0' }
|
27
|
+
its(:weight) { should == '4.0' }
|
28
|
+
its(:number) { should == '1' }
|
29
|
+
|
30
|
+
context 'when non-supported attributes are given' do
|
31
|
+
it 'should ignore them and warn' do
|
32
|
+
_attr_ = attributes.merge(
|
33
|
+
:ignored => 'Ignore me!'
|
34
|
+
)
|
35
|
+
Paypal.logger.should_receive(:warn).with(
|
36
|
+
"Ignored Parameter (Paypal::Payment::Response::Item): ignored=Ignore me!"
|
37
|
+
)
|
38
|
+
Paypal::Payment::Response::Item.new _attr_
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
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
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Payment::Response do
|
4
|
+
describe '.new' do
|
5
|
+
context 'when non-supported attributes are given' do
|
6
|
+
it 'should ignore them and warn' do
|
7
|
+
Paypal.logger.should_receive(:warn).with(
|
8
|
+
"Ignored Parameter (Paypal::Payment::Response): ignored=Ignore me!"
|
9
|
+
)
|
10
|
+
response = Paypal::Payment::Response.new(
|
11
|
+
:ignored => 'Ignore me!'
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec_helper.rb'
|
2
|
+
|
3
|
+
describe Paypal::Util do
|
4
|
+
describe '.formatted_amount' do
|
5
|
+
it 'should return String in "xx.yy" format' do
|
6
|
+
Paypal::Util.formatted_amount(nil).should == '0.00'
|
7
|
+
Paypal::Util.formatted_amount(10).should == '10.00'
|
8
|
+
Paypal::Util.formatted_amount(10.02).should == '10.02'
|
9
|
+
Paypal::Util.formatted_amount(10.2).should == '10.20'
|
10
|
+
Paypal::Util.formatted_amount(10.24).should == '10.24'
|
11
|
+
Paypal::Util.formatted_amount(10.255).should == '10.25'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '.to_numeric' do
|
16
|
+
it 'should return Numeric' do
|
17
|
+
Paypal::Util.to_numeric('10').should be_kind_of(Integer)
|
18
|
+
Paypal::Util.to_numeric('10.5').should be_kind_of(Float)
|
19
|
+
Paypal::Util.to_numeric('-1.5').should == -1.5
|
20
|
+
Paypal::Util.to_numeric('-1').should == -1
|
21
|
+
Paypal::Util.to_numeric('0').should == 0
|
22
|
+
Paypal::Util.to_numeric('0.00').should == 0
|
23
|
+
Paypal::Util.to_numeric('10').should == 10
|
24
|
+
Paypal::Util.to_numeric('10.00').should == 10
|
25
|
+
Paypal::Util.to_numeric('10.02').should == 10.02
|
26
|
+
Paypal::Util.to_numeric('10.2').should == 10.2
|
27
|
+
Paypal::Util.to_numeric('10.20').should == 10.2
|
28
|
+
Paypal::Util.to_numeric('10.24').should == 10.24
|
29
|
+
Paypal::Util.to_numeric('10.25').should == 10.25
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'simplecov'
|
2
|
+
|
3
|
+
SimpleCov.start do
|
4
|
+
add_filter 'spec'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'paypal'
|
8
|
+
require 'rspec'
|
9
|
+
require 'helpers/fake_response_helper'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.before do
|
13
|
+
Paypal.logger = double("logger")
|
14
|
+
end
|
15
|
+
config.after do
|
16
|
+
FakeWeb.clean_registry
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def sandbox_mode(&block)
|
21
|
+
Paypal.sandbox!
|
22
|
+
yield
|
23
|
+
ensure
|
24
|
+
Paypal.sandbox = false
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,278 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: creative-paypal-express
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.8.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- nov matake
|
8
|
+
- CreativeGS
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2016-07-07 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '2.3'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '2.3'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rest-client
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: attr_required
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 0.0.5
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 0.0.5
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: rake
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0.8'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0.8'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: simplecov
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - "<"
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '2.99'
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - "<"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '2.99'
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: fakeweb
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: 1.3.0
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: 1.3.0
|
112
|
+
description: PayPal Express Checkout API Client for Instance, Recurring and Digital
|
113
|
+
Goods Payment.
|
114
|
+
email: hi@creative.gs
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files:
|
118
|
+
- LICENSE
|
119
|
+
- README.rdoc
|
120
|
+
files:
|
121
|
+
- ".document"
|
122
|
+
- ".gitignore"
|
123
|
+
- ".rspec"
|
124
|
+
- ".travis.yml"
|
125
|
+
- Gemfile
|
126
|
+
- LICENSE
|
127
|
+
- README.rdoc
|
128
|
+
- Rakefile
|
129
|
+
- VERSION
|
130
|
+
- lib/paypal.rb
|
131
|
+
- lib/paypal/base.rb
|
132
|
+
- lib/paypal/exception.rb
|
133
|
+
- lib/paypal/exception/api_error.rb
|
134
|
+
- lib/paypal/exception/http_error.rb
|
135
|
+
- lib/paypal/express.rb
|
136
|
+
- lib/paypal/express/request.rb
|
137
|
+
- lib/paypal/express/response.rb
|
138
|
+
- lib/paypal/ipn.rb
|
139
|
+
- lib/paypal/nvp/request.rb
|
140
|
+
- lib/paypal/nvp/response.rb
|
141
|
+
- lib/paypal/payment/common/amount.rb
|
142
|
+
- lib/paypal/payment/recurring.rb
|
143
|
+
- lib/paypal/payment/recurring/activation.rb
|
144
|
+
- lib/paypal/payment/recurring/billing.rb
|
145
|
+
- lib/paypal/payment/recurring/summary.rb
|
146
|
+
- lib/paypal/payment/request.rb
|
147
|
+
- lib/paypal/payment/request/item.rb
|
148
|
+
- lib/paypal/payment/response.rb
|
149
|
+
- lib/paypal/payment/response/address.rb
|
150
|
+
- lib/paypal/payment/response/info.rb
|
151
|
+
- lib/paypal/payment/response/item.rb
|
152
|
+
- lib/paypal/payment/response/payer.rb
|
153
|
+
- lib/paypal/payment/response/reference.rb
|
154
|
+
- lib/paypal/payment/response/refund.rb
|
155
|
+
- lib/paypal/util.rb
|
156
|
+
- paypal-express.gemspec
|
157
|
+
- spec/fake_response/BillAgreementUpdate/fetch.txt
|
158
|
+
- spec/fake_response/BillAgreementUpdate/revoke.txt
|
159
|
+
- spec/fake_response/CreateBillingAgreement/success.txt
|
160
|
+
- spec/fake_response/CreateRecurringPaymentsProfile/failure.txt
|
161
|
+
- spec/fake_response/CreateRecurringPaymentsProfile/success.txt
|
162
|
+
- spec/fake_response/DoCapture/failure.txt
|
163
|
+
- spec/fake_response/DoCapture/success.txt
|
164
|
+
- spec/fake_response/DoExpressCheckoutPayment/failure.txt
|
165
|
+
- spec/fake_response/DoExpressCheckoutPayment/success.txt
|
166
|
+
- spec/fake_response/DoExpressCheckoutPayment/success_with_billing_agreement.txt
|
167
|
+
- spec/fake_response/DoExpressCheckoutPayment/success_with_many_items.txt
|
168
|
+
- spec/fake_response/DoReferenceTransaction/failure.txt
|
169
|
+
- spec/fake_response/DoReferenceTransaction/success.txt
|
170
|
+
- spec/fake_response/DoVoid/success.txt
|
171
|
+
- spec/fake_response/GetExpressCheckoutDetails/failure.txt
|
172
|
+
- spec/fake_response/GetExpressCheckoutDetails/success.txt
|
173
|
+
- spec/fake_response/GetExpressCheckoutDetails/with_billing_accepted_status.txt
|
174
|
+
- spec/fake_response/GetRecurringPaymentsProfileDetails/failure.txt
|
175
|
+
- spec/fake_response/GetRecurringPaymentsProfileDetails/success.txt
|
176
|
+
- spec/fake_response/GetTransactionDetails/failure.txt
|
177
|
+
- spec/fake_response/GetTransactionDetails/success.txt
|
178
|
+
- spec/fake_response/IPN/invalid.txt
|
179
|
+
- spec/fake_response/IPN/valid.txt
|
180
|
+
- spec/fake_response/ManageRecurringPaymentsProfileStatus/failure.txt
|
181
|
+
- spec/fake_response/ManageRecurringPaymentsProfileStatus/success.txt
|
182
|
+
- spec/fake_response/RefundTransaction/full.txt
|
183
|
+
- spec/fake_response/SetExpressCheckout/failure.txt
|
184
|
+
- spec/fake_response/SetExpressCheckout/success.txt
|
185
|
+
- spec/helpers/fake_response_helper.rb
|
186
|
+
- spec/paypal/exception/api_error_spec.rb
|
187
|
+
- spec/paypal/exception/http_error_spec.rb
|
188
|
+
- spec/paypal/express/request_spec.rb
|
189
|
+
- spec/paypal/express/response_spec.rb
|
190
|
+
- spec/paypal/ipn_spec.rb
|
191
|
+
- spec/paypal/nvp/request_spec.rb
|
192
|
+
- spec/paypal/nvp/response_spec.rb
|
193
|
+
- spec/paypal/payment/common/amount_spec.rb
|
194
|
+
- spec/paypal/payment/recurring/activation_spec.rb
|
195
|
+
- spec/paypal/payment/recurring_spec.rb
|
196
|
+
- spec/paypal/payment/request/item_spec.rb
|
197
|
+
- spec/paypal/payment/request_spec.rb
|
198
|
+
- spec/paypal/payment/response/address_spec.rb
|
199
|
+
- spec/paypal/payment/response/info_spec.rb
|
200
|
+
- spec/paypal/payment/response/item_spec.rb
|
201
|
+
- spec/paypal/payment/response/payer_spec.rb
|
202
|
+
- spec/paypal/payment/response_spec.rb
|
203
|
+
- spec/paypal/util_spec.rb
|
204
|
+
- spec/spec_helper.rb
|
205
|
+
homepage: http://github.com/nov/paypal-express
|
206
|
+
licenses: []
|
207
|
+
metadata: {}
|
208
|
+
post_install_message:
|
209
|
+
rdoc_options:
|
210
|
+
- "--charset=UTF-8"
|
211
|
+
require_paths:
|
212
|
+
- lib
|
213
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
214
|
+
requirements:
|
215
|
+
- - ">="
|
216
|
+
- !ruby/object:Gem::Version
|
217
|
+
version: '0'
|
218
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
|
+
requirements:
|
220
|
+
- - ">="
|
221
|
+
- !ruby/object:Gem::Version
|
222
|
+
version: 1.3.6
|
223
|
+
requirements: []
|
224
|
+
rubyforge_project:
|
225
|
+
rubygems_version: 2.4.8
|
226
|
+
signing_key:
|
227
|
+
specification_version: 4
|
228
|
+
summary: PayPal Express Checkout API Client for Instance, Recurring and Digital Goods
|
229
|
+
Payment.
|
230
|
+
test_files:
|
231
|
+
- spec/fake_response/BillAgreementUpdate/fetch.txt
|
232
|
+
- spec/fake_response/BillAgreementUpdate/revoke.txt
|
233
|
+
- spec/fake_response/CreateBillingAgreement/success.txt
|
234
|
+
- spec/fake_response/CreateRecurringPaymentsProfile/failure.txt
|
235
|
+
- spec/fake_response/CreateRecurringPaymentsProfile/success.txt
|
236
|
+
- spec/fake_response/DoCapture/failure.txt
|
237
|
+
- spec/fake_response/DoCapture/success.txt
|
238
|
+
- spec/fake_response/DoExpressCheckoutPayment/failure.txt
|
239
|
+
- spec/fake_response/DoExpressCheckoutPayment/success.txt
|
240
|
+
- spec/fake_response/DoExpressCheckoutPayment/success_with_billing_agreement.txt
|
241
|
+
- spec/fake_response/DoExpressCheckoutPayment/success_with_many_items.txt
|
242
|
+
- spec/fake_response/DoReferenceTransaction/failure.txt
|
243
|
+
- spec/fake_response/DoReferenceTransaction/success.txt
|
244
|
+
- spec/fake_response/DoVoid/success.txt
|
245
|
+
- spec/fake_response/GetExpressCheckoutDetails/failure.txt
|
246
|
+
- spec/fake_response/GetExpressCheckoutDetails/success.txt
|
247
|
+
- spec/fake_response/GetExpressCheckoutDetails/with_billing_accepted_status.txt
|
248
|
+
- spec/fake_response/GetRecurringPaymentsProfileDetails/failure.txt
|
249
|
+
- spec/fake_response/GetRecurringPaymentsProfileDetails/success.txt
|
250
|
+
- spec/fake_response/GetTransactionDetails/failure.txt
|
251
|
+
- spec/fake_response/GetTransactionDetails/success.txt
|
252
|
+
- spec/fake_response/IPN/invalid.txt
|
253
|
+
- spec/fake_response/IPN/valid.txt
|
254
|
+
- spec/fake_response/ManageRecurringPaymentsProfileStatus/failure.txt
|
255
|
+
- spec/fake_response/ManageRecurringPaymentsProfileStatus/success.txt
|
256
|
+
- spec/fake_response/RefundTransaction/full.txt
|
257
|
+
- spec/fake_response/SetExpressCheckout/failure.txt
|
258
|
+
- spec/fake_response/SetExpressCheckout/success.txt
|
259
|
+
- spec/helpers/fake_response_helper.rb
|
260
|
+
- spec/paypal/exception/api_error_spec.rb
|
261
|
+
- spec/paypal/exception/http_error_spec.rb
|
262
|
+
- spec/paypal/express/request_spec.rb
|
263
|
+
- spec/paypal/express/response_spec.rb
|
264
|
+
- spec/paypal/ipn_spec.rb
|
265
|
+
- spec/paypal/nvp/request_spec.rb
|
266
|
+
- spec/paypal/nvp/response_spec.rb
|
267
|
+
- spec/paypal/payment/common/amount_spec.rb
|
268
|
+
- spec/paypal/payment/recurring/activation_spec.rb
|
269
|
+
- spec/paypal/payment/recurring_spec.rb
|
270
|
+
- spec/paypal/payment/request/item_spec.rb
|
271
|
+
- spec/paypal/payment/request_spec.rb
|
272
|
+
- spec/paypal/payment/response/address_spec.rb
|
273
|
+
- spec/paypal/payment/response/info_spec.rb
|
274
|
+
- spec/paypal/payment/response/item_spec.rb
|
275
|
+
- spec/paypal/payment/response/payer_spec.rb
|
276
|
+
- spec/paypal/payment/response_spec.rb
|
277
|
+
- spec/paypal/util_spec.rb
|
278
|
+
- spec/spec_helper.rb
|