paypal-payment 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rspec +1 -0
- data/Gemfile +18 -0
- data/Guardfile +24 -0
- data/README.rdoc +107 -0
- data/Rakefile +5 -0
- data/docs/AdaptivePayments.rdoc +84 -0
- data/docs/PP_NVPAPI_DeveloperGuide.pdf +0 -0
- data/docs/PP_WPP_IntegrationGuide.pdf +0 -0
- data/docs/adaptive_payments.md +55 -0
- data/docs/api.txt +67 -0
- data/docs/design.txt +38 -0
- data/docs/express_checkout.md +172 -0
- data/docs/requirements.txt +32 -0
- data/lib/paypal-payment.rb +10 -0
- data/lib/paypal/adaptive_payments.rb +31 -0
- data/lib/paypal/adaptive_payments/api.rb +51 -0
- data/lib/paypal/adaptive_payments/base.rb +11 -0
- data/lib/paypal/adaptive_payments/client_details.rb +14 -0
- data/lib/paypal/adaptive_payments/display_options.rb +10 -0
- data/lib/paypal/adaptive_payments/funding_constraint.rb +11 -0
- data/lib/paypal/adaptive_payments/funding_type_info.rb +8 -0
- data/lib/paypal/adaptive_payments/funding_type_list.rb +11 -0
- data/lib/paypal/adaptive_payments/initiating_entity.rb +11 -0
- data/lib/paypal/adaptive_payments/institution_customer.rb +13 -0
- data/lib/paypal/adaptive_payments/invoice_data.rb +13 -0
- data/lib/paypal/adaptive_payments/invoice_item.rb +11 -0
- data/lib/paypal/adaptive_payments/payment.rb +105 -0
- data/lib/paypal/adaptive_payments/payment_info.rb +18 -0
- data/lib/paypal/adaptive_payments/payment_info_list.rb +11 -0
- data/lib/paypal/adaptive_payments/payment_options.rb +39 -0
- data/lib/paypal/adaptive_payments/phone.rb +9 -0
- data/lib/paypal/adaptive_payments/preapproval.rb +52 -0
- data/lib/paypal/adaptive_payments/receiver.rb +17 -0
- data/lib/paypal/adaptive_payments/receiver_list.rb +49 -0
- data/lib/paypal/adaptive_payments/receiver_options.rb +19 -0
- data/lib/paypal/adaptive_payments/request.rb +51 -0
- data/lib/paypal/adaptive_payments/response.rb +38 -0
- data/lib/paypal/adaptive_payments/response/address.rb +13 -0
- data/lib/paypal/adaptive_payments/response/address_list.rb +11 -0
- data/lib/paypal/adaptive_payments/response/base_address.rb +13 -0
- data/lib/paypal/adaptive_payments/response/details.rb +19 -0
- data/lib/paypal/adaptive_payments/response/error_list.rb +15 -0
- data/lib/paypal/adaptive_payments/response/pay.rb +31 -0
- data/lib/paypal/adaptive_payments/response/pay_error.rb +16 -0
- data/lib/paypal/adaptive_payments/response/pay_error_list.rb +15 -0
- data/lib/paypal/adaptive_payments/response/pay_options.rb +7 -0
- data/lib/paypal/adaptive_payments/response/preapproval.rb +47 -0
- data/lib/paypal/adaptive_payments/response/refund.rb +16 -0
- data/lib/paypal/adaptive_payments/response/refund_info.rb +24 -0
- data/lib/paypal/adaptive_payments/response/refund_info_list.rb +11 -0
- data/lib/paypal/adaptive_payments/response/shipping_address.rb +11 -0
- data/lib/paypal/adaptive_payments/sender_identifier.rb +7 -0
- data/lib/paypal/adaptive_payments/sender_options.rb +8 -0
- data/lib/paypal/api.rb +94 -0
- data/lib/paypal/cacert.pem +3987 -0
- data/lib/paypal/common.rb +11 -0
- data/lib/paypal/common/base.rb +83 -0
- data/lib/paypal/common/error_data.rb +15 -0
- data/lib/paypal/common/request.rb +45 -0
- data/lib/paypal/common/request_envelope.rb +13 -0
- data/lib/paypal/common/response.rb +34 -0
- data/lib/paypal/common/response_envelope.rb +19 -0
- data/lib/paypal/express_checkout.rb +19 -0
- data/lib/paypal/express_checkout/account.rb +16 -0
- data/lib/paypal/express_checkout/api.rb +43 -0
- data/lib/paypal/express_checkout/base.rb +37 -0
- data/lib/paypal/express_checkout/billing.rb +7 -0
- data/lib/paypal/express_checkout/callback.rb +17 -0
- data/lib/paypal/express_checkout/checkout.rb +144 -0
- data/lib/paypal/express_checkout/fields.rb +449 -0
- data/lib/paypal/express_checkout/fmf.rb +7 -0
- data/lib/paypal/express_checkout/payment.rb +76 -0
- data/lib/paypal/express_checkout/payment_item.rb +7 -0
- data/lib/paypal/express_checkout/recurring.rb +131 -0
- data/lib/paypal/express_checkout/request.rb +212 -0
- data/lib/paypal/express_checkout/response.rb +52 -0
- data/lib/paypal/express_checkout/response/account.rb +30 -0
- data/lib/paypal/express_checkout/response/address.rb +29 -0
- data/lib/paypal/express_checkout/response/authorization.rb +25 -0
- data/lib/paypal/express_checkout/response/base.rb +125 -0
- data/lib/paypal/express_checkout/response/callback_request.rb +10 -0
- data/lib/paypal/express_checkout/response/callback_response.rb +8 -0
- data/lib/paypal/express_checkout/response/capture.rb +14 -0
- data/lib/paypal/express_checkout/response/checkout.rb +11 -0
- data/lib/paypal/express_checkout/response/details.rb +35 -0
- data/lib/paypal/express_checkout/response/manage_profile.rb +9 -0
- data/lib/paypal/express_checkout/response/notification.rb +85 -0
- data/lib/paypal/express_checkout/response/payment.rb +24 -0
- data/lib/paypal/express_checkout/response/profile.rb +58 -0
- data/lib/paypal/express_checkout/response/reference.rb +11 -0
- data/lib/paypal/express_checkout/response/refund.rb +13 -0
- data/lib/paypal/express_checkout/response/search.rb +33 -0
- data/lib/paypal/express_checkout/response/transaction_details.rb +11 -0
- data/lib/paypal/express_checkout/shipping_option.rb +7 -0
- data/lib/paypal/express_checkout/utils.rb +26 -0
- data/lib/paypal/express_checkout/version.rb +10 -0
- data/lib/paypal/invoice.rb +22 -0
- data/lib/paypal/invoice/api.rb +51 -0
- data/lib/paypal/invoice/base.rb +11 -0
- data/lib/paypal/invoice/base_address.rb +11 -0
- data/lib/paypal/invoice/business_info.rb +17 -0
- data/lib/paypal/invoice/date_range.rb +8 -0
- data/lib/paypal/invoice/invoice.rb +117 -0
- data/lib/paypal/invoice/invoice_details.rb +38 -0
- data/lib/paypal/invoice/invoice_item.rb +13 -0
- data/lib/paypal/invoice/invoice_item_list.rb +10 -0
- data/lib/paypal/invoice/invoice_summary.rb +22 -0
- data/lib/paypal/invoice/invoice_summary_list.rb +10 -0
- data/lib/paypal/invoice/other_payment_details.rb +13 -0
- data/lib/paypal/invoice/payment_details.rb +16 -0
- data/lib/paypal/invoice/paypal_payment_details.rb +11 -0
- data/lib/paypal/invoice/request.rb +43 -0
- data/lib/paypal/invoice/response.rb +27 -0
- data/lib/paypal/invoice/response/details.rb +23 -0
- data/lib/paypal/invoice/response/invoice.rb +10 -0
- data/lib/paypal/invoice/response/search.rb +15 -0
- data/lib/paypal/invoice/search.rb +19 -0
- data/lib/paypal/invoice/search_parameters.rb +20 -0
- data/lib/paypal/permissions.rb +12 -0
- data/lib/paypal/permissions/api.rb +60 -0
- data/lib/paypal/permissions/base.rb +11 -0
- data/lib/paypal/permissions/permission.rb +33 -0
- data/lib/paypal/permissions/personal_data.rb +17 -0
- data/lib/paypal/permissions/request.rb +52 -0
- data/lib/paypal/permissions/response.rb +24 -0
- data/lib/paypal/permissions/response/permission.rb +14 -0
- data/lib/paypal/permissions/response/personal_data.rb +8 -0
- data/lib/paypal/permissions/response/token.rb +10 -0
- data/lib/paypal/permissions/token.rb +13 -0
- data/lib/paypal/recurring.rb +110 -0
- data/lib/paypal/request.rb +82 -0
- data/lib/paypal/version.rb +8 -0
- data/paypal-payment.gemspec +30 -0
- data/spec/fixtures/adaptive_payments/payment/create/failure.yml +62 -0
- data/spec/fixtures/adaptive_payments/payment/create/success.yml +58 -0
- data/spec/fixtures/adaptive_payments/payment/details/success.yml +113 -0
- data/spec/fixtures/adaptive_payments/payment/pay/failure.yml +62 -0
- data/spec/fixtures/adaptive_payments/payment/pay/preapproval.yml +58 -0
- data/spec/fixtures/adaptive_payments/payment/pay/success.yml +58 -0
- data/spec/fixtures/adaptive_payments/payment/pay/with_pay_key.yml +58 -0
- data/spec/fixtures/adaptive_payments/payment/refund/failure.yml +62 -0
- data/spec/fixtures/adaptive_payments/payment/refund/success.yml +58 -0
- data/spec/fixtures/adaptive_payments/payment/shipping_addresses/success.yml +113 -0
- data/spec/fixtures/adaptive_payments/payment_options/get/success.yml +174 -0
- data/spec/fixtures/adaptive_payments/payment_options/set/success.yml +113 -0
- data/spec/fixtures/adaptive_payments/preapproval/create/success.yml +58 -0
- data/spec/fixtures/adaptive_payments/preapproval/details/success.yml +168 -0
- data/spec/fixtures/express_checkout/account/balance/success.yml +32 -0
- data/spec/fixtures/express_checkout/account/pal_details/success.yml +32 -0
- data/spec/fixtures/express_checkout/checkout/checkout/sales/success.yml +61 -0
- data/spec/fixtures/express_checkout/checkout/checkout/success.yml +32 -0
- data/spec/fixtures/express_checkout/checkout/details/failure.yml +32 -0
- data/spec/fixtures/express_checkout/checkout/details/success.yml +61 -0
- data/spec/fixtures/express_checkout/checkout/pay/sales/success.yml +61 -0
- data/spec/fixtures/express_checkout/checkout/pay/success.yml +61 -0
- data/spec/fixtures/express_checkout/payment/details/failure.yml +32 -0
- data/spec/fixtures/express_checkout/payment/details/success.yml +32 -0
- data/spec/fixtures/express_checkout/payment/refund/failure.yml +32 -0
- data/spec/fixtures/express_checkout/payment/refund/success.yml +32 -0
- data/spec/fixtures/express_checkout/payment/search/success.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/cancel/failure.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/cancel/success.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/checkout/success.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/create_profile/failure.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/create_profile/success.yml +61 -0
- data/spec/fixtures/express_checkout/recurring/profile/failure.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/profile/success.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/reactivate/failure.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/reactivate/success.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/suspend/failure.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/suspend/success.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/update_profile/failure.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/update_profile/profile.yml +32 -0
- data/spec/fixtures/express_checkout/recurring/update_profile/success.yml +32 -0
- data/spec/fixtures/invoice/cancel/success.yml +174 -0
- data/spec/fixtures/invoice/create/failure.yml +62 -0
- data/spec/fixtures/invoice/create/success.yml +60 -0
- data/spec/fixtures/invoice/create_and_send/failure.yml +62 -0
- data/spec/fixtures/invoice/create_and_send/success.yml +60 -0
- data/spec/fixtures/invoice/details/success.yml +117 -0
- data/spec/fixtures/invoice/mark_as_paid/failure.yml +180 -0
- data/spec/fixtures/invoice/mark_as_paid/success.yml +174 -0
- data/spec/fixtures/invoice/mark_as_refunded/success.yml +174 -0
- data/spec/fixtures/invoice/mark_as_unpaid/success.yml +231 -0
- data/spec/fixtures/invoice/search/success.yml +174 -0
- data/spec/fixtures/invoice/send/success.yml +117 -0
- data/spec/fixtures/invoice/update/failure.yml +119 -0
- data/spec/fixtures/invoice/update/success.yml +117 -0
- data/spec/fixtures/ipn/express_checkout.json +35 -0
- data/spec/fixtures/ipn/recurring_payment.json +44 -0
- data/spec/fixtures/ipn/recurring_payment_profile_created.json +31 -0
- data/spec/fixtures/ipn/recurring_payment_profile_created_with_initial_amount.json +33 -0
- data/spec/fixtures/ipn/recurring_payment_skipped.json +30 -0
- data/spec/fixtures/ipn/recurring_payment_with_initial_amount.json +44 -0
- data/spec/fixtures/notification/failure.yml +50 -0
- data/spec/fixtures/notification/success.yml +50 -0
- data/spec/paypal/adaptive_payments/api_spec.rb +20 -0
- data/spec/paypal/adaptive_payments/payment/base_spec.rb +28 -0
- data/spec/paypal/adaptive_payments/payment/create_spec.rb +63 -0
- data/spec/paypal/adaptive_payments/payment/details_spec.rb +34 -0
- data/spec/paypal/adaptive_payments/payment/pay_spec.rb +97 -0
- data/spec/paypal/adaptive_payments/payment/refund_spec.rb +49 -0
- data/spec/paypal/adaptive_payments/payment/shipping_addresses_spec.rb +30 -0
- data/spec/paypal/adaptive_payments/payment_options/get_spec.rb +33 -0
- data/spec/paypal/adaptive_payments/payment_options/set_spec.rb +66 -0
- data/spec/paypal/adaptive_payments/preapproval/cancel_spec.rb +34 -0
- data/spec/paypal/adaptive_payments/preapproval/create_spec.rb +39 -0
- data/spec/paypal/adaptive_payments/preapproval/details_spec.rb +34 -0
- data/spec/paypal/adaptive_payments/request_spec.rb +48 -0
- data/spec/paypal/api_spec.rb +78 -0
- data/spec/paypal/common/base_spec.rb +157 -0
- data/spec/paypal/common/error_data_spec.rb +0 -0
- data/spec/paypal/common/request_envelope_spec.rb +6 -0
- data/spec/paypal/common/response_spec.rb +0 -0
- data/spec/paypal/express_checkout/account/balance_spec.rb +25 -0
- data/spec/paypal/express_checkout/account/pal_details_spec.rb +20 -0
- data/spec/paypal/express_checkout/checkout/checkout_spec.rb +73 -0
- data/spec/paypal/express_checkout/checkout/details_spec.rb +70 -0
- data/spec/paypal/express_checkout/checkout/pay_spec.rb +68 -0
- data/spec/paypal/express_checkout/fields_spec.rb +138 -0
- data/spec/paypal/express_checkout/payment/refund_spec.rb +34 -0
- data/spec/paypal/express_checkout/payment/search_spec.rb +24 -0
- data/spec/paypal/express_checkout/payment/transaction_details_spec.rb +30 -0
- data/spec/paypal/express_checkout/payment_spec.rb +13 -0
- data/spec/paypal/express_checkout/recurring/create_profile_spec.rb +50 -0
- data/spec/paypal/express_checkout/recurring/manage_profile_spec.rb +62 -0
- data/spec/paypal/express_checkout/recurring/profile_spec.rb +44 -0
- data/spec/paypal/express_checkout/recurring/update_profile_spec.rb +50 -0
- data/spec/paypal/express_checkout/request_spec.rb +221 -0
- data/spec/paypal/express_checkout/response/account_spec.rb +33 -0
- data/spec/paypal/express_checkout/response/base_spec.rb +253 -0
- data/spec/paypal/invoice/cancel_spec.rb +38 -0
- data/spec/paypal/invoice/create_and_send_spec.rb +58 -0
- data/spec/paypal/invoice/create_spec.rb +58 -0
- data/spec/paypal/invoice/details_spec.rb +39 -0
- data/spec/paypal/invoice/mark_as_paid_spec.rb +75 -0
- data/spec/paypal/invoice/mark_as_refunded_spec.rb +47 -0
- data/spec/paypal/invoice/mark_as_unpaid_spec.rb +43 -0
- data/spec/paypal/invoice/search_spec.rb +70 -0
- data/spec/paypal/invoice/send_spec.rb +48 -0
- data/spec/paypal/invoice/update_spec.rb +72 -0
- data/spec/paypal/request_spec.rb +45 -0
- data/spec/spec_helper.rb +35 -0
- metadata +546 -0
@@ -0,0 +1,33 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe PayPal::ExpressCheckout::Response::Account do
|
4
|
+
let(:response) { MockResponse.new(body_str) }
|
5
|
+
let(:body_str) { "ACK=Success&L_AMT0=10.0&L_CURRENCYCODE0=SGD&L_AMT1=20.0&L_CURRENCYCODE1=USD" }
|
6
|
+
|
7
|
+
describe "fields" do
|
8
|
+
subject { PayPal::ExpressCheckout::Response::Account.new(response) }
|
9
|
+
|
10
|
+
its(:methods) { should include(:ack) }
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#balances" do
|
14
|
+
|
15
|
+
subject { PayPal::ExpressCheckout::Response::Account.new(response) }
|
16
|
+
|
17
|
+
its(:balances) { should have(2).items }
|
18
|
+
it "first item should be the correct amount and currency" do
|
19
|
+
subject.balances.first.should eql(
|
20
|
+
{
|
21
|
+
:amount => 10.0, :currency => 'SGD'
|
22
|
+
}
|
23
|
+
)
|
24
|
+
end
|
25
|
+
it "last item should be the correct amount and currency" do
|
26
|
+
subject.balances.last.should eql(
|
27
|
+
{
|
28
|
+
:amount => 20.0, :currency => 'USD'
|
29
|
+
}
|
30
|
+
)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,253 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
class PaymentsTest < PayPal::ExpressCheckout::Response::Base
|
4
|
+
has_many :payments
|
5
|
+
end
|
6
|
+
class PaymentItemsTest < PayPal::ExpressCheckout::Response::Base
|
7
|
+
has_many :payment_items
|
8
|
+
end
|
9
|
+
class ShippingOptionsTest < PayPal::ExpressCheckout::Response::Base
|
10
|
+
has_many :shipping_options
|
11
|
+
end
|
12
|
+
class BillingsTest < PayPal::ExpressCheckout::Response::Base
|
13
|
+
has_many :billings
|
14
|
+
end
|
15
|
+
class FmfsTest < PayPal::ExpressCheckout::Response::Base
|
16
|
+
has_many :fmfs
|
17
|
+
end
|
18
|
+
|
19
|
+
shared_examples_for "setting the correct values" do
|
20
|
+
it "should set the correct values" do
|
21
|
+
subject.send(association).each_with_index do |item, index|
|
22
|
+
attribute_list.first.keys.each do |field|
|
23
|
+
items[index].send(field).should eql(item.send(field))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_item_str(items, prefix, suffix, attribute_list, item_fields)
|
30
|
+
items.each_with_index.map do |item, idx|
|
31
|
+
item_prefix = prefix.gsub(/n/, idx.to_s)
|
32
|
+
item_suffix = suffix.gsub(/n/, idx.to_s)
|
33
|
+
attribute_list.first.keys.map do |field|
|
34
|
+
"#{item_prefix}#{item_fields[field]}#{item_suffix}=#{item.send(field)}"
|
35
|
+
end.join("&")
|
36
|
+
end.join('&')
|
37
|
+
end
|
38
|
+
|
39
|
+
describe PayPal::ExpressCheckout::Response::Base do
|
40
|
+
let(:prefix) { "L_" }
|
41
|
+
let(:suffix) { "n" }
|
42
|
+
let(:response) { MockResponse.new(body_str) }
|
43
|
+
let(:body_str) { "ACK=Success&" + items_str }
|
44
|
+
let(:items) { attribute_list.map { |attributes| item_class.new(attributes) } }
|
45
|
+
let(:item_fields) { PayPal::ExpressCheckout::Fields::ASSOCIATIONS[association] }
|
46
|
+
let(:items_str) { build_item_str(items, prefix, suffix, attribute_list, item_fields) }
|
47
|
+
let(:payment_item_attribute_list) {
|
48
|
+
[
|
49
|
+
[
|
50
|
+
{
|
51
|
+
:item_url => "http://example.com/item/1",
|
52
|
+
:number => "1",
|
53
|
+
:name => "MacBook Air 11'",
|
54
|
+
:amount => "1150.0",
|
55
|
+
:currency => "USD",
|
56
|
+
:item_category => "Physical"
|
57
|
+
},
|
58
|
+
{
|
59
|
+
:item_url => "http://example.com/item/2",
|
60
|
+
:number => "2",
|
61
|
+
:name => "MacBook Air 13'",
|
62
|
+
:amount => "1350.0",
|
63
|
+
:currency => "USD",
|
64
|
+
:item_category => "Physical"
|
65
|
+
}
|
66
|
+
],
|
67
|
+
[
|
68
|
+
{
|
69
|
+
:item_url => "http://example.com/item/10",
|
70
|
+
:number => "1",
|
71
|
+
:name => "MacBook Pro 13'",
|
72
|
+
:amount => "1350.0",
|
73
|
+
:currency => "USD",
|
74
|
+
:item_category => "Physical"
|
75
|
+
},
|
76
|
+
{
|
77
|
+
:item_url => "http://example.com/item/11",
|
78
|
+
:number => "2",
|
79
|
+
:name => "MacBook Air 15'",
|
80
|
+
:amount => "1550.0",
|
81
|
+
:currency => "USD",
|
82
|
+
:item_category => "Physical"
|
83
|
+
}
|
84
|
+
],
|
85
|
+
[
|
86
|
+
{
|
87
|
+
:item_url => "http://example.com/item/20",
|
88
|
+
:number => "1",
|
89
|
+
:name => "iPad 2",
|
90
|
+
:amount => "550.0",
|
91
|
+
:currency => "USD",
|
92
|
+
:item_category => "Physical"
|
93
|
+
},
|
94
|
+
{
|
95
|
+
:item_url => "http://example.com/item/21",
|
96
|
+
:number => "2",
|
97
|
+
:name => "iPad mini'",
|
98
|
+
:amount => "350.0",
|
99
|
+
:currency => "USD",
|
100
|
+
:item_category => "Physical"
|
101
|
+
}
|
102
|
+
],
|
103
|
+
|
104
|
+
]
|
105
|
+
}
|
106
|
+
|
107
|
+
describe "#build_payments" do
|
108
|
+
let(:item_class) { PayPal::ExpressCheckout::Payment }
|
109
|
+
let(:association) { :payments }
|
110
|
+
let(:attribute_list) {
|
111
|
+
[
|
112
|
+
{ :amount => "2500.0", :currency => "USD", :payment_action => "Sale" },
|
113
|
+
{ :amount => "2900.0", :currency => "USD", :payment_action => "Sale" },
|
114
|
+
{ :amount => "900.0", :currency => "USD", :payment_action => "Sale" }
|
115
|
+
]
|
116
|
+
}
|
117
|
+
let(:prefix) { "PAYMENTREQUEST_n_" }
|
118
|
+
let(:suffix) { "" }
|
119
|
+
|
120
|
+
subject { PaymentsTest.new(response) }
|
121
|
+
|
122
|
+
its(:payments) { should have(3).items }
|
123
|
+
|
124
|
+
it_behaves_like "setting the correct values"
|
125
|
+
|
126
|
+
context "with payment_items" do
|
127
|
+
let(:payment_item_class) { PayPal::ExpressCheckout::PaymentItem }
|
128
|
+
let(:payment_items) {
|
129
|
+
payment_item_attribute_list.map do |group|
|
130
|
+
group.map { |attributes| payment_item_class.new(attributes) }
|
131
|
+
end
|
132
|
+
}
|
133
|
+
let(:payment_item_fields) { PayPal::ExpressCheckout::Fields::ASSOCIATIONS[:payment_items] }
|
134
|
+
let(:payment_item_suffix) { "n" }
|
135
|
+
let(:payment_item_str) {
|
136
|
+
items.each_with_index.map do |item, index|
|
137
|
+
build_item_str(
|
138
|
+
payment_items[index],
|
139
|
+
"L_#{prefix}".gsub(/n/, index.to_s),
|
140
|
+
payment_item_suffix,
|
141
|
+
payment_item_attribute_list[index],
|
142
|
+
payment_item_fields
|
143
|
+
)
|
144
|
+
end.join("&")
|
145
|
+
}
|
146
|
+
let(:items_str) {
|
147
|
+
build_item_str(items, prefix, suffix, attribute_list, item_fields) + "&" +
|
148
|
+
payment_item_str
|
149
|
+
}
|
150
|
+
|
151
|
+
subject { PaymentsTest.new(response) }
|
152
|
+
|
153
|
+
its(:payments) { should have(3).items }
|
154
|
+
|
155
|
+
it "should have payment items and set the correct values" do
|
156
|
+
subject.payments.each_with_index do |payment, index|
|
157
|
+
payment.payment_items.size.should eql(payment_items[index].size)
|
158
|
+
payment.payment_items.each_with_index do |payment_item, item_index|
|
159
|
+
item_attributes = payment_item_attribute_list[index][item_index]
|
160
|
+
item_attributes.keys.each do |key|
|
161
|
+
payment_item.send(key).should eql(payment_item_attribute_list[index][item_index][key])
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
describe "#build_shiping_options" do
|
170
|
+
let(:item_class) { PayPal::ExpressCheckout::ShippingOption }
|
171
|
+
let(:association) { :shipping_options }
|
172
|
+
let(:attribute_list) {
|
173
|
+
[
|
174
|
+
{ :is_default => "0", :name => "AIR", :amount => "25.0" },
|
175
|
+
{ :is_default => "1", :name => "SEA", :amount => "15.0" }
|
176
|
+
]
|
177
|
+
}
|
178
|
+
|
179
|
+
subject { ShippingOptionsTest.new(response) }
|
180
|
+
|
181
|
+
its(:shipping_options) { should have(2).items }
|
182
|
+
|
183
|
+
it_behaves_like "setting the correct values"
|
184
|
+
end
|
185
|
+
|
186
|
+
describe "#build_payment_items" do
|
187
|
+
let(:item_class) { PayPal::ExpressCheckout::PaymentItem }
|
188
|
+
let(:association) { :payment_items }
|
189
|
+
let(:attribute_list) { payment_item_attribute_list.first }
|
190
|
+
|
191
|
+
subject { PaymentItemsTest.new(response) }
|
192
|
+
|
193
|
+
its(:payment_items) { should have(2).items }
|
194
|
+
|
195
|
+
it_behaves_like "setting the correct values"
|
196
|
+
end
|
197
|
+
|
198
|
+
describe "#build_billings" do
|
199
|
+
let(:item_class) { PayPal::ExpressCheckout::Billing }
|
200
|
+
let(:association) { :billings }
|
201
|
+
let(:attribute_list) {
|
202
|
+
[
|
203
|
+
{
|
204
|
+
:type => "MerchantInitiatedBilling",
|
205
|
+
:description => "Info",
|
206
|
+
:payment_type => "Any"
|
207
|
+
},
|
208
|
+
{
|
209
|
+
:type => "MerchantInitiatedBillingSingleAgreement",
|
210
|
+
:description => "Info",
|
211
|
+
:payment_type => "InstantOnly"
|
212
|
+
},
|
213
|
+
]
|
214
|
+
}
|
215
|
+
|
216
|
+
subject { BillingsTest.new(response) }
|
217
|
+
|
218
|
+
its(:billings) { should have(2).items }
|
219
|
+
|
220
|
+
it_behaves_like "setting the correct values"
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "#fmfs" do
|
224
|
+
let(:item_class) { PayPal::ExpressCheckout::Fmf }
|
225
|
+
let(:association) { :fmfs }
|
226
|
+
let(:attribute_list) {
|
227
|
+
[
|
228
|
+
{
|
229
|
+
:pending_id => "1",
|
230
|
+
:pending_name => "pending name",
|
231
|
+
:report_id => "2",
|
232
|
+
:report_name => "report name",
|
233
|
+
:deny_id => "3",
|
234
|
+
:deny_name => "deny name"
|
235
|
+
},
|
236
|
+
{
|
237
|
+
:pending_id => "4",
|
238
|
+
:pending_name => "pending 2 name",
|
239
|
+
:report_id => "5",
|
240
|
+
:report_name => "report 2 name",
|
241
|
+
:deny_id => "6",
|
242
|
+
:deny_name => "deny 2 name"
|
243
|
+
}
|
244
|
+
]
|
245
|
+
}
|
246
|
+
|
247
|
+
subject { FmfsTest.new(response) }
|
248
|
+
|
249
|
+
its(:fmfs) { should have(2).items }
|
250
|
+
|
251
|
+
it_behaves_like "setting the correct values"
|
252
|
+
end
|
253
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include PayPal::Invoice
|
4
|
+
|
5
|
+
describe PayPal::Invoice::Invoice do
|
6
|
+
describe "#cancel" do
|
7
|
+
context "when successful" do
|
8
|
+
use_vcr_cassette "invoice/cancel/success"#, :record => :all
|
9
|
+
|
10
|
+
let(:invoice) {
|
11
|
+
PayPal::Invoice::Invoice.new(
|
12
|
+
:merchant_email => 'chardy_1345003248_per@gmail.com',
|
13
|
+
:payer_email => 'chardy_1345003165_per@gmail.com',
|
14
|
+
:item_list => {
|
15
|
+
:item => [
|
16
|
+
{
|
17
|
+
:name => 'iPhone 5',
|
18
|
+
:quantity => 1,
|
19
|
+
:unit_price => 1000.0
|
20
|
+
}
|
21
|
+
]
|
22
|
+
},
|
23
|
+
:currency_code => 'USD',
|
24
|
+
:payment_terms => 'Net30'
|
25
|
+
)
|
26
|
+
}
|
27
|
+
|
28
|
+
before do
|
29
|
+
invoice.create_and_send
|
30
|
+
end
|
31
|
+
|
32
|
+
subject { invoice.cancel }
|
33
|
+
|
34
|
+
its(:success?) { should be_true }
|
35
|
+
its(:valid?) { should be_true }
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include PayPal::Invoice
|
4
|
+
|
5
|
+
describe PayPal::Invoice::Invoice do
|
6
|
+
describe "#create_and_send" do
|
7
|
+
context "when successful" do
|
8
|
+
use_vcr_cassette "invoice/create_and_send/success"#, :record => :all
|
9
|
+
|
10
|
+
let(:invoice) {
|
11
|
+
PayPal::Invoice::Invoice.new(
|
12
|
+
:merchant_email => 'chardy_1345003248_per@gmail.com',
|
13
|
+
:payer_email => 'chardy_1345003165_per@gmail.com',
|
14
|
+
:item_list => {
|
15
|
+
:item => [
|
16
|
+
{
|
17
|
+
:name => 'iPhone 5',
|
18
|
+
:quantity => 1,
|
19
|
+
:unit_price => 1000.0
|
20
|
+
}
|
21
|
+
]
|
22
|
+
},
|
23
|
+
:currency_code => 'USD',
|
24
|
+
:payment_terms => 'Net30'
|
25
|
+
)
|
26
|
+
}
|
27
|
+
|
28
|
+
subject { invoice.create_and_send }
|
29
|
+
|
30
|
+
before { subject }
|
31
|
+
|
32
|
+
it "sets the invoice_id" do
|
33
|
+
invoice.invoice_id.should_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
its(:success?) { should be_true }
|
37
|
+
its(:valid?) { should be_true }
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when failure" do
|
41
|
+
use_vcr_cassette "invoice/create_and_send/failure"#, :record => :all
|
42
|
+
|
43
|
+
let(:invoice) {
|
44
|
+
PayPal::Invoice::Invoice.new(
|
45
|
+
:currency_code => 'USD'
|
46
|
+
)
|
47
|
+
}
|
48
|
+
|
49
|
+
subject { invoice.create_and_send }
|
50
|
+
|
51
|
+
before { subject }
|
52
|
+
|
53
|
+
its(:success?) { should be_false }
|
54
|
+
its(:valid?) { should be_false }
|
55
|
+
its(:errors) { should_not be_empty }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include PayPal::Invoice
|
4
|
+
|
5
|
+
describe PayPal::Invoice::Invoice do
|
6
|
+
describe "#create" do
|
7
|
+
context "when successful" do
|
8
|
+
use_vcr_cassette "invoice/create/success"#, :record => :all
|
9
|
+
|
10
|
+
let(:invoice) {
|
11
|
+
PayPal::Invoice::Invoice.new(
|
12
|
+
:merchant_email => 'chardy_1345003248_per@gmail.com',
|
13
|
+
:payer_email => 'chardy_1345003165_per@gmail.com',
|
14
|
+
:item_list => {
|
15
|
+
:item => [
|
16
|
+
{
|
17
|
+
:name => 'iPhone 5',
|
18
|
+
:quantity => 1,
|
19
|
+
:unit_price => 1000.0
|
20
|
+
}
|
21
|
+
]
|
22
|
+
},
|
23
|
+
:currency_code => 'USD',
|
24
|
+
:payment_terms => 'Net30'
|
25
|
+
)
|
26
|
+
}
|
27
|
+
|
28
|
+
subject { invoice.create }
|
29
|
+
|
30
|
+
before { subject }
|
31
|
+
|
32
|
+
it "sets the invoice_id" do
|
33
|
+
invoice.invoice_id.should_not be_nil
|
34
|
+
end
|
35
|
+
|
36
|
+
its(:success?) { should be_true }
|
37
|
+
its(:valid?) { should be_true }
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when failure" do
|
41
|
+
use_vcr_cassette "invoice/create/failure"#, :record => :all
|
42
|
+
|
43
|
+
let(:invoice) {
|
44
|
+
PayPal::Invoice::Invoice.new(
|
45
|
+
:currency_code => 'USD'
|
46
|
+
)
|
47
|
+
}
|
48
|
+
|
49
|
+
subject { invoice.create }
|
50
|
+
|
51
|
+
before { subject }
|
52
|
+
|
53
|
+
its(:success?) { should be_false }
|
54
|
+
its(:valid?) { should be_false }
|
55
|
+
its(:errors) { should_not be_empty }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
include PayPal::Invoice
|
4
|
+
|
5
|
+
describe PayPal::Invoice::Invoice do
|
6
|
+
describe "#details" do
|
7
|
+
context "when successful" do
|
8
|
+
use_vcr_cassette "invoice/details/success"#, :record => :all
|
9
|
+
|
10
|
+
let(:invoice) {
|
11
|
+
PayPal::Invoice::Invoice.new(
|
12
|
+
:merchant_email => 'chardy_1345003248_per@gmail.com',
|
13
|
+
:payer_email => 'chardy_1345003165_per@gmail.com',
|
14
|
+
:item_list => {
|
15
|
+
:item => [
|
16
|
+
{
|
17
|
+
:name => 'iPhone 5',
|
18
|
+
:quantity => 1,
|
19
|
+
:unit_price => 1000.0
|
20
|
+
}
|
21
|
+
]
|
22
|
+
},
|
23
|
+
:currency_code => 'USD',
|
24
|
+
:payment_terms => 'Net30'
|
25
|
+
)
|
26
|
+
}
|
27
|
+
|
28
|
+
before do
|
29
|
+
invoice.create_and_send
|
30
|
+
end
|
31
|
+
|
32
|
+
subject { invoice.details }
|
33
|
+
|
34
|
+
its(:success?) { should be_true }
|
35
|
+
its(:valid?) { should be_true }
|
36
|
+
its(:invoice_details) { should_not be_nil }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|