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,76 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
class Payment < PayPal::ExpressCheckout::Base
|
4
|
+
has_fields :payment, :ship_to, :amount, :payment_items, :credit_card, :payer, :address, :search, :refund, :seller
|
5
|
+
|
6
|
+
has_many :payment_items
|
7
|
+
|
8
|
+
def search
|
9
|
+
params = collect(
|
10
|
+
:start_date,
|
11
|
+
:end_date,
|
12
|
+
:amount,
|
13
|
+
:currency,
|
14
|
+
:email,
|
15
|
+
:receiver,
|
16
|
+
:receipt_id,
|
17
|
+
:account,
|
18
|
+
:invoice_num,
|
19
|
+
:transaction_id,
|
20
|
+
:transaction_class,
|
21
|
+
:auction_item_num,
|
22
|
+
:status,
|
23
|
+
:profile_id,
|
24
|
+
:salutation,
|
25
|
+
:first_name,
|
26
|
+
:middle_name,
|
27
|
+
:last_name,
|
28
|
+
:suffix
|
29
|
+
)
|
30
|
+
|
31
|
+
run(:search, params)
|
32
|
+
end
|
33
|
+
|
34
|
+
def update_status
|
35
|
+
params = collect(
|
36
|
+
:transaction_id,
|
37
|
+
:action
|
38
|
+
)
|
39
|
+
|
40
|
+
run(:update_status, params)
|
41
|
+
end
|
42
|
+
|
43
|
+
def refund
|
44
|
+
params = group_collect(
|
45
|
+
:transaction_id,
|
46
|
+
:amount,
|
47
|
+
:refund,
|
48
|
+
:msg_sub_id,
|
49
|
+
:store_id,
|
50
|
+
:terminal_id
|
51
|
+
)
|
52
|
+
|
53
|
+
run(:refund, params)
|
54
|
+
end
|
55
|
+
|
56
|
+
def reference
|
57
|
+
params = group_collect(
|
58
|
+
:payment,
|
59
|
+
:ship_to,
|
60
|
+
:amount,
|
61
|
+
:payment_items,
|
62
|
+
:credit_card,
|
63
|
+
:payer,
|
64
|
+
:address
|
65
|
+
)
|
66
|
+
|
67
|
+
run(:reference, params)
|
68
|
+
end
|
69
|
+
|
70
|
+
def details
|
71
|
+
params = collect(:transaction_id)
|
72
|
+
run(:transaction_details, params)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
class Recurring < PayPal::ExpressCheckout::Base
|
4
|
+
has_fields :recurring, :ship_to, :credit_card, :payer, :address, :refund
|
5
|
+
|
6
|
+
has_many :payment_items
|
7
|
+
|
8
|
+
# Suspend a recurring profile.
|
9
|
+
# Suspended profiles can be reactivated.
|
10
|
+
#
|
11
|
+
# ppr = PayPal::Recurring.new(:profile_id => "I-HYRKXBMNLFSK")
|
12
|
+
# response = ppr.suspend
|
13
|
+
#
|
14
|
+
def suspend
|
15
|
+
run(:manage_profile, :action => :suspend, :profile_id => profile_id)
|
16
|
+
end
|
17
|
+
|
18
|
+
# Reactivate a suspended recurring profile.
|
19
|
+
#
|
20
|
+
# ppr = PayPal::Recurring.new(:profile_id => "I-HYRKXBMNLFSK")
|
21
|
+
# response = ppr.reactivate
|
22
|
+
#
|
23
|
+
def reactivate
|
24
|
+
run(:manage_profile, :action => :reactivate, :profile_id => profile_id)
|
25
|
+
end
|
26
|
+
|
27
|
+
# Cancel a recurring profile.
|
28
|
+
# Cancelled profiles cannot be reactivated.
|
29
|
+
#
|
30
|
+
# ppr = PayPal::Recurring.new(:profile_id => "I-HYRKXBMNLFSK")
|
31
|
+
# response = ppr.cancel
|
32
|
+
#
|
33
|
+
def cancel
|
34
|
+
run(:manage_profile, :action => :cancel, :profile_id => profile_id)
|
35
|
+
end
|
36
|
+
|
37
|
+
# Create a recurring billing profile.
|
38
|
+
#
|
39
|
+
# ppr = PayPal::ExpressCheckout::Recurring.new({
|
40
|
+
# :amount => "9.00",
|
41
|
+
# :initial_amount => "9.00",
|
42
|
+
# :initial_amount_action => :cancel,
|
43
|
+
# :currency => "USD",
|
44
|
+
# :description => "Awesome - Monthly Subscription",
|
45
|
+
# :ipn_url => "http://example.com/paypal/ipn",
|
46
|
+
# :frequency => 1,
|
47
|
+
# :token => "EC-05C46042TU8306821",
|
48
|
+
# :period => :monthly,
|
49
|
+
# :reference => "1234",
|
50
|
+
# :payer_id => "WTTS5KC2T46YU",
|
51
|
+
# :start_at => Time.now,
|
52
|
+
# :failed => 1,
|
53
|
+
# :outstanding => :next_billing,
|
54
|
+
# :trial_period => :monthly,
|
55
|
+
# :trial_length => 1,
|
56
|
+
# :trial_frequency => 1,
|
57
|
+
# :trial_amount => 0.00
|
58
|
+
# })
|
59
|
+
#
|
60
|
+
# response = ppr.create_recurring_profile
|
61
|
+
#
|
62
|
+
def create_profile
|
63
|
+
params = group_collect(
|
64
|
+
:payment_items,
|
65
|
+
:recurring,
|
66
|
+
:payer
|
67
|
+
)
|
68
|
+
|
69
|
+
run(:create_profile, params)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Update a recurring billing profile.
|
73
|
+
#
|
74
|
+
# ppr = PayPal::ExpressCheckout::Recurring.new({
|
75
|
+
# :amount => "99.00",
|
76
|
+
# :currency => "USD",
|
77
|
+
# :description => "Awesome - Monthly Subscription",
|
78
|
+
# :note => "Changed plan to Gold",
|
79
|
+
# :ipn_url => "http://example.com/paypal/ipn",
|
80
|
+
# :reference => "1234",
|
81
|
+
# :profile_id => "I-VCEL6TRG35CU",
|
82
|
+
# :start_at => Time.now,
|
83
|
+
# :outstanding => :next_billing
|
84
|
+
# })
|
85
|
+
#
|
86
|
+
# response = ppr.update_recurring_profile
|
87
|
+
#
|
88
|
+
def update_profile
|
89
|
+
params = group_collect(
|
90
|
+
:recurring,
|
91
|
+
:credit_card,
|
92
|
+
:payer,
|
93
|
+
:address
|
94
|
+
)
|
95
|
+
|
96
|
+
run(:update_profile, params)
|
97
|
+
end
|
98
|
+
|
99
|
+
# Retrieve information about existing recurring profile.
|
100
|
+
#
|
101
|
+
# ppr = PayPal::ExpressCheckout::Recurring.new(:profile_id => "I-VCEL6TRG35CU")
|
102
|
+
# response = ppr.profile
|
103
|
+
#
|
104
|
+
def profile
|
105
|
+
run(:profile, :profile_id => profile_id)
|
106
|
+
end
|
107
|
+
|
108
|
+
def bill_outstanding
|
109
|
+
params = collect(
|
110
|
+
:profile_id,
|
111
|
+
:amount,
|
112
|
+
:note
|
113
|
+
)
|
114
|
+
|
115
|
+
run(:bill_outstanding, params)
|
116
|
+
end
|
117
|
+
|
118
|
+
# Retrive fixed options specific request action
|
119
|
+
|
120
|
+
# def fixed_options(request_action)
|
121
|
+
# {
|
122
|
+
# :checkout => {
|
123
|
+
# :payment_action => "Authorization",
|
124
|
+
# :no_shipping => 1,
|
125
|
+
# :L_BILLINGTYPE0 => "RecurringPayments"
|
126
|
+
# }
|
127
|
+
# }.fetch(request_action, {})
|
128
|
+
# end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,212 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
class Request < PayPal::Request
|
4
|
+
METHODS = {
|
5
|
+
:address_verify => "AddressVerify",
|
6
|
+
:authorize => "DoAuthorization",
|
7
|
+
:balance => "GetBalance",
|
8
|
+
:pal_details => "GetPalDetails",
|
9
|
+
:bill_outstanding => "BillOutstandingAmount",
|
10
|
+
:capture => "DoCapture",
|
11
|
+
:reauthorize => "DoReauthorization",
|
12
|
+
:checkout => "SetExpressCheckout",
|
13
|
+
:pay => "DoExpressCheckoutPayment",
|
14
|
+
:details => "GetExpressCheckoutDetails",
|
15
|
+
:create_profile => "CreateRecurringPaymentsProfile",
|
16
|
+
:profile => "GetRecurringPaymentsProfileDetails",
|
17
|
+
:manage_profile => "ManageRecurringPaymentsProfileStatus",
|
18
|
+
:update_profile => "UpdateRecurringPaymentsProfile",
|
19
|
+
:refund => "RefundTransaction",
|
20
|
+
:search => "TransactionSearch",
|
21
|
+
:update_status => "ManagePendingTransactionStatus",
|
22
|
+
:transaction_details => "GetTransactionDetails",
|
23
|
+
:reference => "DoReferenceTransaction",
|
24
|
+
:callback_response => "CallbackResponse"
|
25
|
+
}
|
26
|
+
|
27
|
+
INITIAL_AMOUNT_ACTIONS = {
|
28
|
+
:cancel => "CancelOnFailure",
|
29
|
+
:continue => "ContinueOnFailure"
|
30
|
+
}
|
31
|
+
|
32
|
+
ACTIONS = {
|
33
|
+
:accept => "Accept",
|
34
|
+
:deny => "Deny",
|
35
|
+
:cancel => "Cancel",
|
36
|
+
:suspend => "Suspend",
|
37
|
+
:reactivate => "Reactivate"
|
38
|
+
}
|
39
|
+
|
40
|
+
PERIOD = {
|
41
|
+
:daily => "Day",
|
42
|
+
:weekly => "Week",
|
43
|
+
:semi_monthly => "SemiMonth",
|
44
|
+
:monthly => "Month",
|
45
|
+
:yearly => "Year"
|
46
|
+
}
|
47
|
+
|
48
|
+
TRIAL_PERIOD = {
|
49
|
+
:daily => "Day",
|
50
|
+
:weekly => "Week",
|
51
|
+
:semi_monthly => "SemiMonth",
|
52
|
+
:monthly => "Month",
|
53
|
+
:yearly => "Year"
|
54
|
+
}
|
55
|
+
|
56
|
+
OUTSTANDING = {
|
57
|
+
:next_billing => "AddToNextBilling",
|
58
|
+
:no_auto => "NoAutoBill"
|
59
|
+
}
|
60
|
+
|
61
|
+
REFUND_TYPE = {
|
62
|
+
:full => "Full",
|
63
|
+
:partial => "Partial",
|
64
|
+
:external => "ExternalDispute",
|
65
|
+
:other => "Other"
|
66
|
+
}
|
67
|
+
|
68
|
+
def default_params
|
69
|
+
{
|
70
|
+
:USER => PayPal::ExpressCheckout::Api.username,
|
71
|
+
:PWD => PayPal::ExpressCheckout::Api.password,
|
72
|
+
:SIGNATURE => PayPal::ExpressCheckout::Api.signature,
|
73
|
+
:VERSION => PayPal::ExpressCheckout::Api.api_version
|
74
|
+
}
|
75
|
+
end
|
76
|
+
|
77
|
+
def field_map(object)
|
78
|
+
object.class.field_map
|
79
|
+
end
|
80
|
+
|
81
|
+
def normalize_params(object, params)
|
82
|
+
attributes = field_map(object)
|
83
|
+
params.inject({}) do |buffer, (name, value)|
|
84
|
+
attr_names = [attributes[name.to_sym]].flatten.compact
|
85
|
+
attr_names << name if attr_names.empty?
|
86
|
+
|
87
|
+
attr_names.each do |attr_name|
|
88
|
+
if (attr_name =~ /n/ or attr_name.is_a?(Hash)) and respond_to?("build_#{name}")
|
89
|
+
send("build_#{name}", attr_name, value, buffer)
|
90
|
+
else
|
91
|
+
buffer[attr_name.to_sym] = respond_to?("build_#{name}") ? send("build_#{name}", value) : value
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
buffer
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Parse current API url.
|
100
|
+
#
|
101
|
+
def uri # :nodoc:
|
102
|
+
@uri ||= PayPal::ExpressCheckout::Api.api_endpoint
|
103
|
+
end
|
104
|
+
|
105
|
+
def api_methods
|
106
|
+
METHODS
|
107
|
+
end
|
108
|
+
|
109
|
+
def run(object, method, params = {}, headers = {})
|
110
|
+
params = prepare_params(object, params.merge(:method => api_methods.fetch(method, method.to_s)))
|
111
|
+
headers = prepare_headers(headers)
|
112
|
+
response = post(params, headers)
|
113
|
+
PayPal::ExpressCheckout::Response.process(method, response)
|
114
|
+
end
|
115
|
+
|
116
|
+
def prepare_params(object, params) # :nodoc:
|
117
|
+
normalize_params(object, default_params.merge(params))
|
118
|
+
end
|
119
|
+
|
120
|
+
def build_period(value) # :nodoc:
|
121
|
+
PERIOD.fetch(value.to_sym, value) if value
|
122
|
+
end
|
123
|
+
|
124
|
+
def build_trial_period(value)
|
125
|
+
TRIAL_PERIOD.fetch(value.to_sym, value) if value
|
126
|
+
end
|
127
|
+
|
128
|
+
def build_start_at(value) # :nodoc:
|
129
|
+
build_time(value)
|
130
|
+
end
|
131
|
+
|
132
|
+
def build_start_date(value) # :nodoc:
|
133
|
+
build_time(value)
|
134
|
+
end
|
135
|
+
|
136
|
+
def build_end_date(value) # :nodoc:
|
137
|
+
build_time(value)
|
138
|
+
end
|
139
|
+
|
140
|
+
def build_auto_bill_outstanding(value) # :nodoc:
|
141
|
+
OUTSTANDING.fetch(value.to_sym, value) if value
|
142
|
+
end
|
143
|
+
|
144
|
+
def build_refund_type(value) # :nodoc:
|
145
|
+
REFUND_TYPE.fetch(value.to_sym, value) if value
|
146
|
+
end
|
147
|
+
|
148
|
+
def build_action(value) # :nodoc:
|
149
|
+
ACTIONS.fetch(value.to_sym, value) if value
|
150
|
+
end
|
151
|
+
|
152
|
+
def build_failed_initial_action(value) # :nodoc:
|
153
|
+
INITIAL_AMOUNT_ACTIONS.fetch(value.to_sym, value) if value
|
154
|
+
end
|
155
|
+
|
156
|
+
def build_locale(value) # :nodoc:
|
157
|
+
value.to_s.upcase
|
158
|
+
end
|
159
|
+
|
160
|
+
def build_survey_choices(attr_name, values, buffer)
|
161
|
+
Array(values).each_with_index do |value, idx|
|
162
|
+
buffer[attr_name.gsub(/n/, idx.to_s).to_sym] = value
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
def build_time(value)
|
167
|
+
if value.respond_to?(:strftime)
|
168
|
+
value = value.utc if value.respond_to?(:utc)
|
169
|
+
value.strftime("%Y-%m-%dT%H:%M:%SZ")
|
170
|
+
else
|
171
|
+
value
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def build_shipping_options(attr_name, values, buffer)
|
176
|
+
build_object_array(attr_name, values, buffer, "L_", "n")
|
177
|
+
end
|
178
|
+
|
179
|
+
def build_billings(attr_name, values, buffer)
|
180
|
+
build_object_array(attr_name, values, buffer, "L_", "n")
|
181
|
+
end
|
182
|
+
|
183
|
+
def build_payments(attr_name, values, buffer)
|
184
|
+
build_object_array(attr_name, values, buffer, "PAYMENTREQUEST_n_")
|
185
|
+
Array(values).each_with_index do |payment, idx|
|
186
|
+
build_object_array(
|
187
|
+
PayPal::ExpressCheckout::Fields::ASSOCIATIONS[:payment_items],
|
188
|
+
payment.payment_items,
|
189
|
+
buffer,
|
190
|
+
"L_PAYMENTREQUEST_#{idx}_",
|
191
|
+
"n"
|
192
|
+
)
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
def build_payment_items(attr_name, values, buffer)
|
197
|
+
build_object_array(attr_name, values, buffer, "L_", "n")
|
198
|
+
end
|
199
|
+
|
200
|
+
def build_object_array(attr_name, values, buffer, prefix = "L_", suffix = nil)
|
201
|
+
Array(values).each_with_index do |value, idx|
|
202
|
+
attr_name.each do |attribute, name|
|
203
|
+
name = "#{prefix}#{name}#{suffix}"
|
204
|
+
unless (v = value.send(attribute)).nil?
|
205
|
+
buffer[name.gsub(/n/, idx.to_s).to_sym] = v
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
module Response
|
4
|
+
autoload :Base, "paypal/express_checkout/response/base"
|
5
|
+
autoload :Address, "paypal/express_checkout/response/address"
|
6
|
+
autoload :Account, "paypal/express_checkout/response/account"
|
7
|
+
autoload :Authorization, "paypal/express_checkout/response/authorization"
|
8
|
+
autoload :Capture, "paypal/express_checkout/response/capture"
|
9
|
+
autoload :Checkout, "paypal/express_checkout/response/checkout"
|
10
|
+
autoload :Details, "paypal/express_checkout/response/details"
|
11
|
+
autoload :Payment, "paypal/express_checkout/response/payment"
|
12
|
+
autoload :TransactionDetails, "paypal/express_checkout/response/transaction_details"
|
13
|
+
autoload :ManageProfile, "paypal/express_checkout/response/manage_profile"
|
14
|
+
autoload :Profile, "paypal/express_checkout/response/profile"
|
15
|
+
autoload :Refund, "paypal/express_checkout/response/refund"
|
16
|
+
autoload :Reference, "paypal/express_checkout/response/reference"
|
17
|
+
autoload :Search, "paypal/express_checkout/response/search"
|
18
|
+
autoload :CallbackRequest, "paypal/express_checkout/response/callback_request"
|
19
|
+
autoload :CallbackResponse, "paypal/express_checkout/response/callback_response"
|
20
|
+
|
21
|
+
RESPONDERS = {
|
22
|
+
:address_verify => "Address",
|
23
|
+
:balance => "Account",
|
24
|
+
:pal_details => "Account",
|
25
|
+
:authorize => "Authorization",
|
26
|
+
:reauthorize => "Authorization",
|
27
|
+
:void => "Authorization",
|
28
|
+
:capture => "Capture",
|
29
|
+
:checkout => "Checkout",
|
30
|
+
:pay => "Checkout",
|
31
|
+
:details => "Details",
|
32
|
+
:payment => "Payment",
|
33
|
+
:transaction_details => "TransactionDetails",
|
34
|
+
:update_status => "Payment",
|
35
|
+
:search => "Search",
|
36
|
+
:profile => "Profile",
|
37
|
+
:create_profile => "ManageProfile",
|
38
|
+
:manage_profile => "ManageProfile",
|
39
|
+
:update_profile => "ManageProfile",
|
40
|
+
:bill_outstanding => "ManageProfile",
|
41
|
+
:refund => "Refund",
|
42
|
+
:reference => "Reference",
|
43
|
+
:callback_response => "CallbackResponse"
|
44
|
+
}
|
45
|
+
|
46
|
+
def self.process(method, response)
|
47
|
+
response_class = PayPal::ExpressCheckout::Response.const_get(RESPONDERS[method])
|
48
|
+
response_class.new(response)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|