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,11 @@
|
|
1
|
+
module PayPal
|
2
|
+
module Common
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require "paypal/common/base"
|
7
|
+
require "paypal/common/request"
|
8
|
+
require "paypal/common/request_envelope"
|
9
|
+
require "paypal/common/response"
|
10
|
+
require "paypal/common/response_envelope"
|
11
|
+
require "paypal/common/error_data"
|
@@ -0,0 +1,83 @@
|
|
1
|
+
module PayPal::Common::Base
|
2
|
+
def initialize(attributes = {})
|
3
|
+
attributes.each do |name, value|
|
4
|
+
attr_name = underscore(name)
|
5
|
+
if respond_to?("set_#{attr_name}") and (value.is_a?(Hash) or value.is_a?(Array))
|
6
|
+
send("set_#{attr_name}", value)
|
7
|
+
elsif respond_to?("#{attr_name}=")
|
8
|
+
send("#{attr_name}=", value)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
after_initialize
|
12
|
+
end
|
13
|
+
|
14
|
+
def after_initialize
|
15
|
+
end
|
16
|
+
|
17
|
+
def request
|
18
|
+
PayPal::Common::Request.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def build_value(klass, value)
|
22
|
+
if value.is_a?(Hash)
|
23
|
+
klass.new(value)
|
24
|
+
elsif value.is_a?(Array)
|
25
|
+
value.map do |val|
|
26
|
+
val.is_a?(Hash) ? klass.new(val) : val
|
27
|
+
end
|
28
|
+
else
|
29
|
+
value
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def build_datetime(value)
|
34
|
+
if value.respond_to?(:to_time)
|
35
|
+
value.to_time
|
36
|
+
else
|
37
|
+
Time.parse(value.to_s)
|
38
|
+
end
|
39
|
+
rescue
|
40
|
+
end
|
41
|
+
|
42
|
+
def hash_keys
|
43
|
+
{}
|
44
|
+
end
|
45
|
+
|
46
|
+
def to_hash(*args)
|
47
|
+
ivars = args.empty? ? instance_variables : instance_variables.select { |var| args.include?(var[1..-1].to_sym) }
|
48
|
+
Hash[
|
49
|
+
ivars.map do |var|
|
50
|
+
val = instance_variable_get(var)
|
51
|
+
if val.is_a?(Array)
|
52
|
+
val.map! { |a| a.respond_to?(:to_hash) ? a.to_hash : a }
|
53
|
+
elsif val.respond_to?(:iso8601)
|
54
|
+
val = val.iso8601
|
55
|
+
else
|
56
|
+
val = val.to_hash if val.respond_to?(:to_hash)
|
57
|
+
end
|
58
|
+
hash_key = hash_keys[var[1..-1].to_sym] || camelize(var[1..-1], false).to_sym
|
59
|
+
[hash_key, val]
|
60
|
+
end
|
61
|
+
]
|
62
|
+
end
|
63
|
+
|
64
|
+
def to_json(*args)
|
65
|
+
MultiJson.dump(to_hash(*args))
|
66
|
+
end
|
67
|
+
|
68
|
+
def underscore(word)
|
69
|
+
word.to_s.gsub(/::/, '/').
|
70
|
+
gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
|
71
|
+
gsub(/([a-z\d])([A-Z])/,'\1_\2').
|
72
|
+
tr("-", "_").
|
73
|
+
downcase
|
74
|
+
end
|
75
|
+
|
76
|
+
def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
|
77
|
+
if first_letter_in_uppercase
|
78
|
+
lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::" + $1.upcase }.gsub(/(^|_)(.)/) { $2.upcase }
|
79
|
+
else
|
80
|
+
lower_case_and_underscored_word.to_s[0] + camelize(lower_case_and_underscored_word.to_s)[1..-1]
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module PayPal::Common
|
2
|
+
class ErrorData
|
3
|
+
include PayPal::Common::Base
|
4
|
+
|
5
|
+
attr_accessor :category
|
6
|
+
attr_accessor :domain
|
7
|
+
attr_accessor :error_id
|
8
|
+
attr_accessor :exception_id
|
9
|
+
attr_accessor :message
|
10
|
+
attr_accessor :parameter
|
11
|
+
attr_accessor :severity
|
12
|
+
attr_accessor :subdomain
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
module PayPal::Common
|
2
|
+
class Request < PayPal::Request
|
3
|
+
|
4
|
+
def api
|
5
|
+
PayPal::Api
|
6
|
+
end
|
7
|
+
|
8
|
+
def default_headers
|
9
|
+
super.merge(
|
10
|
+
{
|
11
|
+
'X-PAYPAL-SECURITY-USERID' => api.username,
|
12
|
+
'X-PAYPAL-SECURITY-PASSWORD' => api.password,
|
13
|
+
'X-PAYPAL-SECURITY-SIGNATURE' => api.signature,
|
14
|
+
'X-PAYPAL-REQUEST-DATA-FORMAT' => api.request_data_format,
|
15
|
+
'X-PAYPAL-RESPONSE-DATA-FORMAT' => api.response_data_format,
|
16
|
+
'X-PAYPAL-APPLICATION-ID' => api.app_id
|
17
|
+
}
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
# Returns the actual api endpoint base on method
|
22
|
+
#
|
23
|
+
def method_endpoint(method)
|
24
|
+
api.api_endpoint
|
25
|
+
end
|
26
|
+
|
27
|
+
def prepare_json(json)
|
28
|
+
json[:requestEnvelope] = PayPal::Common::RequestEnvelope.new.to_hash unless json[:requestEnvelope]
|
29
|
+
json
|
30
|
+
end
|
31
|
+
|
32
|
+
def build_json(json)
|
33
|
+
json.is_a?(Hash) ? build_json(json) : json
|
34
|
+
end
|
35
|
+
|
36
|
+
def run(method, json = {})
|
37
|
+
self.uri = method_endpoint(method)
|
38
|
+
post(MultiJson.dump(prepare_json(json)), default_headers)
|
39
|
+
end
|
40
|
+
|
41
|
+
def build_action_type(value)
|
42
|
+
ACTION_TYPES.fetch(value.to_sym, value) if value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module PayPal::Common
|
4
|
+
module Response
|
5
|
+
include PayPal::Common::Base
|
6
|
+
|
7
|
+
attr_accessor :error
|
8
|
+
attr_accessor :response_envelope
|
9
|
+
|
10
|
+
def set_response_envelope(value)
|
11
|
+
self.response_envelope = ResponseEnvelope.new(value)
|
12
|
+
end
|
13
|
+
|
14
|
+
def errors
|
15
|
+
@error||[]
|
16
|
+
end
|
17
|
+
|
18
|
+
def set_error(value)
|
19
|
+
self.error = build_value(ErrorData, value)
|
20
|
+
end
|
21
|
+
|
22
|
+
def response_envelope
|
23
|
+
@response_envelope ||= ResponseEnvelope.new
|
24
|
+
end
|
25
|
+
|
26
|
+
def success?
|
27
|
+
self.response_envelope.success?
|
28
|
+
end
|
29
|
+
|
30
|
+
def valid?
|
31
|
+
(self.errors||[]).empty?
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PayPal::Common
|
2
|
+
class ResponseEnvelope
|
3
|
+
include PayPal::Common::Base
|
4
|
+
|
5
|
+
attr_accessor :timestamp
|
6
|
+
attr_accessor :ack
|
7
|
+
attr_accessor :build
|
8
|
+
attr_accessor :correlation_id
|
9
|
+
|
10
|
+
def success?
|
11
|
+
self.ack == 'Success'
|
12
|
+
end
|
13
|
+
|
14
|
+
def set_timestamp(value)
|
15
|
+
self.timestamp = Time.parse(value)
|
16
|
+
rescue
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require "paypal/express_checkout/api"
|
7
|
+
require "paypal/express_checkout/utils"
|
8
|
+
require "paypal/express_checkout/fields"
|
9
|
+
require "paypal/express_checkout/request"
|
10
|
+
require "paypal/express_checkout/base"
|
11
|
+
require "paypal/express_checkout/account"
|
12
|
+
require "paypal/express_checkout/billing"
|
13
|
+
require "paypal/express_checkout/payment"
|
14
|
+
require "paypal/express_checkout/payment_item"
|
15
|
+
require "paypal/express_checkout/fmf"
|
16
|
+
require "paypal/express_checkout/shipping_option"
|
17
|
+
require "paypal/express_checkout/checkout"
|
18
|
+
require "paypal/express_checkout/recurring"
|
19
|
+
require "paypal/express_checkout/response"
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
class Account < PayPal::ExpressCheckout::Base
|
4
|
+
has_fields :account
|
5
|
+
|
6
|
+
def pal_details
|
7
|
+
run(:pal_details)
|
8
|
+
end
|
9
|
+
|
10
|
+
def balance
|
11
|
+
params = collect(:all_currencies)
|
12
|
+
run(:balance, params)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
class Api
|
4
|
+
|
5
|
+
API_ENDPOINTS = {
|
6
|
+
:sandbox => "https://api-3t.sandbox.paypal.com/nvp",
|
7
|
+
:production => "https://api-3t.paypal.com/nvp"
|
8
|
+
}
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def username
|
12
|
+
PayPal::Api.instance.username
|
13
|
+
end
|
14
|
+
|
15
|
+
def password
|
16
|
+
PayPal::Api.instance.password
|
17
|
+
end
|
18
|
+
|
19
|
+
def signature
|
20
|
+
PayPal::Api.instance.signature
|
21
|
+
end
|
22
|
+
|
23
|
+
def app_id
|
24
|
+
PayPal::Api.instance.app_id
|
25
|
+
end
|
26
|
+
|
27
|
+
def environment
|
28
|
+
PayPal::Api.environment
|
29
|
+
end
|
30
|
+
|
31
|
+
def api_endpoint
|
32
|
+
self::API_ENDPOINTS[environment]
|
33
|
+
end
|
34
|
+
|
35
|
+
# Return PayPal's API version.
|
36
|
+
#
|
37
|
+
def api_version
|
38
|
+
"93.0"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require "cgi"
|
2
|
+
require "uri"
|
3
|
+
require "ostruct"
|
4
|
+
require "time"
|
5
|
+
|
6
|
+
module PayPal
|
7
|
+
module ExpressCheckout
|
8
|
+
class Base
|
9
|
+
include PayPal::ExpressCheckout::Fields
|
10
|
+
|
11
|
+
def initialize(options = {})
|
12
|
+
options.each {|name, value| send("#{name}=", value)}
|
13
|
+
end
|
14
|
+
|
15
|
+
# Just a shortcut convenience.
|
16
|
+
#
|
17
|
+
def request # :nodoc:
|
18
|
+
@request ||= PayPal::ExpressCheckout::Request.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def run(method, params = {}, headers = {})
|
22
|
+
request.run(self, method, params, headers)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
# Collect specified attributes and build a hash out of it.
|
27
|
+
#
|
28
|
+
def collect(*args) # :nodoc:
|
29
|
+
args.inject({}) do |buffer, attr_name|
|
30
|
+
value = send(attr_name)
|
31
|
+
buffer[attr_name] = value if value
|
32
|
+
buffer
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
class Callback < PayPal::ExpressCheckout::Base
|
4
|
+
has_fields :callback
|
5
|
+
has_many :shipping_options
|
6
|
+
|
7
|
+
def response
|
8
|
+
params = group_collect(
|
9
|
+
:callback,
|
10
|
+
:shipping_options
|
11
|
+
)
|
12
|
+
|
13
|
+
run(:callback_response, params)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
module PayPal
|
2
|
+
module ExpressCheckout
|
3
|
+
class Checkout < PayPal::ExpressCheckout::Base
|
4
|
+
has_fields :checkout, :giro, :gift, :survey, :buyer, :tax, :shipping_option, :landing_page, :solution_type, :channel_type
|
5
|
+
|
6
|
+
has_many :shipping_options, :payments, :billings
|
7
|
+
|
8
|
+
# Request a checkout token.
|
9
|
+
#
|
10
|
+
# ppr = PayPal::ExpressCheckout::Checkout.new({
|
11
|
+
# :return_url => "http://example.com/checkout/thank_you",
|
12
|
+
# :cancel_url => "http://example.com/checkout/canceled",
|
13
|
+
# :ipn_url => "http://example.com/paypal/ipn",
|
14
|
+
# :description => "Awesome - Monthly Subscription",
|
15
|
+
# :amount => "9.00",
|
16
|
+
# :currency => "USD"
|
17
|
+
# })
|
18
|
+
#
|
19
|
+
# response = ppr.request_token
|
20
|
+
# response.checkout_url
|
21
|
+
#
|
22
|
+
def checkout
|
23
|
+
params = group_collect(
|
24
|
+
:checkout,
|
25
|
+
:giro,
|
26
|
+
:gift,
|
27
|
+
:survey,
|
28
|
+
:buyer,
|
29
|
+
:tax,
|
30
|
+
:landing_page,
|
31
|
+
:solution_type,
|
32
|
+
:channel_type,
|
33
|
+
:payments,
|
34
|
+
:shipping_options,
|
35
|
+
:billings
|
36
|
+
)
|
37
|
+
|
38
|
+
run(:checkout, params)
|
39
|
+
end
|
40
|
+
|
41
|
+
# Return checkout details.
|
42
|
+
#
|
43
|
+
# ppr = PayPal::ExpressCheckout::Checkout.new({
|
44
|
+
# :token => "EC-6LX60229XS426623E"
|
45
|
+
# })
|
46
|
+
# response = ppr.details
|
47
|
+
#
|
48
|
+
def details
|
49
|
+
run(:details, :token => token)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Verify an address.
|
53
|
+
# ppr = PayPal::ExpressCheckout::Checkout.new({
|
54
|
+
# :email => "user@example.com",
|
55
|
+
# :street => "ABCEDFGH",
|
56
|
+
# :zip => "1234"
|
57
|
+
# })
|
58
|
+
# response = ppr.refund
|
59
|
+
#
|
60
|
+
def address_verify
|
61
|
+
params = collect(
|
62
|
+
:email,
|
63
|
+
:street,
|
64
|
+
:zip
|
65
|
+
)
|
66
|
+
|
67
|
+
run(:address_verify, params)
|
68
|
+
end
|
69
|
+
|
70
|
+
# Execute payment. DoExpressCheckoutPayment
|
71
|
+
def pay
|
72
|
+
params = group_collect(
|
73
|
+
:token,
|
74
|
+
:payer_id,
|
75
|
+
:return_fmf_details,
|
76
|
+
:payments,
|
77
|
+
:survey,
|
78
|
+
:shipping_option
|
79
|
+
)
|
80
|
+
|
81
|
+
run(:pay, params)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Do authorization
|
85
|
+
#
|
86
|
+
def authorize
|
87
|
+
params = collect(
|
88
|
+
:transaction_id,
|
89
|
+
:amount,
|
90
|
+
:transaction_entity,
|
91
|
+
:currency,
|
92
|
+
:msg_sub_id
|
93
|
+
)
|
94
|
+
|
95
|
+
run(:authorize, params)
|
96
|
+
end
|
97
|
+
|
98
|
+
# Do authorization
|
99
|
+
#
|
100
|
+
def reauthorize
|
101
|
+
params = collect(
|
102
|
+
:transaction_id,
|
103
|
+
:amount,
|
104
|
+
:transaction_entity,
|
105
|
+
:currency,
|
106
|
+
:msg_sub_id
|
107
|
+
)
|
108
|
+
|
109
|
+
run(:reauthorize, params)
|
110
|
+
end
|
111
|
+
|
112
|
+
# Do capture
|
113
|
+
#
|
114
|
+
def capture
|
115
|
+
params = collect(
|
116
|
+
:authorization_id,
|
117
|
+
:amount,
|
118
|
+
:currency,
|
119
|
+
:complete_type,
|
120
|
+
:invoice_no,
|
121
|
+
:note,
|
122
|
+
:soft_descriptor,
|
123
|
+
:msg_sub_id,
|
124
|
+
:store_id,
|
125
|
+
:terminal_id
|
126
|
+
)
|
127
|
+
|
128
|
+
run(:capture, params)
|
129
|
+
end
|
130
|
+
|
131
|
+
# Do void
|
132
|
+
#
|
133
|
+
def void
|
134
|
+
params = collect(
|
135
|
+
:authorization_id,
|
136
|
+
:note,
|
137
|
+
:msg_sub_id
|
138
|
+
)
|
139
|
+
|
140
|
+
run(:void, params)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|