paypal-sdk-rest 1.7.6 → 2.0.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/Gemfile +4 -14
- data/README.md +45 -255
- data/lib/lib.rb +88 -0
- data/lib/paypal/core/access_token.rb +20 -0
- data/lib/paypal/core/paypal_environment.rb +38 -0
- data/lib/paypal/core/paypal_http_client.rb +51 -0
- data/lib/paypal/core/token_requests.rb +40 -0
- data/lib/paypal/core/version.rb +3 -0
- data/lib/v1/billing_agreements/agreement_bill_balance_request.rb +35 -0
- data/lib/v1/billing_agreements/agreement_cancel_request.rb +35 -0
- data/lib/v1/billing_agreements/agreement_create_request.rb +33 -0
- data/lib/v1/billing_agreements/agreement_execute_request.rb +31 -0
- data/lib/v1/billing_agreements/agreement_get_request.rb +31 -0
- data/lib/v1/billing_agreements/agreement_re_activate_request.rb +35 -0
- data/lib/v1/billing_agreements/agreement_set_balance_request.rb +35 -0
- data/lib/v1/billing_agreements/agreement_suspend_request.rb +35 -0
- data/lib/v1/billing_agreements/agreement_transactions_request.rb +41 -0
- data/lib/v1/billing_agreements/agreement_update_request.rb +35 -0
- data/lib/v1/billing_plans/plan_create_request.rb +33 -0
- data/lib/v1/billing_plans/plan_get_request.rb +31 -0
- data/lib/v1/billing_plans/plan_list_request.rb +49 -0
- data/lib/v1/billing_plans/plan_update_request.rb +35 -0
- data/lib/v1/identity/user_consent.rb +45 -0
- data/lib/v1/identity/userinfo_get_request.rb +33 -0
- data/lib/v1/invoices/invoice_cancel_request.rb +35 -0
- data/lib/v1/invoices/invoice_create_request.rb +33 -0
- data/lib/v1/invoices/invoice_delete_external_payment_request.rb +33 -0
- data/lib/v1/invoices/invoice_delete_external_refund_request.rb +33 -0
- data/lib/v1/invoices/invoice_delete_request.rb +31 -0
- data/lib/v1/invoices/invoice_get_request.rb +31 -0
- data/lib/v1/invoices/invoice_list_request.rb +44 -0
- data/lib/v1/invoices/invoice_next_invoice_number_request.rb +29 -0
- data/lib/v1/invoices/invoice_qr_code_request.rb +46 -0
- data/lib/v1/invoices/invoice_record_payment_request.rb +35 -0
- data/lib/v1/invoices/invoice_record_refund_request.rb +35 -0
- data/lib/v1/invoices/invoice_remind_request.rb +35 -0
- data/lib/v1/invoices/invoice_search_request.rb +33 -0
- data/lib/v1/invoices/invoice_send_request.rb +36 -0
- data/lib/v1/invoices/invoice_update_request.rb +40 -0
- data/lib/v1/invoices/template_create_request.rb +33 -0
- data/lib/v1/invoices/template_delete_request.rb +31 -0
- data/lib/v1/invoices/template_get_request.rb +31 -0
- data/lib/v1/invoices/template_list_request.rb +34 -0
- data/lib/v1/invoices/template_update_request.rb +35 -0
- data/lib/v1/orders/orders_cancel_request.rb +31 -0
- data/lib/v1/orders/orders_create_request.rb +33 -0
- data/lib/v1/orders/orders_get_request.rb +31 -0
- data/lib/v1/orders/orders_pay_request.rb +35 -0
- data/lib/v1/payment_experience/web_profile_create_request.rb +33 -0
- data/lib/v1/payment_experience/web_profile_delete_request.rb +31 -0
- data/lib/v1/payment_experience/web_profile_get_request.rb +31 -0
- data/lib/v1/payment_experience/web_profile_list_request.rb +29 -0
- data/lib/v1/payment_experience/web_profile_partial_update_request.rb +35 -0
- data/lib/v1/payment_experience/web_profile_update_request.rb +35 -0
- data/lib/v1/payments/authorization_capture_request.rb +35 -0
- data/lib/v1/payments/authorization_get_request.rb +31 -0
- data/lib/v1/payments/authorization_reauthorize_request.rb +35 -0
- data/lib/v1/payments/authorization_void_request.rb +31 -0
- data/lib/v1/payments/capture_get_request.rb +31 -0
- data/lib/v1/payments/capture_refund_request.rb +35 -0
- data/lib/v1/payments/order_authorize_request.rb +35 -0
- data/lib/v1/payments/order_capture_request.rb +35 -0
- data/lib/v1/payments/order_get_request.rb +31 -0
- data/lib/v1/payments/order_void_request.rb +31 -0
- data/lib/v1/payments/payment_create_request.rb +33 -0
- data/lib/v1/payments/payment_execute_request.rb +35 -0
- data/lib/v1/payments/payment_get_request.rb +31 -0
- data/lib/v1/payments/payment_list_request.rb +69 -0
- data/lib/v1/payments/payment_update_request.rb +35 -0
- data/lib/v1/payments/refund_get_request.rb +31 -0
- data/lib/v1/payments/sale_get_request.rb +31 -0
- data/lib/v1/payments/sale_refund_request.rb +35 -0
- data/lib/v1/sync/search_get_request.rb +99 -0
- data/lib/v1/vault/credit_card_create_request.rb +33 -0
- data/lib/v1/vault/credit_card_delete_request.rb +31 -0
- data/lib/v1/vault/credit_card_get_request.rb +31 -0
- data/lib/v1/vault/credit_card_list_request.rb +79 -0
- data/lib/v1/vault/credit_card_update_request.rb +35 -0
- data/lib/v1/webhooks/available_event_type_list_request.rb +29 -0
- data/lib/v1/webhooks/event_get_request.rb +31 -0
- data/lib/v1/webhooks/event_list_request.rb +54 -0
- data/lib/v1/webhooks/event_resend_request.rb +35 -0
- data/lib/v1/webhooks/simulate_event_request.rb +33 -0
- data/lib/v1/webhooks/webhook_create_request.rb +33 -0
- data/lib/v1/webhooks/webhook_delete_request.rb +31 -0
- data/lib/v1/webhooks/webhook_get_request.rb +31 -0
- data/lib/v1/webhooks/webhook_list_event_subscriptions_request.rb +31 -0
- data/lib/v1/webhooks/webhook_list_request.rb +34 -0
- data/lib/v1/webhooks/webhook_update_request.rb +35 -0
- data/lib/v1/webhooks/webhook_verify_signature_request.rb +33 -0
- data/spec/integration/test_harness.rb +25 -0
- data/spec/integration/v1/billing_agreements/agreement_create_spec.rb +63 -0
- data/spec/integration/v1/billing_plans/plan_create_spec.rb +12 -0
- data/spec/integration/v1/billing_plans/plan_get_spec.rb +16 -0
- data/spec/integration/v1/billing_plans/plan_helper.rb +71 -0
- data/spec/integration/v1/billing_plans/plan_list_spec.rb +16 -0
- data/spec/integration/v1/billing_plans/plan_update_spec.rb +19 -0
- data/spec/integration/v1/identity/userinfo_get_spec.rb +65 -0
- data/spec/integration/v1/invoices/invoice_cancel_spec.rb +23 -0
- data/spec/integration/v1/invoices/invoice_create_spec.rb +15 -0
- data/spec/integration/v1/invoices/invoice_delete_external_payment_spec.rb +23 -0
- data/spec/integration/v1/invoices/invoice_delete_external_refund_spec.rb +21 -0
- data/spec/integration/v1/invoices/invoice_delete_spec.rb +16 -0
- data/spec/integration/v1/invoices/invoice_get_spec.rb +18 -0
- data/spec/integration/v1/invoices/invoice_helper.rb +171 -0
- data/spec/integration/v1/invoices/invoice_list_spec.rb +20 -0
- data/spec/integration/v1/invoices/invoice_next_invoice_number_spec.rb +14 -0
- data/spec/integration/v1/invoices/invoice_qr_code_spec.rb +18 -0
- data/spec/integration/v1/invoices/invoice_record_payment_spec.rb +14 -0
- data/spec/integration/v1/invoices/invoice_record_refund_spec.rb +14 -0
- data/spec/integration/v1/invoices/invoice_remind_spec.rb +22 -0
- data/spec/integration/v1/invoices/invoice_search_spec.rb +20 -0
- data/spec/integration/v1/invoices/invoice_send_spec.rb +15 -0
- data/spec/integration/v1/invoices/invoice_update_spec.rb +26 -0
- data/spec/integration/v1/invoices/template_create_spec.rb +14 -0
- data/spec/integration/v1/invoices/template_delete_spec.rb +15 -0
- data/spec/integration/v1/invoices/template_get_spec.rb +18 -0
- data/spec/integration/v1/invoices/template_list_spec.rb +15 -0
- data/spec/integration/v1/invoices/template_update_spec.rb +62 -0
- data/spec/integration/v1/orders/orders_cancel_spec.rb +15 -0
- data/spec/integration/v1/orders/orders_create_spec.rb +17 -0
- data/spec/integration/v1/orders/orders_get_spec.rb +18 -0
- data/spec/integration/v1/orders/orders_helper.rb +36 -0
- data/spec/integration/v1/orders/orders_pay_spec.rb +19 -0
- data/spec/integration/v1/payment_experience/pe_helper.rb +35 -0
- data/spec/integration/v1/payment_experience/web_profile_create_spec.rb +20 -0
- data/spec/integration/v1/payment_experience/web_profile_delete_spec.rb +15 -0
- data/spec/integration/v1/payment_experience/web_profile_get_spec.rb +17 -0
- data/spec/integration/v1/payment_experience/web_profile_list_spec.rb +18 -0
- data/spec/integration/v1/payment_experience/web_profile_partial_update_spec.rb +32 -0
- data/spec/integration/v1/payment_experience/web_profile_update_spec.rb +44 -0
- data/spec/integration/v1/payments/authorization_capture_spec.rb +17 -0
- data/spec/integration/v1/payments/authorization_get_spec.rb +18 -0
- data/spec/integration/v1/payments/authorization_reauthorize_spec.rb +26 -0
- data/spec/integration/v1/payments/authorization_void_spec.rb +19 -0
- data/spec/integration/v1/payments/capture_get_spec.rb +20 -0
- data/spec/integration/v1/payments/capture_refund_spec.rb +27 -0
- data/spec/integration/v1/payments/order_authorize_spec.rb +20 -0
- data/spec/integration/v1/payments/order_capture_spec.rb +21 -0
- data/spec/integration/v1/payments/order_get_spec.rb +14 -0
- data/spec/integration/v1/payments/order_void_spec.rb +14 -0
- data/spec/integration/v1/payments/payment_create_spec.rb +13 -0
- data/spec/integration/v1/payments/payment_execute_spec.rb +19 -0
- data/spec/integration/v1/payments/payment_get_spec.rb +17 -0
- data/spec/integration/v1/payments/payment_list_spec.rb +16 -0
- data/spec/integration/v1/payments/payment_update_spec.rb +28 -0
- data/spec/integration/v1/payments/payments_helper.rb +72 -0
- data/spec/integration/v1/payments/refund_get_spec.rb +19 -0
- data/spec/integration/v1/payments/sale_get_spec.rb +18 -0
- data/spec/integration/v1/payments/sale_refund_spec.rb +18 -0
- data/spec/integration/v1/sync/search_get_spec.rb +34 -0
- data/spec/integration/v1/vault/credit_card_create_spec.rb +16 -0
- data/spec/integration/v1/vault/credit_card_delete_spec.rb +16 -0
- data/spec/integration/v1/vault/credit_card_get_spec.rb +17 -0
- data/spec/integration/v1/vault/credit_card_list_spec.rb +18 -0
- data/spec/integration/v1/vault/credit_card_update_spec.rb +26 -0
- data/spec/integration/v1/vault/vault_helper.rb +28 -0
- data/spec/integration/v1/webhooks/available_event_type_list_spec.rb +16 -0
- data/spec/integration/v1/webhooks/webhook_create_spec.rb +12 -0
- data/spec/integration/v1/webhooks/webhook_delete_spec.rb +13 -0
- data/spec/integration/v1/webhooks/webhook_get_spec.rb +16 -0
- data/spec/integration/v1/webhooks/webhook_helper.rb +43 -0
- data/spec/integration/v1/webhooks/webhook_list_event_subscriptions_spec.rb +16 -0
- data/spec/integration/v1/webhooks/webhook_list_spec.rb +15 -0
- data/spec/integration/v1/webhooks/webhook_update_spec.rb +29 -0
- data/spec/integration/v1/webhooks/webhook_verify_signature_spec.rb +20 -0
- data/spec/spec_helper.rb +97 -28
- data/spec/unit/paypal_http_client_spec.rb +264 -0
- metadata +257 -127
- data/Rakefile +0 -15
- data/data/DigiCertHighAssuranceEVRootCA.pem +0 -23
- data/data/DigiCertSHA2ExtendedValidationServerCA.pem +0 -28
- data/data/paypal.crt +0 -171
- data/lib/generators/paypal/sdk/USAGE +0 -3
- data/lib/generators/paypal/sdk/install_generator.rb +0 -17
- data/lib/generators/paypal/sdk/templates/paypal.rb +0 -2
- data/lib/generators/paypal/sdk/templates/paypal.yml +0 -29
- data/lib/paypal-sdk/core/api/base.rb +0 -169
- data/lib/paypal-sdk/core/api/data_types/array_with_block.rb +0 -44
- data/lib/paypal-sdk/core/api/data_types/base.rb +0 -225
- data/lib/paypal-sdk/core/api/data_types/enum.rb +0 -26
- data/lib/paypal-sdk/core/api/data_types/simple_types.rb +0 -52
- data/lib/paypal-sdk/core/api/ipn.rb +0 -66
- data/lib/paypal-sdk/core/api/rest.rb +0 -177
- data/lib/paypal-sdk/core/api.rb +0 -20
- data/lib/paypal-sdk/core/authentication.rb +0 -66
- data/lib/paypal-sdk/core/config.rb +0 -253
- data/lib/paypal-sdk/core/credential/base.rb +0 -27
- data/lib/paypal-sdk/core/credential/certificate.rb +0 -32
- data/lib/paypal-sdk/core/credential/signature.rb +0 -22
- data/lib/paypal-sdk/core/credential/third_party/subject.rb +0 -25
- data/lib/paypal-sdk/core/credential/third_party/token.rb +0 -39
- data/lib/paypal-sdk/core/credential.rb +0 -16
- data/lib/paypal-sdk/core/exceptions.rb +0 -112
- data/lib/paypal-sdk/core/logging.rb +0 -50
- data/lib/paypal-sdk/core/openid_connect/api.rb +0 -50
- data/lib/paypal-sdk/core/openid_connect/data_types.rb +0 -73
- data/lib/paypal-sdk/core/openid_connect/get_api.rb +0 -28
- data/lib/paypal-sdk/core/openid_connect/request_data_type.rb +0 -52
- data/lib/paypal-sdk/core/openid_connect/set_api.rb +0 -36
- data/lib/paypal-sdk/core/openid_connect.rb +0 -140
- data/lib/paypal-sdk/core/util/http_helper.rb +0 -171
- data/lib/paypal-sdk/core/util/oauth_signature.rb +0 -64
- data/lib/paypal-sdk/core/util/ordered_hash.rb +0 -165
- data/lib/paypal-sdk/core/util.rb +0 -11
- data/lib/paypal-sdk/rest/api.rb +0 -23
- data/lib/paypal-sdk/rest/data_types.rb +0 -2597
- data/lib/paypal-sdk/rest/error_hash.rb +0 -39
- data/lib/paypal-sdk/rest/get_api.rb +0 -20
- data/lib/paypal-sdk/rest/request_data_type.rb +0 -53
- data/lib/paypal-sdk/rest/set_api.rb +0 -42
- data/lib/paypal-sdk/rest/version.rb +0 -7
- data/lib/paypal-sdk/rest.rb +0 -39
- data/lib/paypal-sdk-core.rb +0 -38
- data/lib/paypal-sdk-rest.rb +0 -2
- data/spec/README.md +0 -22
- data/spec/config/cacert.pem +0 -171
- data/spec/config/cert_key.pem +0 -33
- data/spec/config/paypal.yml +0 -35
- data/spec/config/sample_data.yml +0 -3
- data/spec/core/api/data_type_spec.rb +0 -289
- data/spec/core/api/rest_spec.rb +0 -211
- data/spec/core/config_spec.rb +0 -192
- data/spec/core/logging_spec.rb +0 -28
- data/spec/core/openid_connect_spec.rb +0 -153
- data/spec/invoice_examples_spec.rb +0 -38
- data/spec/payments_examples_spec.rb +0 -437
- data/spec/payouts_examples_spec.rb +0 -74
- data/spec/rest/data_types_spec.rb +0 -62
- data/spec/rest/error_hash_spec.rb +0 -83
- data/spec/subscription_examples_spec.rb +0 -227
- data/spec/support/sample_data.rb +0 -5
- data/spec/web_profile_examples_spec.rb +0 -106
- data/spec/webhooks_examples_spec.rb +0 -93
@@ -1,171 +0,0 @@
|
|
1
|
-
require 'net/https'
|
2
|
-
require 'uri'
|
3
|
-
require 'cgi'
|
4
|
-
|
5
|
-
module PayPal::SDK::Core
|
6
|
-
module Util
|
7
|
-
module HTTPHelper
|
8
|
-
|
9
|
-
include Configuration
|
10
|
-
include Logging
|
11
|
-
include Authentication
|
12
|
-
include Exceptions
|
13
|
-
|
14
|
-
# Create HTTP connection based on given service name or configured end point
|
15
|
-
def create_http_connection(uri)
|
16
|
-
new_http(uri).tap do |http|
|
17
|
-
if config.http_timeout
|
18
|
-
http.open_timeout = config.http_timeout
|
19
|
-
http.read_timeout = config.http_timeout
|
20
|
-
end
|
21
|
-
configure_ssl(http) if uri.scheme == "https"
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
# New raw HTTP object
|
26
|
-
def new_http(uri)
|
27
|
-
if config.http_proxy
|
28
|
-
proxy = URI.parse(config.http_proxy)
|
29
|
-
Net::HTTP.new(uri.host, uri.port, proxy.host, proxy.port, proxy.user, proxy.password)
|
30
|
-
else
|
31
|
-
Net::HTTP.new(uri.host, uri.port)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
# Default ca file
|
36
|
-
def default_ca_file
|
37
|
-
File.expand_path("../../../../../data/paypal.crt", __FILE__)
|
38
|
-
end
|
39
|
-
|
40
|
-
# Apply ssl configuration to http object
|
41
|
-
def configure_ssl(http)
|
42
|
-
http.tap do |https|
|
43
|
-
https.use_ssl = true
|
44
|
-
https.ca_file = default_ca_file
|
45
|
-
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
46
|
-
begin
|
47
|
-
https.ssl_version = :TLSv1_2
|
48
|
-
rescue => error
|
49
|
-
logger.warn("WARNING: Your system does not support TLSv1.2. Per PCI Security Council mandate (https://github.com/paypal/TLS-update), you MUST update to latest security library.")
|
50
|
-
end
|
51
|
-
config.ssl_options.each do |key, value|
|
52
|
-
http.send("#{key}=", value)
|
53
|
-
end
|
54
|
-
add_certificate(https)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
|
58
|
-
# Join url
|
59
|
-
def url_join(path, action)
|
60
|
-
path.sub(/\/?$/, "/#{action}")
|
61
|
-
end
|
62
|
-
|
63
|
-
# Make Http call
|
64
|
-
# * payload - Hash(:http, :method, :uri, :body, :header)
|
65
|
-
def http_call(payload)
|
66
|
-
response =
|
67
|
-
log_http_call(payload) do
|
68
|
-
http = payload[:http] || create_http_connection(payload[:uri])
|
69
|
-
http.start do |session|
|
70
|
-
if [ :get, :delete, :head ].include? payload[:method]
|
71
|
-
session.send(payload[:method], payload[:uri].request_uri, payload[:header])
|
72
|
-
else
|
73
|
-
session.send(payload[:method], payload[:uri].request_uri, payload[:body], payload[:header])
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
handle_response(response)
|
79
|
-
end
|
80
|
-
|
81
|
-
# Log Http call
|
82
|
-
# * payload - Hash(:http, :method, :uri, :body, :header)
|
83
|
-
def log_http_call(payload)
|
84
|
-
logger.info "Request[#{payload[:method]}]: #{payload[:uri].to_s}"
|
85
|
-
|
86
|
-
logger.debug "Request.body=#{payload[:body]}\trequest.header=#{payload[:header]}"
|
87
|
-
|
88
|
-
start_time = Time.now
|
89
|
-
response = yield
|
90
|
-
logger.info sprintf("Response[%s]: %s, Duration: %.3fs", response.code,
|
91
|
-
response.message, Time.now - start_time)
|
92
|
-
|
93
|
-
logger.add(
|
94
|
-
response_details_log_level(response),
|
95
|
-
"Response.body=#{response.body}\tResponse.header=#{response.to_hash}"
|
96
|
-
)
|
97
|
-
|
98
|
-
response
|
99
|
-
end
|
100
|
-
|
101
|
-
# Generate header based on given header keys and properties
|
102
|
-
# === Arguments
|
103
|
-
# * <tt>header_keys</tt> -- List of Header keys for the properties
|
104
|
-
# * <tt>properties</tt> -- properties
|
105
|
-
# === Return
|
106
|
-
# Hash with header as key property as value
|
107
|
-
# === Example
|
108
|
-
# map_header_value( { :username => "X-PAYPAL-USERNAME"}, { :username => "guest" })
|
109
|
-
# # Return: { "X-PAYPAL-USERNAME" => "guest" }
|
110
|
-
def map_header_value(header_keys, properties)
|
111
|
-
header = {}
|
112
|
-
properties.each do |key, value|
|
113
|
-
key = header_keys[key]
|
114
|
-
header[key] = value.to_s if key and value
|
115
|
-
end
|
116
|
-
header
|
117
|
-
end
|
118
|
-
|
119
|
-
def encode_www_form(hash)
|
120
|
-
if defined? URI.encode_www_form
|
121
|
-
URI.encode_www_form(hash)
|
122
|
-
else
|
123
|
-
hash.map{|key, value| "#{CGI.escape(key.to_s)}=#{CGI.escape(value.to_s)}" }.join("&")
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
# Handles response and error codes from the remote service.
|
128
|
-
def handle_response(response)
|
129
|
-
case response.code.to_i
|
130
|
-
when 301, 302, 303, 307
|
131
|
-
raise(Redirection.new(response))
|
132
|
-
when 200...400
|
133
|
-
response
|
134
|
-
when 400
|
135
|
-
raise(BadRequest.new(response))
|
136
|
-
when 401
|
137
|
-
raise(UnauthorizedAccess.new(response))
|
138
|
-
when 403
|
139
|
-
raise(ForbiddenAccess.new(response))
|
140
|
-
when 404
|
141
|
-
raise(ResourceNotFound.new(response))
|
142
|
-
when 405
|
143
|
-
raise(MethodNotAllowed.new(response))
|
144
|
-
when 409
|
145
|
-
raise(ResourceConflict.new(response))
|
146
|
-
when 410
|
147
|
-
raise(ResourceGone.new(response))
|
148
|
-
when 422
|
149
|
-
raise(ResourceInvalid.new(response))
|
150
|
-
when 401...500
|
151
|
-
raise(ClientError.new(response))
|
152
|
-
when 500...600
|
153
|
-
raise(ServerError.new(response))
|
154
|
-
else
|
155
|
-
raise(ConnectionError.new(response, "Unknown response code: #{response.code}"))
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
private
|
160
|
-
|
161
|
-
def response_details_log_level(response)
|
162
|
-
if (400...600).cover?(response.code.to_i)
|
163
|
-
Logger::WARN
|
164
|
-
else
|
165
|
-
Logger::DEBUG
|
166
|
-
end
|
167
|
-
end
|
168
|
-
|
169
|
-
end
|
170
|
-
end
|
171
|
-
end
|
@@ -1,64 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'cgi'
|
3
|
-
require 'openssl'
|
4
|
-
require 'base64'
|
5
|
-
|
6
|
-
module PayPal::SDK::Core
|
7
|
-
module Util
|
8
|
-
class OauthSignature
|
9
|
-
attr_accessor :username, :password, :token, :token_secret, :url, :timestamp
|
10
|
-
|
11
|
-
def initialize(username, password, token, token_secret, url, timestamp = nil)
|
12
|
-
@username = username
|
13
|
-
@password = password
|
14
|
-
@token = token
|
15
|
-
@token_secret = token_secret
|
16
|
-
@url = url
|
17
|
-
@timestamp = timestamp || Time.now.to_i.to_s
|
18
|
-
end
|
19
|
-
|
20
|
-
def authorization_string
|
21
|
-
signature = oauth_signature
|
22
|
-
"token=#{token},signature=#{signature},timestamp=#{timestamp}"
|
23
|
-
end
|
24
|
-
|
25
|
-
def oauth_signature
|
26
|
-
key = [
|
27
|
-
paypal_encode(password),
|
28
|
-
paypal_encode(token_secret),
|
29
|
-
].join("&").gsub(/%[0-9A-F][0-9A-F]/, &:downcase )
|
30
|
-
|
31
|
-
digest = OpenSSL::HMAC.digest('sha1', key, base_string)
|
32
|
-
Base64.encode64(digest).chomp
|
33
|
-
end
|
34
|
-
|
35
|
-
def base_string
|
36
|
-
params = {
|
37
|
-
"oauth_consumer_key" => username,
|
38
|
-
"oauth_version" => "1.0",
|
39
|
-
"oauth_signature_method" => "HMAC-SHA1",
|
40
|
-
"oauth_token" => token,
|
41
|
-
"oauth_timestamp" => timestamp,
|
42
|
-
}
|
43
|
-
sorted_query_string = params.sort.map{|v| v.join("=") }.join("&")
|
44
|
-
|
45
|
-
base = [
|
46
|
-
"POST",
|
47
|
-
paypal_encode(url),
|
48
|
-
paypal_encode(sorted_query_string)
|
49
|
-
].join("&")
|
50
|
-
base = base.gsub(/%[0-9A-F][0-9A-F]/, &:downcase )
|
51
|
-
end
|
52
|
-
|
53
|
-
# The PayPalURLEncoder java class percent encodes everything other than 'a-zA-Z0-9 _'.
|
54
|
-
# Then it converts ' ' to '+'.
|
55
|
-
# Ruby's CGI.encode takes care of the ' ' and '*' to satisfy PayPal
|
56
|
-
# (but beware, URI.encode percent encodes spaces, and does nothing with '*').
|
57
|
-
# Finally, CGI.encode does not encode '.-', which we need to do here.
|
58
|
-
def paypal_encode str
|
59
|
-
CGI.escape(str.to_s).gsub('.', '%2E').gsub('-', '%2D')
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
@@ -1,165 +0,0 @@
|
|
1
|
-
module PayPal::SDK::Core
|
2
|
-
module Util
|
3
|
-
class OrderedHash < ::Hash #:nodoc:
|
4
|
-
|
5
|
-
def to_yaml_type
|
6
|
-
"!tag:yaml.org,2002:map"
|
7
|
-
end
|
8
|
-
|
9
|
-
# Hash is ordered in Ruby 1.9!
|
10
|
-
if RUBY_VERSION < '1.9'
|
11
|
-
|
12
|
-
# In MRI the Hash class is core and written in C. In particular, methods are
|
13
|
-
# programmed with explicit C function calls and polymorphism is not honored.
|
14
|
-
#
|
15
|
-
# For example, []= is crucial in this implementation to maintain the @keys
|
16
|
-
# array but hash.c invokes rb_hash_aset() originally. This prevents method
|
17
|
-
# reuse through inheritance and forces us to reimplement stuff.
|
18
|
-
#
|
19
|
-
# For instance, we cannot use the inherited #merge! because albeit the algorithm
|
20
|
-
# itself would work, our []= is not being called at all by the C code.
|
21
|
-
|
22
|
-
def initialize(*args, &block)
|
23
|
-
super
|
24
|
-
@keys = []
|
25
|
-
end
|
26
|
-
|
27
|
-
def self.[](*args)
|
28
|
-
ordered_hash = new
|
29
|
-
|
30
|
-
if (args.length == 1 && args.first.is_a?(Array))
|
31
|
-
args.first.each do |key_value_pair|
|
32
|
-
next unless (key_value_pair.is_a?(Array))
|
33
|
-
ordered_hash[key_value_pair[0]] = key_value_pair[1]
|
34
|
-
end
|
35
|
-
|
36
|
-
return ordered_hash
|
37
|
-
end
|
38
|
-
|
39
|
-
unless (args.size % 2 == 0)
|
40
|
-
raise ArgumentError.new("odd number of arguments for Hash")
|
41
|
-
end
|
42
|
-
|
43
|
-
args.each_with_index do |val, ind|
|
44
|
-
next if (ind % 2 != 0)
|
45
|
-
ordered_hash[val] = args[ind + 1]
|
46
|
-
end
|
47
|
-
|
48
|
-
ordered_hash
|
49
|
-
end
|
50
|
-
|
51
|
-
def initialize_copy(other)
|
52
|
-
super
|
53
|
-
# make a deep copy of keys
|
54
|
-
@keys = other.keys
|
55
|
-
end
|
56
|
-
|
57
|
-
def []=(key, value)
|
58
|
-
@keys << key if !has_key?(key)
|
59
|
-
super
|
60
|
-
end
|
61
|
-
|
62
|
-
def delete(key)
|
63
|
-
if has_key? key
|
64
|
-
index = @keys.index(key)
|
65
|
-
@keys.delete_at index
|
66
|
-
end
|
67
|
-
super
|
68
|
-
end
|
69
|
-
|
70
|
-
def delete_if
|
71
|
-
super
|
72
|
-
sync_keys!
|
73
|
-
self
|
74
|
-
end
|
75
|
-
|
76
|
-
def reject!
|
77
|
-
super
|
78
|
-
sync_keys!
|
79
|
-
self
|
80
|
-
end
|
81
|
-
|
82
|
-
def reject(&block)
|
83
|
-
dup.reject!(&block)
|
84
|
-
end
|
85
|
-
|
86
|
-
def keys
|
87
|
-
@keys.dup
|
88
|
-
end
|
89
|
-
|
90
|
-
def values
|
91
|
-
@keys.collect { |key| self[key] }
|
92
|
-
end
|
93
|
-
|
94
|
-
def to_hash
|
95
|
-
self
|
96
|
-
end
|
97
|
-
|
98
|
-
def to_a
|
99
|
-
@keys.map { |key| [ key, self[key] ] }
|
100
|
-
end
|
101
|
-
|
102
|
-
def each_key
|
103
|
-
@keys.each { |key| yield key }
|
104
|
-
end
|
105
|
-
|
106
|
-
def each_value
|
107
|
-
@keys.each { |key| yield self[key]}
|
108
|
-
end
|
109
|
-
|
110
|
-
def each
|
111
|
-
@keys.each {|key| yield [key, self[key]]}
|
112
|
-
end
|
113
|
-
|
114
|
-
alias_method :each_pair, :each
|
115
|
-
|
116
|
-
def clear
|
117
|
-
super
|
118
|
-
@keys.clear
|
119
|
-
self
|
120
|
-
end
|
121
|
-
|
122
|
-
def shift
|
123
|
-
k = @keys.first
|
124
|
-
v = delete(k)
|
125
|
-
[k, v]
|
126
|
-
end
|
127
|
-
|
128
|
-
def merge!(other_hash)
|
129
|
-
if block_given?
|
130
|
-
other_hash.each { |k, v| self[k] = key?(k) ? yield(k, self[k], v) : v }
|
131
|
-
else
|
132
|
-
other_hash.each { |k, v| self[k] = v }
|
133
|
-
end
|
134
|
-
self
|
135
|
-
end
|
136
|
-
|
137
|
-
alias_method :update, :merge!
|
138
|
-
|
139
|
-
def merge(other_hash, &block)
|
140
|
-
dup.merge!(other_hash, &block)
|
141
|
-
end
|
142
|
-
|
143
|
-
# When replacing with another hash, the initial order of our keys must come from the other hash -ordered or not.
|
144
|
-
def replace(other)
|
145
|
-
super
|
146
|
-
@keys = other.keys
|
147
|
-
self
|
148
|
-
end
|
149
|
-
|
150
|
-
def invert
|
151
|
-
OrderedHash[self.to_a.map!{|key_value_pair| key_value_pair.reverse}]
|
152
|
-
end
|
153
|
-
|
154
|
-
def inspect
|
155
|
-
"#<OrderedHash #{super}>"
|
156
|
-
end
|
157
|
-
|
158
|
-
private
|
159
|
-
def sync_keys!
|
160
|
-
@keys.delete_if {|k| !has_key?(k)}
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
end
|
data/lib/paypal-sdk/core/util.rb
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
module PayPal
|
2
|
-
module SDK
|
3
|
-
module Core
|
4
|
-
module Util
|
5
|
-
autoload :OauthSignature, "paypal-sdk/core/util/oauth_signature"
|
6
|
-
autoload :OrderedHash, "paypal-sdk/core/util/ordered_hash"
|
7
|
-
autoload :HTTPHelper, "paypal-sdk/core/util/http_helper"
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
data/lib/paypal-sdk/rest/api.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'paypal-sdk-core'
|
2
|
-
require 'paypal-sdk/rest/version'
|
3
|
-
|
4
|
-
module PayPal
|
5
|
-
module SDK
|
6
|
-
module REST
|
7
|
-
class API < Core::API::REST
|
8
|
-
# include Services
|
9
|
-
|
10
|
-
def initialize(environment = nil, options = {})
|
11
|
-
super("", environment, options)
|
12
|
-
end
|
13
|
-
|
14
|
-
class << self
|
15
|
-
def user_agent
|
16
|
-
@user_agent ||= "PayPalSDK/PayPal-Ruby-SDK #{PayPal::SDK::REST::VERSION} (#{sdk_library_details})"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|