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
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color --format documentation
|
data/Gemfile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'curb'
|
4
|
+
gem 'oj'
|
5
|
+
gem 'multi_json'
|
6
|
+
|
7
|
+
group :development, :test do
|
8
|
+
gem 'rspec'
|
9
|
+
gem 'guard-rspec'
|
10
|
+
gem 'rb-fsevent', '~> 0.9'
|
11
|
+
gem 'rake'
|
12
|
+
gem 'vcr'
|
13
|
+
gem 'fakeweb'
|
14
|
+
gem 'webmock', '1.8.11'
|
15
|
+
gem 'pry'
|
16
|
+
gem 'awesome_print'
|
17
|
+
gem 'activesupport'
|
18
|
+
end
|
data/Guardfile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard 'rspec', :version => 2 do
|
5
|
+
watch(%r{^spec/.+_spec\.rb$})
|
6
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
7
|
+
watch('spec/spec_helper.rb') { "spec" }
|
8
|
+
|
9
|
+
# Rails example
|
10
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
11
|
+
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
12
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
13
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
14
|
+
watch('config/routes.rb') { "spec/routing" }
|
15
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
16
|
+
|
17
|
+
# Capybara request specs
|
18
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
|
19
|
+
|
20
|
+
# Turnip features and steps
|
21
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
22
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
23
|
+
end
|
24
|
+
|
data/README.rdoc
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
= PayPal Payment
|
2
|
+
|
3
|
+
PayPal API Client for Adaptive Payments, Invoice and Express Checkout.
|
4
|
+
|
5
|
+
== Installation (Gemfile)
|
6
|
+
|
7
|
+
gem 'paypal-payment', :git => 'https://github.com/chardy/paypal-payment.git'
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
First, you need to set up your credentials:
|
12
|
+
|
13
|
+
require "paypal-payment"
|
14
|
+
|
15
|
+
PayPal::Api.configure do |config|
|
16
|
+
config.sandbox = true
|
17
|
+
config.username = "chardy_api1.gmail.com"
|
18
|
+
config.password = "8DTSWBZC7GDR3T4X"
|
19
|
+
config.signature = "AG-8mOpuFhFyFOYHlaTUYn3Syf15AWJKRnfHMVsmCtC3DK51-ENEPqLS"
|
20
|
+
end
|
21
|
+
|
22
|
+
== Adaptive Payments
|
23
|
+
|
24
|
+
You can request a new preapproval authorization:
|
25
|
+
pa = PayPal::AdaptivePayments::Preapproval.new(
|
26
|
+
:client_details => {
|
27
|
+
:ip_address => "234.8.8.18",
|
28
|
+
:device_id => "123456",
|
29
|
+
:application_id => "PP"
|
30
|
+
},
|
31
|
+
:starting_date => Date.today,
|
32
|
+
:currency_code => 'USD',
|
33
|
+
:max_total_amount_of_all_payments => 2000.0,
|
34
|
+
:cancel_url => 'http://yoursite.com/preapproval/cancel?preapprovalkey=${preapprovalkey}',
|
35
|
+
:return_url => 'http://yoursite.com/preapproval/accepted?preapprovalkey=${preapprovalkey}'
|
36
|
+
)
|
37
|
+
|
38
|
+
response = pa.create
|
39
|
+
puts response.preapproval_url if response.valid?
|
40
|
+
|
41
|
+
You need to redirect your user to the url returned by <tt>response.approval_url</tt>.
|
42
|
+
After the user accepts or rejects your preapproval request, he will be redirected to one of those urls you specified.
|
43
|
+
Note that you need to append "preapprovalkey=${preapprovalkey}" to the urls if you want PayPal to redirect with preapprovalkey
|
44
|
+
You can use the <tt>preapprovalkey</tt> parameter to query for the approval details.
|
45
|
+
|
46
|
+
If you need to retrieve information about your buyer, like address or e-mail, you can use the
|
47
|
+
<tt>details()</tt> method.
|
48
|
+
|
49
|
+
pa = PayPal::AdaptivePayments::Preapproval.new(:preapproval_key => "PA-89578182UL033944H")
|
50
|
+
response = pa.details
|
51
|
+
|
52
|
+
When you need to request payment, create a new Payment with the preapproval key.
|
53
|
+
|
54
|
+
pp = PayPal::AdaptivePayments::Payment.new(
|
55
|
+
:preapproval_key => "PA-89578182UL033944H",
|
56
|
+
:receiver => {:email => "seller@example.com", :amount => 10.0},
|
57
|
+
:currency_code => 'USD',
|
58
|
+
:cancel_url => 'http://example.com/cancel',
|
59
|
+
:return_url => 'http://example.com/thank_you'
|
60
|
+
)
|
61
|
+
|
62
|
+
response = pp.pay
|
63
|
+
response.success?
|
64
|
+
response.completed?
|
65
|
+
|
66
|
+
You can manage your preapproval.
|
67
|
+
|
68
|
+
pa = PayPal::AdaptivePayments::Preapproval.new(:preapproval_key => "PA-89578182UL033944H")
|
69
|
+
pa.cancel
|
70
|
+
|
71
|
+
=== What information do I need to keep?
|
72
|
+
|
73
|
+
You should save two paramaters to your database: <tt>TOKEN</tt> and <tt>PROFILEID</tt>.
|
74
|
+
<tt>TOKEN</tt> is required when user returns to your website after he authorizes (or not) the billing process. You
|
75
|
+
need to save it so you can find him later. You can remove this info after payment and recurring profile are set.
|
76
|
+
|
77
|
+
The <tt>PROFILEID</tt> allows you to manage the recurring profile, like cancelling billing when an user don't
|
78
|
+
want to use your service anymore.
|
79
|
+
|
80
|
+
<b>NOTE:</b> TOKEN will expire after approximately 3 hours.
|
81
|
+
|
82
|
+
== Maintainer
|
83
|
+
|
84
|
+
* Chardy Wang
|
85
|
+
|
86
|
+
== License
|
87
|
+
|
88
|
+
(The MIT License)
|
89
|
+
|
90
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
91
|
+
a copy of this software and associated documentation files (the
|
92
|
+
'Software'), to deal in the Software without restriction, including
|
93
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
94
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
95
|
+
permit persons to whom the Software is furnished to do so, subject to
|
96
|
+
the following conditions:
|
97
|
+
|
98
|
+
The above copyright notice and this permission notice shall be
|
99
|
+
included in all copies or substantial portions of the Software.
|
100
|
+
|
101
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
102
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
103
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
104
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
105
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
106
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
107
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
= PayPal Payment
|
2
|
+
|
3
|
+
PayPal API Client for Adaptive Payments, Invoice and Express Checkout.
|
4
|
+
|
5
|
+
== Installation (Gemfile)
|
6
|
+
|
7
|
+
gem 'paypal-payment', :git => 'git://vendor@appcepted.com:/home/vendor/pp_paypal'
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
First, you need to set up your credentials:
|
12
|
+
|
13
|
+
require "paypal-payment"
|
14
|
+
|
15
|
+
PayPal::Api.configure do |config|
|
16
|
+
config.sandbox = true
|
17
|
+
config.username = "chardy_api1.gmail.com"
|
18
|
+
config.password = "8DTSWBZC7GDR3T4X"
|
19
|
+
config.signature = "AG-8mOpuFhFyFOYHlaTUYn3Syf15AWJKRnfHMVsmCtC3DK51-ENEPqLS"
|
20
|
+
end
|
21
|
+
|
22
|
+
== Adaptive Payments
|
23
|
+
|
24
|
+
You can request a new preapproval authorization:
|
25
|
+
pa = PayPal::AdaptivePayments::Preapproval.new(
|
26
|
+
:client_details => {
|
27
|
+
:ip_address => "234.8.8.18",
|
28
|
+
:device_id => "123456",
|
29
|
+
:application_id => "PP"
|
30
|
+
},
|
31
|
+
:starting_date => Date.today,
|
32
|
+
:currency_code => 'USD',
|
33
|
+
:max_total_amount_of_all_payments => 2000.0,
|
34
|
+
:cancel_url => 'http://yoursite.com/preapproval/cancel?preapprovalkey=${preapprovalkey}',
|
35
|
+
:return_url => 'http://yoursite.com/preapproval/accepted?preapprovalkey=${preapprovalkey}'
|
36
|
+
)
|
37
|
+
|
38
|
+
response = pa.create
|
39
|
+
puts response.approval_url if response.valid?
|
40
|
+
|
41
|
+
You need to redirect your user to the url returned by <tt>response.approval_url</tt>.
|
42
|
+
After the user accepts or rejects your preapproval request, he will be redirected to one of those urls you specified.
|
43
|
+
Note that you need to append "preapprovalkey=${preapprovalkey}" to the urls if you want PayPal to redirect with preapprovalkey
|
44
|
+
You can use the <tt>preapprovalkey</tt> parameter to query for the approval details.
|
45
|
+
|
46
|
+
If you need to retrieve information about your buyer, like address or e-mail, you can use the
|
47
|
+
<tt>details()</tt> method.
|
48
|
+
|
49
|
+
pa = PayPal::AdaptivePayments::Preapproval.new(:preapproval_key => "PA-89578182UL033944H")
|
50
|
+
response = pa.details
|
51
|
+
|
52
|
+
When you need to request payment, create a new Payment with the preapproval key.
|
53
|
+
|
54
|
+
pp = PayPal::AdaptivePayments::Payment.new(
|
55
|
+
:preapproval_key => "PA-89578182UL033944H",
|
56
|
+
:receiver => {:email => "seller@example.com", :amount => 10.0},
|
57
|
+
:currency_code => 'USD',
|
58
|
+
:cancel_url => 'http://example.com/cancel',
|
59
|
+
:return_url => 'http://example.com/thank_you'
|
60
|
+
)
|
61
|
+
|
62
|
+
response = pp.pay
|
63
|
+
response.success?
|
64
|
+
response.completed?
|
65
|
+
|
66
|
+
You can manage your preapproval.
|
67
|
+
|
68
|
+
pa = PayPal::AdaptivePayments::Preapproval.new(:preapproval_key => "PA-89578182UL033944H")
|
69
|
+
pa.cancel
|
70
|
+
|
71
|
+
=== What information do I need to keep?
|
72
|
+
|
73
|
+
You should save two paramaters to your database: <tt>TOKEN</tt> and <tt>PROFILEID</tt>.
|
74
|
+
<tt>TOKEN</tt> is required when user returns to your website after he authorizes (or not) the billing process. You
|
75
|
+
need to save it so you can find him later. You can remove this info after payment and recurring profile are set.
|
76
|
+
|
77
|
+
The <tt>PROFILEID</tt> allows you to manage the recurring profile, like cancelling billing when an user don't
|
78
|
+
want to use your service anymore.
|
79
|
+
|
80
|
+
<b>NOTE:</b> TOKEN will expire after approximately 3 hours.
|
81
|
+
|
82
|
+
== Maintainer
|
83
|
+
|
84
|
+
* Chardy Wang
|
Binary file
|
Binary file
|
@@ -0,0 +1,55 @@
|
|
1
|
+
# How to Set Up a Payment Preapproval Using Adaptive Payments
|
2
|
+
|
3
|
+
https://www.x.com/developers/paypal/documentation-tools/adaptive-payments/how-to/ht_ap-basicPreapproval-curl-etc
|
4
|
+
|
5
|
+
Setting up a payment preapproval using Adaptive Payments requires:
|
6
|
+
|
7
|
+
1. Setting up the preapproval.
|
8
|
+
2. Redirecting the customer to PayPal for authorization.
|
9
|
+
3. Optionally, retrieving data about the preapproval.
|
10
|
+
4. Optionally, capturing a future payment.
|
11
|
+
|
12
|
+
When you use Adaptive Payments to set up payment preapprovals, the payment amounts can vary frequently.
|
13
|
+
|
14
|
+
Step 1: Set Up the Preapproval
|
15
|
+
|
16
|
+
pp = PayPal::AdaptivePayments::Preapproval.new(
|
17
|
+
:starting_date => Date.today,
|
18
|
+
:ending_date => Date.today >> 12,
|
19
|
+
:max_amount_per_payment => 35.0,
|
20
|
+
:max_number_of_payments => 20,
|
21
|
+
:max_total_amount_of_all_payments => 2000.0,
|
22
|
+
:cancel_url => 'http://www.yourdomain.com/success.html',
|
23
|
+
:return_url => 'http://www.yourdomain.com/cancel.html',
|
24
|
+
:currency_code => 'USD'
|
25
|
+
)
|
26
|
+
|
27
|
+
response = pp.create
|
28
|
+
|
29
|
+
Step 2: Redirect the Customer to PayPal for Authorization
|
30
|
+
|
31
|
+
To get the preapproval url
|
32
|
+
|
33
|
+
response.preapproval_url
|
34
|
+
|
35
|
+
Step 3: Retrieve Data about the Preapproval (Optional)
|
36
|
+
|
37
|
+
details = pp.details
|
38
|
+
|
39
|
+
Or
|
40
|
+
|
41
|
+
details = PayPal::AdaptivePayments::Preapproval.new(:preapproval_key => pp.preapproval_key).details
|
42
|
+
|
43
|
+
Step 4: Capture a Future Payment (Optional)
|
44
|
+
|
45
|
+
pp = PayPal::AdaptivePayments::Payment.new(
|
46
|
+
:preapproval_key => preapproval_key,
|
47
|
+
:receiver => { :amount => 10.0, :email => "test@example.com" },
|
48
|
+
:currency_code => 'USD',
|
49
|
+
:cancel_url => 'http://www.yourdomain.com/success.html',
|
50
|
+
:return_url => 'http://www.yourdomain.com/cancel.html'
|
51
|
+
)
|
52
|
+
|
53
|
+
pp.pay
|
54
|
+
|
55
|
+
|
data/docs/api.txt
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
Express Checkout
|
2
|
+
================
|
3
|
+
|
4
|
+
Implemented
|
5
|
+
===========
|
6
|
+
AddressVerify
|
7
|
+
BillOutstandingAmount
|
8
|
+
DoAuthorization
|
9
|
+
DoCapture
|
10
|
+
DoReauthorization
|
11
|
+
DoVoid
|
12
|
+
GetPalDetails
|
13
|
+
GetBalance
|
14
|
+
ManagePendingTransactionStatus
|
15
|
+
TransactionSearch
|
16
|
+
GetTransactionDetails
|
17
|
+
DoReferenceTransaction
|
18
|
+
Callback
|
19
|
+
|
20
|
+
Deprecated
|
21
|
+
==========
|
22
|
+
CreateBillingAgreement
|
23
|
+
GetBillingAgreementCustomerDetails
|
24
|
+
SetCustomerBillingAgreement
|
25
|
+
|
26
|
+
* CreateRecurringPaymentsProfile
|
27
|
+
* DoExpressCheckoutPayment
|
28
|
+
* GetExpressCheckoutDetails
|
29
|
+
* GetRecurringPaymentsProfileDetails
|
30
|
+
* ManageRecurringPaymentsProfileStatus
|
31
|
+
* RefundTransaction
|
32
|
+
* SetExpressCheckout
|
33
|
+
* UpdateRecurringPaymentsProfile
|
34
|
+
|
35
|
+
:checkout => "SetExpressCheckout",
|
36
|
+
:payment => "DoExpressCheckoutPayment",
|
37
|
+
:details => "GetExpressCheckoutDetails",
|
38
|
+
:create_profile => "CreateRecurringPaymentsProfile",
|
39
|
+
:profile => "GetRecurringPaymentsProfileDetails",
|
40
|
+
:manage_profile => "ManageRecurringPaymentsProfileStatus",
|
41
|
+
:update_profile => "UpdateRecurringPaymentsProfile",
|
42
|
+
:refund => "RefundTransaction"
|
43
|
+
|
44
|
+
Endpoints
|
45
|
+
---------
|
46
|
+
https://api-3t.paypal.com/nvp
|
47
|
+
https://api-3t.sandbox.paypal.com/nvp
|
48
|
+
|
49
|
+
Adaptive Payments
|
50
|
+
=================
|
51
|
+
CancelPreapproval
|
52
|
+
ConvertCurrency
|
53
|
+
ExecutePayment
|
54
|
+
GetFundingPlans
|
55
|
+
GetPaymentOptions
|
56
|
+
GetShippingAddresses
|
57
|
+
Pay
|
58
|
+
PaymentDetails
|
59
|
+
Preapproval
|
60
|
+
PreapprovalDetails
|
61
|
+
Refund
|
62
|
+
SetPaymentOptions
|
63
|
+
|
64
|
+
Endpoints
|
65
|
+
---------
|
66
|
+
https://svcs.paypal.com/AdaptivePayments/<API_operation>
|
67
|
+
https://svcs.sandbox.paypal.com/AdaptivePayments/<API_operation>
|
data/docs/design.txt
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
Pay
|
2
|
+
===
|
3
|
+
ap = AdaptivePayments::Payment.new()
|
4
|
+
ap.cancel_url = ""
|
5
|
+
ap.return_url = ""
|
6
|
+
ap.receivers << Receiver.new(email: '', amount: 10.00)
|
7
|
+
ap.receivers << PrimaryReceiver.new()
|
8
|
+
ap.create (action_type = :create)
|
9
|
+
ap.options = (SetPaymentOptions)
|
10
|
+
ap.options (GetPaymentOptions)
|
11
|
+
ap.pay (pay_key ? ExecutePayment : action_type = :pay)
|
12
|
+
ap.details (PaymentDetails)
|
13
|
+
ap.funding_plans (GetFundingPlans)
|
14
|
+
ap.shipping_addresses (GetShippingAddresses)
|
15
|
+
ap.refund (Refund)
|
16
|
+
|
17
|
+
PaymentDetails
|
18
|
+
==============
|
19
|
+
ap = AdaptivePayments::Payment.new(pay_key => '123456')
|
20
|
+
ap.details (returns PaymentDetail)
|
21
|
+
|
22
|
+
PaymentOptions
|
23
|
+
===============
|
24
|
+
ap = AdaptivePayments::Payment.new(pay_key => '123456')
|
25
|
+
ap.options (GetPaymentOptions)
|
26
|
+
ap.options =
|
27
|
+
|
28
|
+
Preapproval
|
29
|
+
===========
|
30
|
+
app = AdaptivePayments::Preapproval.new()
|
31
|
+
app.create
|
32
|
+
app.details
|
33
|
+
app.cancel
|
34
|
+
|
35
|
+
Refund
|
36
|
+
======
|
37
|
+
ap = AdaptivePayments::Payment.new(pay_key => '123456')
|
38
|
+
ap.refund
|
@@ -0,0 +1,172 @@
|
|
1
|
+
= PayPal Payment
|
2
|
+
|
3
|
+
PayPal API Client for Adaptive Payments, Invoice and Express Checkout.
|
4
|
+
|
5
|
+
== Installation (Gemfile)
|
6
|
+
|
7
|
+
gem 'paypal-payment', :git => 'vendor@appcepted.com:/home/vendor/pp_paypal'
|
8
|
+
|
9
|
+
== Usage
|
10
|
+
|
11
|
+
First, you need to set up your credentials:
|
12
|
+
|
13
|
+
require "paypal-payment"
|
14
|
+
|
15
|
+
PayPal::Api.configure do |config|
|
16
|
+
config.sandbox = true
|
17
|
+
config.username = "chardy_api1.gmail.com"
|
18
|
+
config.password = "8DTSWBZC7GDR3T4X"
|
19
|
+
config.signature = "AG-8mOpuFhFyFOYHlaTUYn3Syf15AWJKRnfHMVsmCtC3DK51-ENEPqLS"
|
20
|
+
end
|
21
|
+
|
22
|
+
== Ref: https://www.x.com/developers/paypal/documentation-tools/express-checkout/how-to/ht_ec-recurringPaymentProfile-curl-etc
|
23
|
+
|
24
|
+
== 1. Express Checkout - Recurring (authorization)
|
25
|
+
|
26
|
+
payment = PayPal::ExpressCheckout::Payment.new(
|
27
|
+
:payment_action => "Authorization",
|
28
|
+
:description => "Awesome - Monthly Subscription",
|
29
|
+
:notify_url => "http://example.com/paypal/ipn",
|
30
|
+
:amount => "9.00", # not bill yet
|
31
|
+
:currency => "USD"
|
32
|
+
)
|
33
|
+
|
34
|
+
billing = PayPal::ExpressCheckout::Billing.new(
|
35
|
+
:type => 'RecurringPayments',
|
36
|
+
:description => "Awesome - Monthly Subscription"
|
37
|
+
)
|
38
|
+
|
39
|
+
ppc = PayPal::ExpressCheckout::Checkout.new({
|
40
|
+
:return_url => "http://example.com/thank_you?app_name=camera_app",
|
41
|
+
:cancel_url => "http://example.com/canceled",
|
42
|
+
:billings => [ billing ],
|
43
|
+
:payments => [ payment ]
|
44
|
+
})
|
45
|
+
|
46
|
+
response = ppc.checkout
|
47
|
+
|
48
|
+
response.valid?
|
49
|
+
response.checkout_url
|
50
|
+
# https://www.sandbox.paypal.com/webscr?cmd=_express-checkout&token=InsertTokenHere
|
51
|
+
|
52
|
+
token = response.token
|
53
|
+
payer_id = response.details.payer_id
|
54
|
+
|
55
|
+
rco = PayPal::ExpressCheckout::Checkout.new(:token => token)
|
56
|
+
payer_id = rco.details.payer_id
|
57
|
+
|
58
|
+
== 1.a after click the checkout_url, make payment, redirect to return_url and paypal will return
|
59
|
+
|
60
|
+
TOKEN=token_value
|
61
|
+
&BILLINGAGREEMENTACCEPTEDSTATUS=1
|
62
|
+
&ACK=Success
|
63
|
+
&PAYERID=3TXTXECKF1234
|
64
|
+
|
65
|
+
== 2. Express Checkout - Recurring
|
66
|
+
|
67
|
+
ppr = PayPal::ExpressCheckout::Recurring.new({
|
68
|
+
:amount => "9.00",
|
69
|
+
:initial_amount => "9.00",
|
70
|
+
:failed_initial_action => :cancel,
|
71
|
+
:currency => "USD",
|
72
|
+
:description => "Awesome - Monthly Subscription",
|
73
|
+
:frequency => 1,
|
74
|
+
:token => token,
|
75
|
+
:period => :monthly,
|
76
|
+
:reference => "1234",
|
77
|
+
:payer_id => payer_id,
|
78
|
+
:start_at => Time.now,
|
79
|
+
:max_failed_payments => 1,
|
80
|
+
:auto_bill_outstanding => :next_billing
|
81
|
+
})
|
82
|
+
|
83
|
+
ppr.create_profile
|
84
|
+
ppr.profile_status
|
85
|
+
ppr.profile_id
|
86
|
+
|
87
|
+
== 3. Express Checkout - Recurring - manage profile
|
88
|
+
|
89
|
+
ppr = PayPal::ExpressCheckout::Recurring.new(:profile_id => "I-1RFWFFS16BF4")
|
90
|
+
ppr.suspend
|
91
|
+
ppr.success?
|
92
|
+
|
93
|
+
ppr.profile # see profile_spec.rb
|
94
|
+
|
95
|
+
ppr.reactivate
|
96
|
+
|
97
|
+
ppr.cancel # cannot reactivate
|
98
|
+
|
99
|
+
== 4. Express Checkout - Recurring - update profile
|
100
|
+
|
101
|
+
ppr = PayPal::ExpressCheckout::Recurring.new(:profile_id => "I-1RFWFFS16BF4")
|
102
|
+
|
103
|
+
PayPal::ExpressCheckout::Recurring.new({
|
104
|
+
:description => "Awesome - Monthly Subscription (Updated)",
|
105
|
+
:amount => "10.00",
|
106
|
+
:currency => "BRL",
|
107
|
+
:note => "Changed Plan",
|
108
|
+
:profile_id => profile_id
|
109
|
+
})
|
110
|
+
|
111
|
+
=====
|
112
|
+
|
113
|
+
== 1. Express Checkout - Sale
|
114
|
+
|
115
|
+
payment = PayPal::ExpressCheckout::Payment.new(
|
116
|
+
:payment_action => "Sale",
|
117
|
+
:description => "Awesome - Sale",
|
118
|
+
:notify_url => "http://example.com/paypal/ipn",
|
119
|
+
:amount => "9.00",
|
120
|
+
:currency => "USD"
|
121
|
+
)
|
122
|
+
|
123
|
+
ppc = PayPal::ExpressCheckout::Checkout.new({
|
124
|
+
:return_url => "http://example.com/thank_you",
|
125
|
+
:cancel_url => "http://example.com/canceled",
|
126
|
+
:payments => [ payment ]
|
127
|
+
})
|
128
|
+
|
129
|
+
response = ppc.checkout
|
130
|
+
response.valid?
|
131
|
+
response.checkout_url
|
132
|
+
|
133
|
+
== 1.a after click the checkout_url, make payment, redirect to return_url and paypal will return
|
134
|
+
|
135
|
+
TOKEN=token_value
|
136
|
+
&ACK=Success
|
137
|
+
|
138
|
+
== 2. Express Checkout - Sale
|
139
|
+
|
140
|
+
payment = PayPal::ExpressCheckout::Payment.new(
|
141
|
+
:payment_action => "Sale",
|
142
|
+
:description => "Awesome - Sale",
|
143
|
+
:notify_url => "http://example.com/paypal/ipn",
|
144
|
+
:amount => "9.00",
|
145
|
+
:currency => "USD"
|
146
|
+
)
|
147
|
+
|
148
|
+
checkout = PayPal::ExpressCheckout::Checkout.new(:token => token)
|
149
|
+
payer_id = checkout.details.payer_id
|
150
|
+
|
151
|
+
checkout = PayPal::ExpressCheckout::Checkout.new(
|
152
|
+
:token => token,
|
153
|
+
:payer_id => payer_id,
|
154
|
+
:payments => [payment]
|
155
|
+
)
|
156
|
+
checkout.pay
|
157
|
+
|
158
|
+
== 3. Express Checkout - Sale - Manage
|
159
|
+
|
160
|
+
payment = PayPal::ExpressCheckout::Payment.new(:transaction_id => transaction_id)
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
|
172
|
+
|