direct-sdk-ruby 1.0.0
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 +7 -0
- data/Gemfile +2 -0
- data/LICENSE.txt +22 -0
- data/README.md +141 -0
- data/Rakefile +34 -0
- data/direct-sdk-ruby.gemspec +28 -0
- data/lib/ingenico/direct/sdk.rb +26 -0
- data/lib/ingenico/direct/sdk/api_exception.rb +42 -0
- data/lib/ingenico/direct/sdk/api_resource.rb +115 -0
- data/lib/ingenico/direct/sdk/authenticator.rb +16 -0
- data/lib/ingenico/direct/sdk/authorization_exception.rb +13 -0
- data/lib/ingenico/direct/sdk/call_context.rb +26 -0
- data/lib/ingenico/direct/sdk/client.rb +85 -0
- data/lib/ingenico/direct/sdk/communication_exception.rb +16 -0
- data/lib/ingenico/direct/sdk/communicator.rb +301 -0
- data/lib/ingenico/direct/sdk/communicator_configuration.rb +59 -0
- data/lib/ingenico/direct/sdk/connection.rb +41 -0
- data/lib/ingenico/direct/sdk/data_object.rb +32 -0
- data/lib/ingenico/direct/sdk/declined_payment_exception.rb +30 -0
- data/lib/ingenico/direct/sdk/declined_payout_exception.rb +32 -0
- data/lib/ingenico/direct/sdk/declined_refund_exception.rb +32 -0
- data/lib/ingenico/direct/sdk/declined_transaction_exception.rb +16 -0
- data/lib/ingenico/direct/sdk/defaultimpl.rb +6 -0
- data/lib/ingenico/direct/sdk/defaultimpl/authorization_type.rb +24 -0
- data/lib/ingenico/direct/sdk/defaultimpl/default_authenticator.rb +108 -0
- data/lib/ingenico/direct/sdk/defaultimpl/default_connection.rb +293 -0
- data/lib/ingenico/direct/sdk/defaultimpl/default_marshaller.rb +32 -0
- data/lib/ingenico/direct/sdk/direct_exception.rb +15 -0
- data/lib/ingenico/direct/sdk/domain/account_on_file.rb +50 -0
- data/lib/ingenico/direct/sdk/domain/account_on_file_attribute.rb +39 -0
- data/lib/ingenico/direct/sdk/domain/account_on_file_display_hints.rb +38 -0
- data/lib/ingenico/direct/sdk/domain/additional_order_input.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/address.rb +51 -0
- data/lib/ingenico/direct/sdk/domain/address_personal.rb +59 -0
- data/lib/ingenico/direct/sdk/domain/airline_data.rb +129 -0
- data/lib/ingenico/direct/sdk/domain/airline_flight_leg.rb +99 -0
- data/lib/ingenico/direct/sdk/domain/airline_passenger.rb +39 -0
- data/lib/ingenico/direct/sdk/domain/amount_breakdown.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/amount_of_money.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/api_error.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/browser_data.rb +39 -0
- data/lib/ingenico/direct/sdk/domain/cancel_payment_response.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/capture.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/capture_output.rb +79 -0
- data/lib/ingenico/direct/sdk/domain/capture_payment_request.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/capture_response.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/capture_status_output.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/captures_response.rb +34 -0
- data/lib/ingenico/direct/sdk/domain/card.rb +39 -0
- data/lib/ingenico/direct/sdk/domain/card_essentials.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/card_fraud_results.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/card_payment_method_specific_input.rb +95 -0
- data/lib/ingenico/direct/sdk/domain/card_payment_method_specific_input_base.rb +79 -0
- data/lib/ingenico/direct/sdk/domain/card_payment_method_specific_output.rb +67 -0
- data/lib/ingenico/direct/sdk/domain/card_payout_method_specific_input.rb +39 -0
- data/lib/ingenico/direct/sdk/domain/card_recurrence_details.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/card_without_cvv.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/company_information.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/complete_payment_card_payment_method_specific_input.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/complete_payment_request.rb +39 -0
- data/lib/ingenico/direct/sdk/domain/complete_payment_response.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/contact_details.rb +43 -0
- data/lib/ingenico/direct/sdk/domain/create_hosted_checkout_request.rb +63 -0
- data/lib/ingenico/direct/sdk/domain/create_hosted_checkout_response.rb +49 -0
- data/lib/ingenico/direct/sdk/domain/create_hosted_tokenization_request.rb +39 -0
- data/lib/ingenico/direct/sdk/domain/create_hosted_tokenization_response.rb +41 -0
- data/lib/ingenico/direct/sdk/domain/create_payment_request.rb +67 -0
- data/lib/ingenico/direct/sdk/domain/create_payment_response.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/create_payout_request.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/create_token_request.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/created_payment_output.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/created_token_response.rb +51 -0
- data/lib/ingenico/direct/sdk/domain/customer.rb +87 -0
- data/lib/ingenico/direct/sdk/domain/customer_account.rb +71 -0
- data/lib/ingenico/direct/sdk/domain/customer_account_authentication.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/customer_device.rb +51 -0
- data/lib/ingenico/direct/sdk/domain/customer_payment_activity.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/customer_token.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/decrypted_payment_data.rb +43 -0
- data/lib/ingenico/direct/sdk/domain/directory_entry.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/empty_validator.rb +13 -0
- data/lib/ingenico/direct/sdk/domain/error_response.rb +38 -0
- data/lib/ingenico/direct/sdk/domain/external_cardholder_authentication_data.rb +59 -0
- data/lib/ingenico/direct/sdk/domain/external_token_linked.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/fixed_list_validator.rb +33 -0
- data/lib/ingenico/direct/sdk/domain/fraud_fields.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/fraud_results.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/g_pay_three_d_secure.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/get_hosted_checkout_response.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/get_hosted_tokenization_response.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/get_payment_product_groups_response.rb +34 -0
- data/lib/ingenico/direct/sdk/domain/get_payment_products_response.rb +34 -0
- data/lib/ingenico/direct/sdk/domain/gift_card_purchase.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/hosted_checkout_specific_input.rb +55 -0
- data/lib/ingenico/direct/sdk/domain/hosted_checkout_specific_output.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/label_template_element.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/length_validator.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/line_item.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/line_item_invoice_data.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/loan_recipient.rb +43 -0
- data/lib/ingenico/direct/sdk/domain/merchant_action.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/mobile_payment_data.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/mobile_payment_method_specific_input.rb +63 -0
- data/lib/ingenico/direct/sdk/domain/mobile_payment_method_specific_output.rb +59 -0
- data/lib/ingenico/direct/sdk/domain/mobile_payment_product320_specific_input.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/order.rb +71 -0
- data/lib/ingenico/direct/sdk/domain/order_line_details.rb +55 -0
- data/lib/ingenico/direct/sdk/domain/order_references.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/order_status_output.rb +50 -0
- data/lib/ingenico/direct/sdk/domain/order_type_information.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/payment_account_on_file.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/payment_creation_output.rb +39 -0
- data/lib/ingenico/direct/sdk/domain/payment_error_response.rb +46 -0
- data/lib/ingenico/direct/sdk/domain/payment_output.rb +79 -0
- data/lib/ingenico/direct/sdk/domain/payment_product.rb +77 -0
- data/lib/ingenico/direct/sdk/domain/payment_product5100_specific_input.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/payment_product5402_specific_output.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/payment_product5500_specific_output.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/payment_product771_specific_output.rb +13 -0
- data/lib/ingenico/direct/sdk/domain/payment_product840_customer_account.rb +55 -0
- data/lib/ingenico/direct/sdk/domain/payment_product840_specific_output.rb +54 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_display_hints.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_field.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_field_data_restrictions.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_field_display_element.rb +39 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_field_display_hints.rb +71 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_field_form_element.rb +38 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_field_tooltip.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_field_validators.rb +91 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_filter.rb +43 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_filters_hosted_checkout.rb +38 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_group.rb +43 -0
- data/lib/ingenico/direct/sdk/domain/payment_product_networks_response.rb +33 -0
- data/lib/ingenico/direct/sdk/domain/payment_references.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/payment_response.rb +55 -0
- data/lib/ingenico/direct/sdk/domain/payment_status_output.rb +58 -0
- data/lib/ingenico/direct/sdk/domain/payout_error_response.rb +46 -0
- data/lib/ingenico/direct/sdk/domain/payout_output.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/payout_response.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/payout_result.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/payout_status_output.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/personal_information.rb +39 -0
- data/lib/ingenico/direct/sdk/domain/personal_information_token.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/personal_name.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/personal_name_token.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/product_directory.rb +34 -0
- data/lib/ingenico/direct/sdk/domain/protection_eligibility.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/range_validator.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/redirect_data.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/redirect_payment_method_specific_input.rb +67 -0
- data/lib/ingenico/direct/sdk/domain/redirect_payment_method_specific_output.rb +67 -0
- data/lib/ingenico/direct/sdk/domain/redirect_payment_product809_specific_input.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/redirect_payment_product840_specific_input.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/redirection_data.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/refund_card_method_specific_output.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/refund_e_wallet_method_specific_output.rb +39 -0
- data/lib/ingenico/direct/sdk/domain/refund_error_response.rb +46 -0
- data/lib/ingenico/direct/sdk/domain/refund_mobile_method_specific_output.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/refund_output.rb +79 -0
- data/lib/ingenico/direct/sdk/domain/refund_payment_product840_customer_account.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/refund_payment_product840_specific_output.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/refund_redirect_method_specific_output.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/refund_request.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/refund_response.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/refunds_response.rb +34 -0
- data/lib/ingenico/direct/sdk/domain/regular_expression_validator.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/sepa_direct_debit_payment_method_specific_output.rb +43 -0
- data/lib/ingenico/direct/sdk/domain/session_request.rb +33 -0
- data/lib/ingenico/direct/sdk/domain/session_response.rb +49 -0
- data/lib/ingenico/direct/sdk/domain/shipping.rb +51 -0
- data/lib/ingenico/direct/sdk/domain/shopping_cart.rb +65 -0
- data/lib/ingenico/direct/sdk/domain/shopping_cart_extension.rb +52 -0
- data/lib/ingenico/direct/sdk/domain/test_connection.rb +27 -0
- data/lib/ingenico/direct/sdk/domain/three_d_secure.rb +63 -0
- data/lib/ingenico/direct/sdk/domain/three_d_secure_base.rb +47 -0
- data/lib/ingenico/direct/sdk/domain/three_d_secure_data.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/three_d_secure_results.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/token_card.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/token_card_data.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/token_card_specific_input.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/token_data.rb +31 -0
- data/lib/ingenico/direct/sdk/domain/token_e_wallet.rb +35 -0
- data/lib/ingenico/direct/sdk/domain/token_response.rb +55 -0
- data/lib/ingenico/direct/sdk/domain/value_mapping_element.rb +38 -0
- data/lib/ingenico/direct/sdk/endpoint_configuration.rb +127 -0
- data/lib/ingenico/direct/sdk/exceptions.rb +8 -0
- data/lib/ingenico/direct/sdk/factory.rb +136 -0
- data/lib/ingenico/direct/sdk/idempotence_exception.rb +24 -0
- data/lib/ingenico/direct/sdk/logging.rb +10 -0
- data/lib/ingenico/direct/sdk/logging/communicator_logger.rb +22 -0
- data/lib/ingenico/direct/sdk/logging/log_message_builder.rb +56 -0
- data/lib/ingenico/direct/sdk/logging/logging_capable.rb +19 -0
- data/lib/ingenico/direct/sdk/logging/logging_util.rb +271 -0
- data/lib/ingenico/direct/sdk/logging/request_log_message_builder.rb +39 -0
- data/lib/ingenico/direct/sdk/logging/response_log_message_builder.rb +34 -0
- data/lib/ingenico/direct/sdk/logging/ruby_communicator_logger.rb +57 -0
- data/lib/ingenico/direct/sdk/logging/stdout_communicator_logger.rb +34 -0
- data/lib/ingenico/direct/sdk/marshaller.rb +24 -0
- data/lib/ingenico/direct/sdk/marshaller_syntax_exception.rb +6 -0
- data/lib/ingenico/direct/sdk/merchant/hostedcheckout/hosted_checkout_client.rb +87 -0
- data/lib/ingenico/direct/sdk/merchant/hostedtokenization/hosted_tokenization_client.rb +87 -0
- data/lib/ingenico/direct/sdk/merchant/merchant_client.rb +83 -0
- data/lib/ingenico/direct/sdk/merchant/payments/payments_client.rb +291 -0
- data/lib/ingenico/direct/sdk/merchant/payouts/payouts_client.rb +87 -0
- data/lib/ingenico/direct/sdk/merchant/productgroups/get_product_group_params.rb +58 -0
- data/lib/ingenico/direct/sdk/merchant/productgroups/get_product_groups_params.rb +58 -0
- data/lib/ingenico/direct/sdk/merchant/productgroups/product_groups_client.rb +88 -0
- data/lib/ingenico/direct/sdk/merchant/products/get_payment_product_networks_params.rb +39 -0
- data/lib/ingenico/direct/sdk/merchant/products/get_payment_product_params.rb +58 -0
- data/lib/ingenico/direct/sdk/merchant/products/get_payment_products_params.rb +58 -0
- data/lib/ingenico/direct/sdk/merchant/products/get_product_directory_params.rb +31 -0
- data/lib/ingenico/direct/sdk/merchant/products/products_client.rb +156 -0
- data/lib/ingenico/direct/sdk/merchant/services/services_client.rb +52 -0
- data/lib/ingenico/direct/sdk/merchant/sessions/sessions_client.rb +55 -0
- data/lib/ingenico/direct/sdk/merchant/tokens/tokens_client.rb +117 -0
- data/lib/ingenico/direct/sdk/meta_data_provider.rb +150 -0
- data/lib/ingenico/direct/sdk/modules.rb +71 -0
- data/lib/ingenico/direct/sdk/not_found_exception.rb +16 -0
- data/lib/ingenico/direct/sdk/param_request.rb +11 -0
- data/lib/ingenico/direct/sdk/pooled_connection.rb +21 -0
- data/lib/ingenico/direct/sdk/proxy_configuration.rb +74 -0
- data/lib/ingenico/direct/sdk/reference_exception.rb +14 -0
- data/lib/ingenico/direct/sdk/request_header.rb +50 -0
- data/lib/ingenico/direct/sdk/request_param.rb +23 -0
- data/lib/ingenico/direct/sdk/response_exception.rb +47 -0
- data/lib/ingenico/direct/sdk/response_header.rb +42 -0
- data/lib/ingenico/direct/sdk/validation_exception.rb +14 -0
- data/lib/ingenico/direct/sdk/webhooks.rb +11 -0
- data/lib/ingenico/direct/sdk/webhooks/api_version_mismatch_exception.rb +20 -0
- data/lib/ingenico/direct/sdk/webhooks/in_memory_secret_key_store.rb +56 -0
- data/lib/ingenico/direct/sdk/webhooks/secret_key_not_available_exception.rb +17 -0
- data/lib/ingenico/direct/sdk/webhooks/secret_key_store.rb +16 -0
- data/lib/ingenico/direct/sdk/webhooks/signature_validation_exception.rb +19 -0
- data/lib/ingenico/direct/sdk/webhooks/webhooks.rb +22 -0
- data/lib/ingenico/direct/sdk/webhooks/webhooks_event.rb +58 -0
- data/lib/ingenico/direct/sdk/webhooks/webhooks_helper.rb +99 -0
- data/lib/ingenico/direct/sdk/webhooks/webhooks_helper_builder.rb +25 -0
- metadata +385 -0
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
|
|
3
|
+
# Contains the URL, username and password of a proxy.
|
|
4
|
+
#
|
|
5
|
+
# @attr [String] scheme Proxy scheme (http or https)
|
|
6
|
+
# @attr [String] host Proxy hostname
|
|
7
|
+
# @attr [Integer] port Proxy port
|
|
8
|
+
# @attr [String] username Proxy authentication username
|
|
9
|
+
# @attr [String] password Proxy authentication password
|
|
10
|
+
class ProxyConfiguration
|
|
11
|
+
|
|
12
|
+
# Initialize a new ProxyConfiguration from the parameter hash.
|
|
13
|
+
# In order to be complete either host, port and scheme, or an address is required.
|
|
14
|
+
#
|
|
15
|
+
# @param args [Hash] the parameters to initialize the proxy configuration with
|
|
16
|
+
# @option args [String] :host host part of the URL to the proxy.
|
|
17
|
+
# @option args [Integer] :port port the proxy will be accessed through.
|
|
18
|
+
# @option args [String] :scheme HTTP scheme used to communicate with the proxy (http or https).
|
|
19
|
+
# @option args [String] :address full URI to the proxy excluding username and password.
|
|
20
|
+
# If given this uri takes precedence over individual host, port and scheme.
|
|
21
|
+
# @option args [String] :username username used in authentication to the proxy.
|
|
22
|
+
# @option args [String] :password password used to authenticate to the proxy.
|
|
23
|
+
def initialize(args)
|
|
24
|
+
|
|
25
|
+
host = args[:host]
|
|
26
|
+
port = args[:port]
|
|
27
|
+
username = args[:username]
|
|
28
|
+
password = args[:password]
|
|
29
|
+
scheme = args[:scheme] || 'http'
|
|
30
|
+
|
|
31
|
+
# Don't switch the order, a given address overrides host, port and username
|
|
32
|
+
address = args[:address]
|
|
33
|
+
host = address.host if address
|
|
34
|
+
port = address.port if address
|
|
35
|
+
scheme = address.scheme if address
|
|
36
|
+
|
|
37
|
+
raise ArgumentError, 'scheme is required' unless scheme && !scheme.strip.empty?
|
|
38
|
+
raise ArgumentError, 'host is required' unless host && !host.strip.empty?
|
|
39
|
+
raise ArgumentError, 'port is required' unless port&.positive? && port <= 65535
|
|
40
|
+
|
|
41
|
+
@host = host
|
|
42
|
+
@port = port
|
|
43
|
+
@username = username
|
|
44
|
+
@password = password
|
|
45
|
+
@scheme = scheme
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
attr_accessor :scheme
|
|
49
|
+
attr_accessor :host
|
|
50
|
+
attr_accessor :port
|
|
51
|
+
|
|
52
|
+
attr_accessor :username
|
|
53
|
+
attr_accessor :password
|
|
54
|
+
|
|
55
|
+
# @return [String] a URL string representation of the proxy, excluding authentication.
|
|
56
|
+
def proxy_uri
|
|
57
|
+
"#{scheme}://#{host}:#{port}"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def to_s
|
|
61
|
+
proxy_uri
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
private
|
|
65
|
+
|
|
66
|
+
def self.get_port(address)
|
|
67
|
+
port = address.port
|
|
68
|
+
return port if port != -1
|
|
69
|
+
return 80 if address.scheme.casecmp('http') == 0
|
|
70
|
+
return 443 if address.scheme.casecmp('https') == 0
|
|
71
|
+
raise ArgumentError, "unsupported scheme: #{address.scheme}"
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
|
|
3
|
+
# This error is raised when the request refers to a resource or object that is not found by the Ingenico ePayments platform.
|
|
4
|
+
# The object referred to may not exist or it could have been removed recently.
|
|
5
|
+
class ReferenceException < ApiException
|
|
6
|
+
|
|
7
|
+
# Create a new ReferenceException.
|
|
8
|
+
# @see ApiException#initialize
|
|
9
|
+
def initialize(status_code, response_body, error_id, errors,
|
|
10
|
+
message = 'the Ingenico ePayments platform returned a reference error response')
|
|
11
|
+
super(status_code, response_body, error_id, errors, message)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
|
|
3
|
+
# Represents HTTP request headers
|
|
4
|
+
# Each header is immutable has a #name and #value attribute
|
|
5
|
+
#
|
|
6
|
+
# @attr_reader [String] name HTTP header name
|
|
7
|
+
# @attr_reader [String] value HTTP header value
|
|
8
|
+
class RequestHeader
|
|
9
|
+
|
|
10
|
+
# Create a new header using the name and value given as parameters.
|
|
11
|
+
def initialize(name, value)
|
|
12
|
+
raise ArgumentError, 'name is required' if name.nil? || name.strip.empty?
|
|
13
|
+
@name = name
|
|
14
|
+
@value = normalize_value(value)
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
attr_reader :name
|
|
18
|
+
attr_reader :value
|
|
19
|
+
|
|
20
|
+
def to_s
|
|
21
|
+
"#{name}:#{value}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Return the {Ingenico::Direct::SDK::ResponseHeader} that goes by the given _header_name_,
|
|
25
|
+
# If this Response does not contain a header with the given name, return _nil_ instead
|
|
26
|
+
def self.get_header(headers, header_name)
|
|
27
|
+
selected_headers = headers.select { |h| h.name == header_name }
|
|
28
|
+
return selected_headers&.length.positive? ?
|
|
29
|
+
selected_headers[0] :
|
|
30
|
+
nil
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Returns the header value of the header that goes by the given _header_name_,
|
|
34
|
+
# If this response does not contain a header with the given name, return _nil_ instead
|
|
35
|
+
def self.get_header_value(headers, header_name)
|
|
36
|
+
return get_header(headers, header_name)&.value
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
private
|
|
40
|
+
|
|
41
|
+
def normalize_value(value)
|
|
42
|
+
return value if value.nil? || value.empty?
|
|
43
|
+
# Replace all sequences of whitespace*-linebreak-whitespace* into a single linebreak-space
|
|
44
|
+
# This will ensure that:
|
|
45
|
+
# - no line ends with whitespace, because this causes authentication failures
|
|
46
|
+
# - each line starts with a single whitespace, so it is a valid header value
|
|
47
|
+
value.gsub(/[\s&&[^\r\n]]*(\r?\n)[\s&&[^\r\n]]*/, '\1 ')
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
|
|
3
|
+
# Represents a URL request parameter.
|
|
4
|
+
# Each parameter is immutable and has a #name and #value attribute.
|
|
5
|
+
#
|
|
6
|
+
# @attr_reader [String] name Parameter name
|
|
7
|
+
# @attr_reader [String] value Parameter value
|
|
8
|
+
class RequestParam
|
|
9
|
+
|
|
10
|
+
def initialize(name, value)
|
|
11
|
+
raise ArgumentError, 'name is required' if name.nil? || name.strip.empty?
|
|
12
|
+
@name = name
|
|
13
|
+
@value = value
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
attr_reader :name
|
|
17
|
+
attr_reader :value
|
|
18
|
+
|
|
19
|
+
def to_s
|
|
20
|
+
"#{name}=#{value}"
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
|
|
3
|
+
# Exception used internally in the SDK to indicate an error response was received from the Ingenico ePayments platform.
|
|
4
|
+
#
|
|
5
|
+
# @attr_reader [Integer] status_code HTTP status code that was returned by the Ingenico ePayments platform
|
|
6
|
+
# @attr_reader [String] body HTTP message body that was returned by the Ingenico ePayments platform
|
|
7
|
+
# @attr_reader [Array<Ingenico:Direct:SDK:ResponseHeader>] headers HTTP headers used in the response from the Ingenico ePayments platform
|
|
8
|
+
class ResponseException < RuntimeError
|
|
9
|
+
|
|
10
|
+
def initialize(status_code, headers, body)
|
|
11
|
+
super('the Ingenico ePayments platform returned an error response')
|
|
12
|
+
@status_code = status_code
|
|
13
|
+
@headers = if headers.nil? || headers.empty?
|
|
14
|
+
{}
|
|
15
|
+
else
|
|
16
|
+
headers.inject({}) do |hash, header|
|
|
17
|
+
hash[header.name.downcase.to_sym] = header.dup.freeze
|
|
18
|
+
hash
|
|
19
|
+
end
|
|
20
|
+
end.freeze
|
|
21
|
+
@body = body
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
attr_reader :status_code
|
|
25
|
+
attr_reader :body
|
|
26
|
+
attr_reader :headers
|
|
27
|
+
|
|
28
|
+
# Returns the {Ingenico::Direct::SDK::ResponseHeader} that corresponds to the given _header_name_
|
|
29
|
+
# used in the HTTP response from the Ingenico ePayments platform, or *nil* if the header was not present in the response.
|
|
30
|
+
def get_header(header_name)
|
|
31
|
+
ResponseHeader.get_header(@headers, header_name)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
# Returns the header value received that corresponds to the header named by _header_name_,
|
|
35
|
+
# or *nil* if _header_name_ was not a header present in the HTTP response.
|
|
36
|
+
def get_header_value(header_name)
|
|
37
|
+
ResponseHeader.get_header_value(@headers, header_name)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def to_s
|
|
41
|
+
str = super.to_s
|
|
42
|
+
str += "; status_code=#{@status_code}" if @status_code.positive?
|
|
43
|
+
str += "; response_body='#{@body}'" if @body&.length.positive?
|
|
44
|
+
str.to_s
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
|
|
3
|
+
# Represents HTTP response headers
|
|
4
|
+
# Each header is immutable has a #name and #value attribute
|
|
5
|
+
#
|
|
6
|
+
# @attr_reader [String] name HTTP header name
|
|
7
|
+
# @attr_reader [String] value HTTP header value
|
|
8
|
+
class ResponseHeader
|
|
9
|
+
|
|
10
|
+
# Create a new header using the name and value given as parameters.
|
|
11
|
+
def initialize(name, value)
|
|
12
|
+
raise ArgumentError, 'name is required' if name.nil? || name.strip.empty?
|
|
13
|
+
@name = name
|
|
14
|
+
@value = value
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
attr_reader :name
|
|
18
|
+
attr_reader :value
|
|
19
|
+
|
|
20
|
+
def to_s
|
|
21
|
+
"#{name}:#{value}"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Return the {Ingenico::Direct::SDK::ResponseHeader} that goes by the given _header_name_,
|
|
25
|
+
# If this Response does not contain a header with the given name, return _nil_ instead
|
|
26
|
+
def self.get_header(headers, header_name)
|
|
27
|
+
selected_headers = headers.select { |h| h.name.casecmp(header_name) == 0 }
|
|
28
|
+
if selected_headers.nil? || selected_headers.length == 0
|
|
29
|
+
return nil
|
|
30
|
+
else
|
|
31
|
+
return selected_headers[0]
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Returns the header value of the header that goes by the given _header_name_,
|
|
36
|
+
# If this response does not contain a header with the given name, return _nil_ instead
|
|
37
|
+
def self.get_header_value(headers, header_name)
|
|
38
|
+
header = get_header(headers, header_name)
|
|
39
|
+
return header&.value
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
|
|
3
|
+
# Raised when the request sent to the Ingenico ePayments platform returned a HTTP response with status code 400.
|
|
4
|
+
# This indicates the request received by the Ingenico ePayments platform was malformed.
|
|
5
|
+
class ValidationException < ApiException
|
|
6
|
+
|
|
7
|
+
# Create a new ValidationException
|
|
8
|
+
# @see ApiException#initialize
|
|
9
|
+
def initialize(status_code, response_body, error_id, errors,
|
|
10
|
+
message = 'the Ingenico ePayments platform returned an incorrect request error response')
|
|
11
|
+
super(status_code, response_body, error_id, errors, message)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
prefix = 'ingenico/direct/sdk/webhooks'
|
|
2
|
+
|
|
3
|
+
require "#{prefix}/api_version_mismatch_exception"
|
|
4
|
+
require "#{prefix}/signature_validation_exception"
|
|
5
|
+
require "#{prefix}/secret_key_not_available_exception"
|
|
6
|
+
require "#{prefix}/secret_key_store"
|
|
7
|
+
require "#{prefix}/in_memory_secret_key_store"
|
|
8
|
+
require "#{prefix}/webhooks_event"
|
|
9
|
+
require "#{prefix}/webhooks_helper"
|
|
10
|
+
require "#{prefix}/webhooks_helper_builder"
|
|
11
|
+
require "#{prefix}/webhooks"
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
module Webhooks
|
|
3
|
+
# Raised when a webhooks event has an API version that is not supported by current version
|
|
4
|
+
# of SDK.
|
|
5
|
+
#
|
|
6
|
+
# @attr_reader [String] event_api_version The API version from the webhooks event.
|
|
7
|
+
# @attr_reader [String] sdk_api_version The API version that this version of the SDK supports.
|
|
8
|
+
class ApiVersionMismatchException < RuntimeError
|
|
9
|
+
|
|
10
|
+
def initialize(event_api_version, sdk_api_version)
|
|
11
|
+
super("event API version '#{event_api_version}' is not compatible with SDK API version '#{sdk_api_version}'")
|
|
12
|
+
@event_api_version = event_api_version
|
|
13
|
+
@sdk_api_version = sdk_api_version
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
attr_reader :event_api_version
|
|
17
|
+
attr_reader :sdk_api_version
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
require 'concurrent'
|
|
2
|
+
require 'singleton'
|
|
3
|
+
|
|
4
|
+
module Ingenico::Direct::SDK
|
|
5
|
+
module Webhooks
|
|
6
|
+
# An in-memory secret key store. This implementation can be used
|
|
7
|
+
# in applications where secret keys are specified at application
|
|
8
|
+
# startup. Thread-safe.
|
|
9
|
+
class InMemorySecretKeyStore
|
|
10
|
+
|
|
11
|
+
include Singleton
|
|
12
|
+
include SecretKeyStore
|
|
13
|
+
|
|
14
|
+
# Creates new InMemorySecretKeyStore
|
|
15
|
+
def initialize
|
|
16
|
+
# NOTE: use Map instead of Hash to provide better performance
|
|
17
|
+
# under high concurrency.
|
|
18
|
+
@store = Concurrent::Map.new
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Retrieves the secret key corresponding to the given key id
|
|
22
|
+
#
|
|
23
|
+
# @param key_id [String] key id of the secret key
|
|
24
|
+
# @raise [Ingenico::Direct::SDK::Webhooks::SecretKeyNotAvailableException] if the secret key for the given key id is not available.
|
|
25
|
+
def get_secret_key(key_id)
|
|
26
|
+
if (secret_key = @store.get(key_id))
|
|
27
|
+
return secret_key
|
|
28
|
+
end
|
|
29
|
+
msg = "could not find secret key for key id #{key_id}"
|
|
30
|
+
raise SecretKeyNotAvailableException, message: msg, key_id: key_id
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Stores the given secret key for the given key id.
|
|
34
|
+
#
|
|
35
|
+
# @param key_id [String] key id of the secret key
|
|
36
|
+
# @param secret_key [String] the secret key to be stored
|
|
37
|
+
def store_secret_key(key_id, secret_key)
|
|
38
|
+
raise ArgumentError if key_id.nil? || key_id.strip.empty?
|
|
39
|
+
raise ArgumentError if secret_key.nil? || secret_key.strip.empty?
|
|
40
|
+
@store.put(key_id, secret_key)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Removes the secret key for the given key id.
|
|
44
|
+
#
|
|
45
|
+
# @param key_id [String] the key id whose corresponding secret should be removed from the store
|
|
46
|
+
def remove_secret_key(key_id)
|
|
47
|
+
@store.delete(key_id)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Removes all stored secret keys from the store
|
|
51
|
+
def clear
|
|
52
|
+
@store.clear
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
module Webhooks
|
|
3
|
+
# Raised when an error caused a secret to become not available.
|
|
4
|
+
#
|
|
5
|
+
# @attr_reader [String] key_id
|
|
6
|
+
class SecretKeyNotAvailableException < SignatureValidationException
|
|
7
|
+
|
|
8
|
+
def initialize(args)
|
|
9
|
+
raise ArgumentError if (key_id = args.delete(:key_id)).nil? # key_id is mandatory
|
|
10
|
+
super(args)
|
|
11
|
+
@key_id = key_id
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
attr_reader :key_id
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
module Webhooks
|
|
3
|
+
# An abstract store of secret keys. Implementation can store secret keys in a database,
|
|
4
|
+
# on disk, etc. Should be Thread-safe.
|
|
5
|
+
module SecretKeyStore
|
|
6
|
+
|
|
7
|
+
# Retrieve secret key for given key id
|
|
8
|
+
#
|
|
9
|
+
# @param key_id [String] key id of the secret key
|
|
10
|
+
# @raise [Ingenico::Direct::SDK::Webhooks::SecretKeyNotAvailableException] if the secret key for the given key id is not available.
|
|
11
|
+
def get_secret_key(key_id)
|
|
12
|
+
raise NotImplementedError
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
module Webhooks
|
|
3
|
+
|
|
4
|
+
# Raised when an error occurred when validating Webhooks signatures
|
|
5
|
+
class SignatureValidationException < RuntimeError
|
|
6
|
+
|
|
7
|
+
# Creates a new SignatureValidationException
|
|
8
|
+
#
|
|
9
|
+
# @param [Hash] args the options to create the Exception with
|
|
10
|
+
# @option args [String] :message the error message
|
|
11
|
+
# @option args [RuntimeError] :cause an Error object that causes the Exception
|
|
12
|
+
def initialize(args)
|
|
13
|
+
super(args[:message]) # NOTE: can be nil
|
|
14
|
+
# store backtrace info if exception given
|
|
15
|
+
set_backtrace(args[:cause].backtrace) if args[:cause]
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
module Ingenico::Direct::SDK
|
|
2
|
+
module Webhooks
|
|
3
|
+
# Ingenico ePayments platform factory for several webhooks components
|
|
4
|
+
module Webhooks
|
|
5
|
+
DefaultMarshaller ||= Ingenico::Direct::SDK::DefaultImpl::DefaultMarshaller
|
|
6
|
+
|
|
7
|
+
# Creates a WebhooksHelperBuilder that uses the
|
|
8
|
+
# given SecretkeyStore
|
|
9
|
+
def self.create_helper_builder(secret_key_store)
|
|
10
|
+
WebhooksHelperBuilder.new
|
|
11
|
+
.with_marshaller(DefaultMarshaller.INSTANCE)
|
|
12
|
+
.with_secret_key_store(secret_key_store)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
# Creates a WebhooksHelper that uses the given
|
|
16
|
+
# SecretkeyStore.
|
|
17
|
+
def self.create_helper(secret_key_store)
|
|
18
|
+
create_helper_builder(secret_key_store).build
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|