paypal-sdk-rest 1.7.4 → 2.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -14
- data/README.md +45 -251
- 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 +250 -120
- 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.rb +0 -38
- data/lib/paypal-sdk-rest.rb +0 -2
- data/lib/paypal-sdk/core/api.rb +0 -20
- 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/authentication.rb +0 -66
- data/lib/paypal-sdk/core/config.rb +0 -253
- data/lib/paypal-sdk/core/credential.rb +0 -16
- 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/exceptions.rb +0 -112
- data/lib/paypal-sdk/core/logging.rb +0 -50
- data/lib/paypal-sdk/core/openid_connect.rb +0 -140
- 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/util.rb +0 -11
- 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/rest.rb +0 -39
- 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/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,39 +0,0 @@
|
|
1
|
-
module PayPal::SDK::Core
|
2
|
-
module Credential
|
3
|
-
module ThirdParty
|
4
|
-
class Token
|
5
|
-
|
6
|
-
attr_accessor :token, :token_secret, :credential, :url
|
7
|
-
|
8
|
-
# Initialize Token credentials
|
9
|
-
# === Arguments
|
10
|
-
# * <tt>credential</tt> -- Credential Object
|
11
|
-
# * <tt>config</tt> -- Configuration object
|
12
|
-
# * <tt>url</tt> -- Request url
|
13
|
-
def initialize(credential, config, url)
|
14
|
-
@credential = credential
|
15
|
-
@token = config.token
|
16
|
-
@token_secret = config.token_secret
|
17
|
-
@url = url
|
18
|
-
end
|
19
|
-
|
20
|
-
RemoveProperties = [ :username, :password, :signature ]
|
21
|
-
|
22
|
-
# Return credential properties for authentication.
|
23
|
-
def properties
|
24
|
-
credential_properties = credential.properties
|
25
|
-
credential_properties.delete_if{|k,v| RemoveProperties.include? k }
|
26
|
-
credential_properties.merge( :authorization => oauth_authentication )
|
27
|
-
end
|
28
|
-
|
29
|
-
private
|
30
|
-
# Return OAuth authentication string.
|
31
|
-
def oauth_authentication
|
32
|
-
Util::OauthSignature.new(credential.username, credential.password, token, token_secret, url).
|
33
|
-
authorization_string
|
34
|
-
end
|
35
|
-
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,112 +0,0 @@
|
|
1
|
-
require 'json'
|
2
|
-
require 'pp'
|
3
|
-
|
4
|
-
module PayPal::SDK::Core
|
5
|
-
module Exceptions
|
6
|
-
class ConnectionError < StandardError # :nodoc:
|
7
|
-
attr_reader :response
|
8
|
-
|
9
|
-
def initialize(response, message = nil)
|
10
|
-
@response = response
|
11
|
-
@message = message
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_s
|
15
|
-
begin
|
16
|
-
response_body = JSON.parse(response.body)
|
17
|
-
debug_id = response["paypal-debug-id"]
|
18
|
-
debug_id = response["correlation-id"] if debug_id.to_s == ''
|
19
|
-
debug_id = response_body["debug_id"] if debug_id.to_s == ''
|
20
|
-
rescue
|
21
|
-
end
|
22
|
-
message = "Failed."
|
23
|
-
message << " Response code = #{response.code}." if response.respond_to?(:code)
|
24
|
-
message << " Response message = #{response.message}." if response.respond_to?(:message)
|
25
|
-
message << " Response debug ID = #{debug_id}." if debug_id
|
26
|
-
message
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# Raised when a Timeout::Error occurs.
|
31
|
-
class TimeoutError < ConnectionError
|
32
|
-
def initialize(message)
|
33
|
-
@message = message
|
34
|
-
end
|
35
|
-
def to_s; @message ;end
|
36
|
-
end
|
37
|
-
|
38
|
-
# Raised when a OpenSSL::SSL::SSLError occurs.
|
39
|
-
class SSLError < ConnectionError
|
40
|
-
def initialize(message)
|
41
|
-
@message = message
|
42
|
-
end
|
43
|
-
def to_s; @message ;end
|
44
|
-
end
|
45
|
-
|
46
|
-
# 3xx Redirection
|
47
|
-
class Redirection < ConnectionError # :nodoc:
|
48
|
-
def to_s
|
49
|
-
response['Location'] ? "#{super} => #{response['Location']}" : super
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
class MissingParam < ArgumentError # :nodoc:
|
54
|
-
end
|
55
|
-
|
56
|
-
class MissingConfig < StandardError # :nodoc:
|
57
|
-
end
|
58
|
-
|
59
|
-
# 4xx Client Error
|
60
|
-
class ClientError < ConnectionError # :nodoc:
|
61
|
-
end
|
62
|
-
|
63
|
-
# 400 Bad Request
|
64
|
-
class BadRequest < ClientError # :nodoc:
|
65
|
-
end
|
66
|
-
|
67
|
-
# 401 Unauthorized
|
68
|
-
class UnauthorizedAccess < ClientError # :nodoc:
|
69
|
-
end
|
70
|
-
|
71
|
-
# 403 Forbidden
|
72
|
-
class ForbiddenAccess < ClientError # :nodoc:
|
73
|
-
end
|
74
|
-
|
75
|
-
# 404 Not Found
|
76
|
-
class ResourceNotFound < ClientError # :nodoc:
|
77
|
-
end
|
78
|
-
|
79
|
-
# 409 Conflict
|
80
|
-
class ResourceConflict < ClientError # :nodoc:
|
81
|
-
end
|
82
|
-
|
83
|
-
# 410 Gone
|
84
|
-
class ResourceGone < ClientError # :nodoc:
|
85
|
-
end
|
86
|
-
|
87
|
-
# 422 Unprocessable Entity
|
88
|
-
class ResourceInvalid < ClientError # :nodoc:
|
89
|
-
end
|
90
|
-
|
91
|
-
# 5xx Server Error
|
92
|
-
class ServerError < ConnectionError # :nodoc:
|
93
|
-
end
|
94
|
-
|
95
|
-
# 405 Method Not Allowed
|
96
|
-
class MethodNotAllowed < ClientError # :nodoc:
|
97
|
-
def allowed_methods
|
98
|
-
@response['Allow'].split(',').map { |verb| verb.strip.downcase.to_sym }
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
# API error: returned as 200 + "error" key in response.
|
103
|
-
class UnsuccessfulApiCall < RuntimeError
|
104
|
-
attr_reader :api_error
|
105
|
-
|
106
|
-
def initialize(api_error)
|
107
|
-
super(api_error['message'])
|
108
|
-
@api_error = api_error
|
109
|
-
end
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'logger'
|
2
|
-
|
3
|
-
module PayPal::SDK::Core
|
4
|
-
|
5
|
-
# Include Logging module to provide logger functionality.
|
6
|
-
# == Configure logger
|
7
|
-
# Logging.logger = Logger.new(STDERR)
|
8
|
-
#
|
9
|
-
# == Example
|
10
|
-
# include Logger
|
11
|
-
# logger.info "Debug message"
|
12
|
-
module Logging
|
13
|
-
|
14
|
-
# Get logger object
|
15
|
-
def logger
|
16
|
-
@logger ||= Logging.logger
|
17
|
-
end
|
18
|
-
|
19
|
-
def log_event(message, &block)
|
20
|
-
start_time = Time.now
|
21
|
-
block.call
|
22
|
-
ensure
|
23
|
-
logger.info sprintf("[%.3fs] %s", Time.now - start_time, message)
|
24
|
-
end
|
25
|
-
|
26
|
-
class << self
|
27
|
-
|
28
|
-
# Get or Create configured logger based on the default environment configuration
|
29
|
-
def logger
|
30
|
-
@logger ||= Logger.new(STDERR)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Set logger directly and clear the loggers cache.
|
34
|
-
# === Attributes
|
35
|
-
# * <tt>logger</tt> -- Logger object
|
36
|
-
# === Example
|
37
|
-
# Logging.logger = Logger.new(STDERR)
|
38
|
-
def logger=(logger)
|
39
|
-
@logger = logger
|
40
|
-
if Config.config.mode.eql? 'live' and @logger.level == Logger::DEBUG
|
41
|
-
@logger.warn "DEBUG log level not allowed in sandbox mode for security of confidential information. Changing log level to INFO..."
|
42
|
-
@logger.level = Logger::INFO
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
end
|
50
|
-
|
@@ -1,140 +0,0 @@
|
|
1
|
-
|
2
|
-
module PayPal::SDK
|
3
|
-
module Core
|
4
|
-
module OpenIDConnect
|
5
|
-
autoload :API, "paypal-sdk/core/openid_connect/api"
|
6
|
-
autoload :SetAPI, "paypal-sdk/core/openid_connect/set_api"
|
7
|
-
autoload :GetAPI, "paypal-sdk/core/openid_connect/get_api"
|
8
|
-
autoload :RequestDataType, "paypal-sdk/core/openid_connect/request_data_type"
|
9
|
-
autoload :DataTypes, "paypal-sdk/core/openid_connect/data_types"
|
10
|
-
|
11
|
-
include DataTypes
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def api
|
15
|
-
RequestDataType.api
|
16
|
-
end
|
17
|
-
|
18
|
-
def set_config(*args)
|
19
|
-
RequestDataType.set_config(*args)
|
20
|
-
end
|
21
|
-
alias_method :config=, :set_config
|
22
|
-
|
23
|
-
AUTHORIZATION_URL = "paypal.com/signin/authorize"
|
24
|
-
ENDSESSION_URL = "paypal.com/webapps/auth/protocol/openidconnect/v1/endsession"
|
25
|
-
DEFAULT_SCOPE = "openid"
|
26
|
-
|
27
|
-
def authorize_url(params = {})
|
28
|
-
uri = URI(url_for_mode(AUTHORIZATION_URL))
|
29
|
-
uri.query = api.encode_www_form({
|
30
|
-
:response_type => "code",
|
31
|
-
:scope => DEFAULT_SCOPE,
|
32
|
-
:client_id => RequestDataType.client_id,
|
33
|
-
:redirect_uri => api.config.openid_redirect_uri
|
34
|
-
}.merge(params))
|
35
|
-
uri.to_s
|
36
|
-
end
|
37
|
-
|
38
|
-
def logout_url(params = {})
|
39
|
-
uri = URI(url_for_mode(ENDSESSION_URL))
|
40
|
-
uri.query = api.encode_www_form({
|
41
|
-
:logout => "true",
|
42
|
-
:redirect_uri => api.config.openid_redirect_uri
|
43
|
-
}.merge(params))
|
44
|
-
uri.to_s
|
45
|
-
end
|
46
|
-
|
47
|
-
private
|
48
|
-
|
49
|
-
def url_for_mode(url)
|
50
|
-
"https://www.#{"sandbox." if api.api_mode == :sandbox}#{url}"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
module DataTypes
|
55
|
-
class Tokeninfo < Base
|
56
|
-
include RequestDataType
|
57
|
-
PATH = "v1/identity/openidconnect/tokenservice"
|
58
|
-
FP_PATH = "v1/oauth2/token"
|
59
|
-
|
60
|
-
class << self
|
61
|
-
|
62
|
-
def basic_auth_header(options)
|
63
|
-
credentials = options[:client_id].to_s + ":" + options[:client_secret].to_s
|
64
|
-
encoded = Base64.encode64(credentials.force_encoding('UTF-8')).gsub!(/\n/, "")
|
65
|
-
"Basic #{encoded}"
|
66
|
-
end
|
67
|
-
|
68
|
-
def create_from_authorization_code(options, http_header = {})
|
69
|
-
options = { :code => options } if options.is_a? String
|
70
|
-
options = options.merge( :grant_type => "authorization_code" )
|
71
|
-
Tokeninfo.new(api.post(PATH, with_credentials(options), http_header))
|
72
|
-
end
|
73
|
-
alias_method :create, :create_from_authorization_code
|
74
|
-
|
75
|
-
def create_from_refresh_token(options, http_header = {})
|
76
|
-
options = { :refresh_token => options } if options.is_a? String
|
77
|
-
options = options.merge( :grant_type => "refresh_token" )
|
78
|
-
http_header = http_header.merge( { "Content-Type" => "application/x-www-form-urlencoded", "Authorization" => basic_auth_header(with_credentials(options)) } )
|
79
|
-
Tokeninfo.new(api.post(PATH, options, http_header))
|
80
|
-
end
|
81
|
-
alias_method :refresh, :create_from_refresh_token
|
82
|
-
|
83
|
-
def create_from_future_payment_auth_code(options, http_header = {})
|
84
|
-
options = { :code => options } if options.is_a? String
|
85
|
-
options = options.merge( { :grant_type => "authorization_code", :response_type => "token", :redirect_uri => "urn:ietf:wg:oauth:2.0:oob" } )
|
86
|
-
http_header = http_header.merge( { "Content-Type" => "application/x-www-form-urlencoded", "Authorization" => basic_auth_header(with_credentials(options)) } )
|
87
|
-
Tokeninfo.new(api.post(FP_PATH, options, http_header))
|
88
|
-
end
|
89
|
-
alias_method :token_hash, :create_from_future_payment_auth_code
|
90
|
-
alias_method :create_fp, :create_from_future_payment_auth_code
|
91
|
-
|
92
|
-
def with_credentials(options = {})
|
93
|
-
options = options.dup
|
94
|
-
[ :client_id, :client_secret ].each do |key|
|
95
|
-
options[key] = self.send(key) unless options[key] or options[key.to_s]
|
96
|
-
end
|
97
|
-
options
|
98
|
-
end
|
99
|
-
|
100
|
-
def authorize_url(options = {})
|
101
|
-
OpenIDConnect.authorize_url(options)
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
def refresh(options = {})
|
106
|
-
tokeninfo = self.class.refresh({
|
107
|
-
:refresh_token => self.refresh_token}.merge(options))
|
108
|
-
self.merge!(tokeninfo.to_hash)
|
109
|
-
end
|
110
|
-
|
111
|
-
def userinfo(options = {})
|
112
|
-
Userinfo.get({ :access_token => self.access_token }.merge(options))
|
113
|
-
end
|
114
|
-
|
115
|
-
def logout_url(options = {})
|
116
|
-
OpenIDConnect.logout_url({ :id_token => self.id_token }.merge(options))
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
class Userinfo < Base
|
122
|
-
include RequestDataType
|
123
|
-
PATH = "v1/identity/openidconnect/userinfo"
|
124
|
-
|
125
|
-
class << self
|
126
|
-
def get_userinfo(options = {}, http_header = {})
|
127
|
-
options = { :access_token => options } if options.is_a? String
|
128
|
-
options = options.merge( :schema => "openid" ) unless options[:schema] or options["schema"]
|
129
|
-
Userinfo.new(api.post(PATH, options, http_header))
|
130
|
-
end
|
131
|
-
alias_method :get, :get_userinfo
|
132
|
-
end
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
# Alias for the Core::OpenIDConnect constant
|
139
|
-
OpenIDConnect = Core::OpenIDConnect
|
140
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
require 'multi_json'
|
2
|
-
require 'paypal-sdk/rest/version'
|
3
|
-
|
4
|
-
module PayPal::SDK
|
5
|
-
module Core
|
6
|
-
module OpenIDConnect
|
7
|
-
class API < Core::API::Base
|
8
|
-
|
9
|
-
DEFAULT_OPENID_ENDPOINT = {
|
10
|
-
:sandbox => "https://api.sandbox.paypal.com",
|
11
|
-
:live => "https://api.paypal.com" }
|
12
|
-
|
13
|
-
def initialize(environment = nil, options = {})
|
14
|
-
super("", environment, options)
|
15
|
-
end
|
16
|
-
|
17
|
-
def service_endpoint
|
18
|
-
self.config.openid_endpoint || DEFAULT_OPENID_ENDPOINT[self.api_mode] || DEFAULT_OPENID_ENDPOINT[:sandbox]
|
19
|
-
end
|
20
|
-
|
21
|
-
def format_request(payload)
|
22
|
-
payload[:uri].path = url_join(payload[:uri].path, payload[:action])
|
23
|
-
payload[:body] = encode_www_form(payload[:params]) if payload[:params]
|
24
|
-
payload[:header] = {"Content-Type" => "application/x-www-form-urlencoded" }.merge(payload[:header])
|
25
|
-
payload
|
26
|
-
end
|
27
|
-
|
28
|
-
def format_response(payload)
|
29
|
-
payload[:data] =
|
30
|
-
if payload[:response].code >= "200" and payload[:response].code <= "299"
|
31
|
-
MultiJson.load(payload[:response].body)
|
32
|
-
elsif payload[:response].content_type == "application/json"
|
33
|
-
{ "error" => MultiJson.load(payload[:response].body) }
|
34
|
-
else
|
35
|
-
{ "error" => { "name" => payload[:response].code, "message" => payload[:response].message,
|
36
|
-
"developer_msg" => payload[:response] } }
|
37
|
-
end
|
38
|
-
payload
|
39
|
-
end
|
40
|
-
|
41
|
-
class << self
|
42
|
-
def user_agent
|
43
|
-
@user_agent ||= "PayPalSDK/openid-connect-ruby #{PayPal::SDK::REST::VERSION} (#{sdk_library_details})"
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,73 +0,0 @@
|
|
1
|
-
require 'paypal-sdk-core'
|
2
|
-
|
3
|
-
module PayPal::SDK::Core
|
4
|
-
module OpenIDConnect
|
5
|
-
module DataTypes
|
6
|
-
class Base < PayPal::SDK::Core::API::DataTypes::Base
|
7
|
-
end
|
8
|
-
|
9
|
-
class Address < Base
|
10
|
-
def self.load_members
|
11
|
-
object_of :street_address, String
|
12
|
-
object_of :locality, String
|
13
|
-
object_of :region, String
|
14
|
-
object_of :postal_code, String
|
15
|
-
object_of :country, String
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
class Userinfo < Base
|
20
|
-
def self.load_members
|
21
|
-
object_of :user_id, String
|
22
|
-
object_of :sub, String
|
23
|
-
object_of :name, String
|
24
|
-
object_of :given_name, String
|
25
|
-
object_of :family_name, String
|
26
|
-
object_of :middle_name, String
|
27
|
-
object_of :picture, String
|
28
|
-
object_of :email, String
|
29
|
-
object_of :email_verified, Boolean
|
30
|
-
object_of :gender, String
|
31
|
-
object_of :birthday, String
|
32
|
-
object_of :zoneinfo, String
|
33
|
-
object_of :locale, String
|
34
|
-
object_of :language, String
|
35
|
-
object_of :verified, Boolean
|
36
|
-
object_of :phone_number, String
|
37
|
-
object_of :address, Address
|
38
|
-
object_of :verified_account, Boolean
|
39
|
-
object_of :account_type, String
|
40
|
-
object_of :account_creation_date, String
|
41
|
-
object_of :age_range, String
|
42
|
-
object_of :payer_id, String
|
43
|
-
end
|
44
|
-
end
|
45
|
-
|
46
|
-
class Tokeninfo < Base
|
47
|
-
def self.load_members
|
48
|
-
object_of :scope, String
|
49
|
-
object_of :access_token, String
|
50
|
-
object_of :refresh_token, String
|
51
|
-
object_of :token_type, String
|
52
|
-
object_of :id_token, String
|
53
|
-
object_of :expires_in, Integer
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
class Error < Base
|
58
|
-
def self.load_members
|
59
|
-
object_of :error, String
|
60
|
-
object_of :error_description, String
|
61
|
-
object_of :error_uri, String
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
constants.each do |data_type_klass|
|
67
|
-
data_type_klass = const_get(data_type_klass)
|
68
|
-
data_type_klass.load_members if defined? data_type_klass.load_members
|
69
|
-
end
|
70
|
-
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|