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,30 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
module Response
|
4
|
+
class Account < PayPal::ExpressCheckout::Response::Base
|
5
|
+
|
6
|
+
has_fields :account
|
7
|
+
# mapping(
|
8
|
+
# :pal => :PAL,
|
9
|
+
# :locale => :LOCALE
|
10
|
+
# )
|
11
|
+
|
12
|
+
def balances
|
13
|
+
@balances ||= begin
|
14
|
+
index = 0
|
15
|
+
[].tap do |balances|
|
16
|
+
while params["L_AMT#{index}"]
|
17
|
+
balances << {
|
18
|
+
:amount => params["L_AMT#{index}"].to_f,
|
19
|
+
:currency => params["L_CURRENCYCODE#{index}"]
|
20
|
+
}
|
21
|
+
|
22
|
+
index += 1
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
module Response
|
4
|
+
class Address < PayPal::ExpressCheckout::Response::Base
|
5
|
+
|
6
|
+
has_fields :address
|
7
|
+
# mapping(
|
8
|
+
# :confirmation => :CONFIRMATIONCODE,
|
9
|
+
# :street_match => :STREETMATCH,
|
10
|
+
# :zip_match => :ZIPMATCH,
|
11
|
+
# :country => :COUNTRYCODE
|
12
|
+
# :token => :TOKEN,
|
13
|
+
# )
|
14
|
+
|
15
|
+
def confirmed?
|
16
|
+
confirmation == 'Confirmed'
|
17
|
+
end
|
18
|
+
|
19
|
+
def street_matched?
|
20
|
+
street_match == 'Matched'
|
21
|
+
end
|
22
|
+
|
23
|
+
def zip_matched?
|
24
|
+
zip_match == 'Matched'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
module Response
|
4
|
+
class Authorization < Base
|
5
|
+
has_fields :payment, :amount
|
6
|
+
|
7
|
+
# mapping(
|
8
|
+
# :authorization_id => :AUTHORIZATIONID,
|
9
|
+
# :transaction_id => :TRANSACTIONID,
|
10
|
+
# :amount => :AMT,
|
11
|
+
# :msg_sub_id => :MSGSUBID,
|
12
|
+
# :payment_status => :PAYMENTSTATUS,
|
13
|
+
# :pending_reason => :PENDINGREASON,
|
14
|
+
# :protection_eligibility => :PROTECTIONELIGIBILITY,
|
15
|
+
# :protection_eligibility_type => :PROTECTIONELIGIBILITYTYPE
|
16
|
+
# )
|
17
|
+
|
18
|
+
def pending?
|
19
|
+
payment_status == 'Pending'
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
module Response
|
4
|
+
class Base
|
5
|
+
include PayPal::ExpressCheckout::Fields
|
6
|
+
extend PayPal::ExpressCheckout::Utils
|
7
|
+
|
8
|
+
attr_accessor :response
|
9
|
+
|
10
|
+
has_fields :response
|
11
|
+
|
12
|
+
def initialize(response = nil)
|
13
|
+
@response = response
|
14
|
+
build_values
|
15
|
+
end
|
16
|
+
|
17
|
+
def params
|
18
|
+
@params ||= CGI.parse(response.body_str).inject({}) do |buffer, (name, value)|
|
19
|
+
buffer.merge(name => value.first)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def build_values
|
24
|
+
params.each_pair do |key, value|
|
25
|
+
unless key.to_s =~ /^L\_|\_(\d)+\_/
|
26
|
+
attr_name = inverted_field_map[key.to_s]
|
27
|
+
if respond_to?("#{attr_name}=")
|
28
|
+
value = send("build_#{attr_name}", value) if respond_to?("build_#{attr_name}")
|
29
|
+
send("#{attr_name}=", value)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
self.class.associations.each do |association|
|
34
|
+
if respond_to?("build_#{association}")
|
35
|
+
send("build_#{association}")
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def build_payments(prefix='PAYMENTREQUEST_n_', suffix='')
|
41
|
+
build_association(
|
42
|
+
:payments,
|
43
|
+
PayPal::ExpressCheckout::Payment,
|
44
|
+
:amount,
|
45
|
+
prefix,
|
46
|
+
suffix
|
47
|
+
).each_with_index do |p, index|
|
48
|
+
build_payment_items("L_#{prefix}".gsub(/n/, index.to_s), "n", p)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def build_payment_items(prefix="L_", suffix="n", object=self)
|
53
|
+
build_association(:payment_items, PayPal::ExpressCheckout::PaymentItem, :amount, prefix, suffix, object)
|
54
|
+
end
|
55
|
+
|
56
|
+
def build_shipping_options(prefix="L_", suffix="n")
|
57
|
+
build_association(:shipping_options, PayPal::ExpressCheckout::ShippingOption, :name, prefix, suffix)
|
58
|
+
end
|
59
|
+
|
60
|
+
def build_billings(prefix="L_", suffix="n")
|
61
|
+
build_association(:billings, PayPal::ExpressCheckout::Billing, :type, prefix, suffix)
|
62
|
+
end
|
63
|
+
|
64
|
+
def build_fmfs(prefix="L_", suffix="n")
|
65
|
+
build_association(:fmfs, PayPal::ExpressCheckout::Fmf, [:pending_id, :report_id, :deny_id], prefix, suffix)
|
66
|
+
end
|
67
|
+
|
68
|
+
def build_association(association, association_class, initial_fields, prefix="L_", suffix="n", object=self)
|
69
|
+
initial_fields = Array(initial_fields)
|
70
|
+
detection_fields = ASSOCIATIONS[association].map{|k,v| initial_fields.include?(k) ? v : nil}.compact
|
71
|
+
index = 0
|
72
|
+
index_prefix = prefix.gsub(/n/, index.to_s)
|
73
|
+
index_suffix = suffix.gsub(/n/, index.to_s)
|
74
|
+
while detection_fields.inject(false) { |memo, field| memo || params["#{index_prefix}#{field}#{index_suffix}"] }
|
75
|
+
attributes = {}
|
76
|
+
ASSOCIATIONS[association].invert.each do |name, method|
|
77
|
+
build_method = "build_#{method}"
|
78
|
+
value = params["#{index_prefix}#{name}#{index_suffix}"]
|
79
|
+
attributes[method] = object.respond_to?(build_method) ? object.send(build_method, value) : value
|
80
|
+
end
|
81
|
+
object.send("#{association}").send("<<", association_class.new(attributes))
|
82
|
+
index += 1
|
83
|
+
index_prefix = prefix.gsub(/n/, index.to_s)
|
84
|
+
index_suffix = suffix.gsub(/n/, index.to_s)
|
85
|
+
end
|
86
|
+
object.send(association)
|
87
|
+
end
|
88
|
+
|
89
|
+
def errors
|
90
|
+
@errors ||= begin
|
91
|
+
index = 0
|
92
|
+
[].tap do |errors|
|
93
|
+
while params["L_ERRORCODE#{index}"]
|
94
|
+
errors << {
|
95
|
+
:code => params["L_ERRORCODE#{index}"],
|
96
|
+
:messages => [
|
97
|
+
params["L_SHORTMESSAGE#{index}"],
|
98
|
+
params["L_LONGMESSAGE#{index}"]
|
99
|
+
]
|
100
|
+
}
|
101
|
+
|
102
|
+
index += 1
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
def success?
|
109
|
+
ack == "Success"
|
110
|
+
end
|
111
|
+
|
112
|
+
def valid?
|
113
|
+
errors.empty? && success?
|
114
|
+
end
|
115
|
+
|
116
|
+
protected
|
117
|
+
|
118
|
+
def build_requested_at(stamp) # :nodoc:
|
119
|
+
Time.parse(stamp)
|
120
|
+
end
|
121
|
+
alias_method :build_timpstamp, :build_requested_at
|
122
|
+
end
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
module Response
|
4
|
+
class Details < Base
|
5
|
+
has_fields :checkout, :giro, :gift, :survey, :buyer, :tax, :payer
|
6
|
+
|
7
|
+
has_many :payments
|
8
|
+
|
9
|
+
def payment
|
10
|
+
@payment ||= payments.first
|
11
|
+
end
|
12
|
+
|
13
|
+
def notify_url
|
14
|
+
payment && payment.notify_url
|
15
|
+
end
|
16
|
+
|
17
|
+
def amount
|
18
|
+
payment && payment.amount
|
19
|
+
end
|
20
|
+
|
21
|
+
def description
|
22
|
+
payment && payment.description
|
23
|
+
end
|
24
|
+
|
25
|
+
def currency
|
26
|
+
payment && payment.currency
|
27
|
+
end
|
28
|
+
|
29
|
+
def agreed?
|
30
|
+
params["BILLINGAGREEMENTACCEPTEDSTATUS"] == "1"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
module Response
|
4
|
+
class Notification < PayPal::ExpressCheckout::Response::Base
|
5
|
+
|
6
|
+
attr_reader :params
|
7
|
+
|
8
|
+
mapping({
|
9
|
+
:type => :txn_type,
|
10
|
+
:transaction_id => :txn_id,
|
11
|
+
:fee => [:mc_fee, :payment_fee],
|
12
|
+
:reference => [:rp_invoice_id, :custom, :invoice],
|
13
|
+
:payment_id => :recurring_payment_id,
|
14
|
+
:amount => [:amount, :mc_gross, :payment_gross],
|
15
|
+
:currency => :mc_currency,
|
16
|
+
:status => :payment_status,
|
17
|
+
:pending_reason => :pending_reason,
|
18
|
+
:profile_status => :profile_status,
|
19
|
+
:payment_date => :payment_date,
|
20
|
+
:time_created => :time_created,
|
21
|
+
:seller_id => :receiver_id,
|
22
|
+
:email => :receiver_email,
|
23
|
+
:initial_amount => :initial_payment_amount,
|
24
|
+
:payer_email => :payer_email
|
25
|
+
})
|
26
|
+
|
27
|
+
def initialize(params = {})
|
28
|
+
self.params = params
|
29
|
+
end
|
30
|
+
|
31
|
+
def params=(params)
|
32
|
+
@params = params.inject({}) do |buffer, (name,value)|
|
33
|
+
buffer.merge(name.to_sym => value)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def express_checkout?
|
38
|
+
type == "express_checkout"
|
39
|
+
end
|
40
|
+
|
41
|
+
def recurring_payment?
|
42
|
+
type == "recurring_payment"
|
43
|
+
end
|
44
|
+
|
45
|
+
def recurring_payment_profile?
|
46
|
+
type == "recurring_payment_profile_created"
|
47
|
+
end
|
48
|
+
|
49
|
+
def request
|
50
|
+
@request ||= PayPal::Recurring::Request.new.tap do |request|
|
51
|
+
request.uri = URI.parse("#{PayPal::Recurring.site_endpoint}?cmd=_notify-validate")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def response
|
56
|
+
@response ||= request.post(params.merge(:cmd => "_notify-validate"))
|
57
|
+
end
|
58
|
+
|
59
|
+
def valid?
|
60
|
+
completed? && verified? && email == PayPal::Recurring.email && seller_id == PayPal::Recurring.seller_id
|
61
|
+
end
|
62
|
+
|
63
|
+
def completed?
|
64
|
+
status == "Completed"
|
65
|
+
end
|
66
|
+
|
67
|
+
def next_payment_date
|
68
|
+
self.class.convert_to_time(params[:next_payment_date]) if params[:next_payment_date]
|
69
|
+
end
|
70
|
+
|
71
|
+
def paid_at
|
72
|
+
self.class.convert_to_time(payment_date) if payment_date
|
73
|
+
end
|
74
|
+
|
75
|
+
def created_at
|
76
|
+
self.class.convert_to_time(time_created) if time_created
|
77
|
+
end
|
78
|
+
|
79
|
+
def verified?
|
80
|
+
response.body == "VERIFIED"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
module Response
|
4
|
+
class Payment < PayPal::ExpressCheckout::Response::Base
|
5
|
+
mapping(
|
6
|
+
:status => :PAYMENTINFO_0_PAYMENTSTATUS,
|
7
|
+
:amount => :PAYMENTINFO_0_AMT,
|
8
|
+
:fees => :PAYMENTINFO_0_FEEAMT,
|
9
|
+
:transaction_id => :PAYMENTINFO_0_TRANSACTIONID,
|
10
|
+
:seller_id => :PAYMENTINFO_0_SECUREMERCHANTACCOUNTID,
|
11
|
+
:reference => [:PROFILEREFERENCE, :PAYMENTREQUEST_0_CUSTOM, :PAYMENTREQUEST_0_INVNUM]
|
12
|
+
)
|
13
|
+
|
14
|
+
def completed?
|
15
|
+
params[:PAYMENTINFO_0_PAYMENTSTATUS] == "Completed"
|
16
|
+
end
|
17
|
+
|
18
|
+
def approved?
|
19
|
+
params[:PAYMENTINFO_0_ACK] == "Success"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
module Response
|
4
|
+
class Profile < PayPal::ExpressCheckout::Response::Base
|
5
|
+
has_fields :recurring, :amount, :ship_to, :credit_card, :payer, :address
|
6
|
+
|
7
|
+
OUTSTANDING = {
|
8
|
+
"AddToNextBilling" => :next_billing,
|
9
|
+
"NoAutoBill" => :no_auto_bill
|
10
|
+
}
|
11
|
+
|
12
|
+
STATUS = {
|
13
|
+
"Cancelled" => :cancelled,
|
14
|
+
"Active" => :active,
|
15
|
+
"Suspended" => :suspended
|
16
|
+
}
|
17
|
+
|
18
|
+
PERIOD = {
|
19
|
+
"Month" => :monthly,
|
20
|
+
"Weekly" => :weekly,
|
21
|
+
"Year" => :yearly,
|
22
|
+
"Day" => :daily
|
23
|
+
}
|
24
|
+
|
25
|
+
def active?
|
26
|
+
status == :active
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_auto_bill_outstanding(value)
|
30
|
+
OUTSTANDING.fetch(value, value)
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_status(value)
|
34
|
+
STATUS.fetch(value, value)
|
35
|
+
end
|
36
|
+
|
37
|
+
def build_date(string)
|
38
|
+
Time.parse(string)
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_start_at(string)
|
42
|
+
Time.parse(string)
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_last_payment_date(string)
|
46
|
+
Time.parse(string)
|
47
|
+
end
|
48
|
+
|
49
|
+
def build_period(value)
|
50
|
+
PERIOD.fetch(value, value)
|
51
|
+
end
|
52
|
+
|
53
|
+
alias_method :build_start_at, :build_date
|
54
|
+
alias_method :build_last_payment_date, :build_date
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|