onlinepayments-sdk-ruby 3.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 +140 -0
- data/Rakefile +34 -0
- data/lib/onlinepayments/sdk/api_exception.rb +42 -0
- data/lib/onlinepayments/sdk/api_resource.rb +115 -0
- data/lib/onlinepayments/sdk/authenticator.rb +16 -0
- data/lib/onlinepayments/sdk/authorization_exception.rb +13 -0
- data/lib/onlinepayments/sdk/call_context.rb +26 -0
- data/lib/onlinepayments/sdk/client.rb +82 -0
- data/lib/onlinepayments/sdk/communication_exception.rb +16 -0
- data/lib/onlinepayments/sdk/communicator.rb +300 -0
- data/lib/onlinepayments/sdk/communicator_configuration.rb +59 -0
- data/lib/onlinepayments/sdk/connection.rb +41 -0
- data/lib/onlinepayments/sdk/data_object.rb +31 -0
- data/lib/onlinepayments/sdk/declined_payment_exception.rb +30 -0
- data/lib/onlinepayments/sdk/declined_payout_exception.rb +32 -0
- data/lib/onlinepayments/sdk/declined_refund_exception.rb +32 -0
- data/lib/onlinepayments/sdk/declined_transaction_exception.rb +16 -0
- data/lib/onlinepayments/sdk/defaultimpl/authorization_type.rb +24 -0
- data/lib/onlinepayments/sdk/defaultimpl/default_authenticator.rb +108 -0
- data/lib/onlinepayments/sdk/defaultimpl/default_connection.rb +295 -0
- data/lib/onlinepayments/sdk/defaultimpl/default_marshaller.rb +32 -0
- data/lib/onlinepayments/sdk/defaultimpl.rb +6 -0
- data/lib/onlinepayments/sdk/domain/account_on_file.rb +49 -0
- data/lib/onlinepayments/sdk/domain/account_on_file_attribute.rb +38 -0
- data/lib/onlinepayments/sdk/domain/account_on_file_display_hints.rb +37 -0
- data/lib/onlinepayments/sdk/domain/additional_order_input.rb +54 -0
- data/lib/onlinepayments/sdk/domain/address.rb +50 -0
- data/lib/onlinepayments/sdk/domain/address_personal.rb +58 -0
- data/lib/onlinepayments/sdk/domain/airline_data.rb +128 -0
- data/lib/onlinepayments/sdk/domain/airline_flight_leg.rb +102 -0
- data/lib/onlinepayments/sdk/domain/airline_passenger.rb +38 -0
- data/lib/onlinepayments/sdk/domain/amount_breakdown.rb +30 -0
- data/lib/onlinepayments/sdk/domain/amount_of_money.rb +30 -0
- data/lib/onlinepayments/sdk/domain/api_error.rb +46 -0
- data/lib/onlinepayments/sdk/domain/bank_account_iban.rb +26 -0
- data/lib/onlinepayments/sdk/domain/browser_data.rb +42 -0
- data/lib/onlinepayments/sdk/domain/cancel_payment_response.rb +30 -0
- data/lib/onlinepayments/sdk/domain/capture.rb +46 -0
- data/lib/onlinepayments/sdk/domain/capture_output.rb +82 -0
- data/lib/onlinepayments/sdk/domain/capture_payment_request.rb +38 -0
- data/lib/onlinepayments/sdk/domain/capture_response.rb +46 -0
- data/lib/onlinepayments/sdk/domain/capture_status_output.rb +26 -0
- data/lib/onlinepayments/sdk/domain/captures_response.rb +33 -0
- data/lib/onlinepayments/sdk/domain/card.rb +38 -0
- data/lib/onlinepayments/sdk/domain/card_essentials.rb +34 -0
- data/lib/onlinepayments/sdk/domain/card_fraud_results.rb +34 -0
- data/lib/onlinepayments/sdk/domain/card_payment_method_specific_input.rb +98 -0
- data/lib/onlinepayments/sdk/domain/card_payment_method_specific_input_base.rb +86 -0
- data/lib/onlinepayments/sdk/domain/card_payment_method_specific_input_for_hosted_checkout.rb +26 -0
- data/lib/onlinepayments/sdk/domain/card_payment_method_specific_output.rb +78 -0
- data/lib/onlinepayments/sdk/domain/card_payout_method_specific_input.rb +38 -0
- data/lib/onlinepayments/sdk/domain/card_recurrence_details.rb +26 -0
- data/lib/onlinepayments/sdk/domain/card_without_cvv.rb +34 -0
- data/lib/onlinepayments/sdk/domain/company_information.rb +26 -0
- data/lib/onlinepayments/sdk/domain/complete_payment_card_payment_method_specific_input.rb +30 -0
- data/lib/onlinepayments/sdk/domain/complete_payment_request.rb +38 -0
- data/lib/onlinepayments/sdk/domain/complete_payment_response.rb +46 -0
- data/lib/onlinepayments/sdk/domain/contact_details.rb +42 -0
- data/lib/onlinepayments/sdk/domain/create_hosted_checkout_request.rb +78 -0
- data/lib/onlinepayments/sdk/domain/create_hosted_checkout_response.rb +48 -0
- data/lib/onlinepayments/sdk/domain/create_hosted_tokenization_request.rb +38 -0
- data/lib/onlinepayments/sdk/domain/create_hosted_tokenization_response.rb +50 -0
- data/lib/onlinepayments/sdk/domain/create_mandate_request.rb +58 -0
- data/lib/onlinepayments/sdk/domain/create_mandate_response.rb +38 -0
- data/lib/onlinepayments/sdk/domain/create_mandate_with_return_url.rb +58 -0
- data/lib/onlinepayments/sdk/domain/create_payment_request.rb +74 -0
- data/lib/onlinepayments/sdk/domain/create_payment_response.rb +46 -0
- data/lib/onlinepayments/sdk/domain/create_payout_request.rb +46 -0
- data/lib/onlinepayments/sdk/domain/create_token_request.rb +34 -0
- data/lib/onlinepayments/sdk/domain/created_payment_output.rb +34 -0
- data/lib/onlinepayments/sdk/domain/created_token_response.rb +50 -0
- data/lib/onlinepayments/sdk/domain/customer.rb +86 -0
- data/lib/onlinepayments/sdk/domain/customer_account.rb +70 -0
- data/lib/onlinepayments/sdk/domain/customer_account_authentication.rb +30 -0
- data/lib/onlinepayments/sdk/domain/customer_device.rb +50 -0
- data/lib/onlinepayments/sdk/domain/customer_payment_activity.rb +34 -0
- data/lib/onlinepayments/sdk/domain/customer_token.rb +46 -0
- data/lib/onlinepayments/sdk/domain/decrypted_payment_data.rb +42 -0
- data/lib/onlinepayments/sdk/domain/directory_entry.rb +34 -0
- data/lib/onlinepayments/sdk/domain/empty_validator.rb +12 -0
- data/lib/onlinepayments/sdk/domain/error_response.rb +37 -0
- data/lib/onlinepayments/sdk/domain/external_cardholder_authentication_data.rb +58 -0
- data/lib/onlinepayments/sdk/domain/external_token_linked.rb +34 -0
- data/lib/onlinepayments/sdk/domain/fixed_list_validator.rb +32 -0
- data/lib/onlinepayments/sdk/domain/fraud_fields.rb +30 -0
- data/lib/onlinepayments/sdk/domain/fraud_results.rb +26 -0
- data/lib/onlinepayments/sdk/domain/g_pay_three_d_secure.rb +46 -0
- data/lib/onlinepayments/sdk/domain/get_hosted_checkout_response.rb +34 -0
- data/lib/onlinepayments/sdk/domain/get_hosted_tokenization_response.rb +34 -0
- data/lib/onlinepayments/sdk/domain/get_iin_details_request.rb +34 -0
- data/lib/onlinepayments/sdk/domain/get_iin_details_response.rb +45 -0
- data/lib/onlinepayments/sdk/domain/get_mandate_response.rb +30 -0
- data/lib/onlinepayments/sdk/domain/get_payment_product_groups_response.rb +33 -0
- data/lib/onlinepayments/sdk/domain/get_payment_products_response.rb +33 -0
- data/lib/onlinepayments/sdk/domain/gift_card_purchase.rb +34 -0
- data/lib/onlinepayments/sdk/domain/hosted_checkout_specific_input.rb +66 -0
- data/lib/onlinepayments/sdk/domain/hosted_checkout_specific_output.rb +30 -0
- data/lib/onlinepayments/sdk/domain/iin_detail.rb +30 -0
- data/lib/onlinepayments/sdk/domain/label_template_element.rb +30 -0
- data/lib/onlinepayments/sdk/domain/length_validator.rb +30 -0
- data/lib/onlinepayments/sdk/domain/line_item.rb +46 -0
- data/lib/onlinepayments/sdk/domain/line_item_invoice_data.rb +26 -0
- data/lib/onlinepayments/sdk/domain/loan_recipient.rb +42 -0
- data/lib/onlinepayments/sdk/domain/lodging_data.rb +26 -0
- data/lib/onlinepayments/sdk/domain/mandate_address.rb +42 -0
- data/lib/onlinepayments/sdk/domain/mandate_contact_details.rb +26 -0
- data/lib/onlinepayments/sdk/domain/mandate_customer.rb +58 -0
- data/lib/onlinepayments/sdk/domain/mandate_merchant_action.rb +34 -0
- data/lib/onlinepayments/sdk/domain/mandate_personal_information.rb +34 -0
- data/lib/onlinepayments/sdk/domain/mandate_personal_name.rb +30 -0
- data/lib/onlinepayments/sdk/domain/mandate_redirect_data.rb +30 -0
- data/lib/onlinepayments/sdk/domain/mandate_response.rb +50 -0
- data/lib/onlinepayments/sdk/domain/merchant_action.rb +34 -0
- data/lib/onlinepayments/sdk/domain/mobile_payment_data.rb +30 -0
- data/lib/onlinepayments/sdk/domain/mobile_payment_method_hosted_checkout_specific_input.rb +30 -0
- data/lib/onlinepayments/sdk/domain/mobile_payment_method_specific_input.rb +62 -0
- data/lib/onlinepayments/sdk/domain/mobile_payment_method_specific_output.rb +58 -0
- data/lib/onlinepayments/sdk/domain/mobile_payment_product320_specific_input.rb +30 -0
- data/lib/onlinepayments/sdk/domain/operation_output.rb +58 -0
- data/lib/onlinepayments/sdk/domain/order.rb +70 -0
- data/lib/onlinepayments/sdk/domain/order_line_details.rb +54 -0
- data/lib/onlinepayments/sdk/domain/order_references.rb +34 -0
- data/lib/onlinepayments/sdk/domain/order_status_output.rb +49 -0
- data/lib/onlinepayments/sdk/domain/order_type_information.rb +30 -0
- data/lib/onlinepayments/sdk/domain/payment_account_on_file.rb +30 -0
- data/lib/onlinepayments/sdk/domain/payment_context.rb +38 -0
- data/lib/onlinepayments/sdk/domain/payment_creation_output.rb +38 -0
- data/lib/onlinepayments/sdk/domain/payment_details_response.rb +65 -0
- data/lib/onlinepayments/sdk/domain/payment_error_response.rb +45 -0
- data/lib/onlinepayments/sdk/domain/payment_output.rb +82 -0
- data/lib/onlinepayments/sdk/domain/payment_product.rb +102 -0
- data/lib/onlinepayments/sdk/domain/payment_product130_specific_input.rb +30 -0
- data/lib/onlinepayments/sdk/domain/payment_product130_specific_three_d_secure.rb +38 -0
- data/lib/onlinepayments/sdk/domain/payment_product302_specific_data.rb +32 -0
- data/lib/onlinepayments/sdk/domain/payment_product320_specific_data.rb +36 -0
- data/lib/onlinepayments/sdk/domain/payment_product5100_specific_input.rb +26 -0
- data/lib/onlinepayments/sdk/domain/payment_product5402_specific_output.rb +26 -0
- data/lib/onlinepayments/sdk/domain/payment_product5500_specific_output.rb +34 -0
- data/lib/onlinepayments/sdk/domain/payment_product771_specific_output.rb +26 -0
- data/lib/onlinepayments/sdk/domain/payment_product840_customer_account.rb +54 -0
- data/lib/onlinepayments/sdk/domain/payment_product840_specific_output.rb +53 -0
- data/lib/onlinepayments/sdk/domain/payment_product_display_hints.rb +34 -0
- data/lib/onlinepayments/sdk/domain/payment_product_field.rb +46 -0
- data/lib/onlinepayments/sdk/domain/payment_product_field_data_restrictions.rb +34 -0
- data/lib/onlinepayments/sdk/domain/payment_product_field_display_element.rb +38 -0
- data/lib/onlinepayments/sdk/domain/payment_product_field_display_hints.rb +70 -0
- data/lib/onlinepayments/sdk/domain/payment_product_field_form_element.rb +37 -0
- data/lib/onlinepayments/sdk/domain/payment_product_field_tooltip.rb +30 -0
- data/lib/onlinepayments/sdk/domain/payment_product_field_validators.rb +90 -0
- data/lib/onlinepayments/sdk/domain/payment_product_filter.rb +42 -0
- data/lib/onlinepayments/sdk/domain/payment_product_filters_hosted_checkout.rb +37 -0
- data/lib/onlinepayments/sdk/domain/payment_product_group.rb +52 -0
- data/lib/onlinepayments/sdk/domain/payment_product_networks_response.rb +32 -0
- data/lib/onlinepayments/sdk/domain/payment_references.rb +30 -0
- data/lib/onlinepayments/sdk/domain/payment_response.rb +54 -0
- data/lib/onlinepayments/sdk/domain/payment_status_output.rb +57 -0
- data/lib/onlinepayments/sdk/domain/payout_error_response.rb +45 -0
- data/lib/onlinepayments/sdk/domain/payout_output.rb +30 -0
- data/lib/onlinepayments/sdk/domain/payout_response.rb +46 -0
- data/lib/onlinepayments/sdk/domain/payout_result.rb +46 -0
- data/lib/onlinepayments/sdk/domain/payout_status_output.rb +34 -0
- data/lib/onlinepayments/sdk/domain/personal_information.rb +38 -0
- data/lib/onlinepayments/sdk/domain/personal_information_token.rb +30 -0
- data/lib/onlinepayments/sdk/domain/personal_name.rb +34 -0
- data/lib/onlinepayments/sdk/domain/personal_name_token.rb +30 -0
- data/lib/onlinepayments/sdk/domain/product_directory.rb +33 -0
- data/lib/onlinepayments/sdk/domain/protection_eligibility.rb +30 -0
- data/lib/onlinepayments/sdk/domain/range_validator.rb +30 -0
- data/lib/onlinepayments/sdk/domain/redirect_data.rb +30 -0
- data/lib/onlinepayments/sdk/domain/redirect_payment_method_specific_input.rb +66 -0
- data/lib/onlinepayments/sdk/domain/redirect_payment_method_specific_output.rb +66 -0
- data/lib/onlinepayments/sdk/domain/redirect_payment_product809_specific_input.rb +26 -0
- data/lib/onlinepayments/sdk/domain/redirect_payment_product840_specific_input.rb +26 -0
- data/lib/onlinepayments/sdk/domain/redirection_data.rb +26 -0
- data/lib/onlinepayments/sdk/domain/refund_card_method_specific_output.rb +30 -0
- data/lib/onlinepayments/sdk/domain/refund_e_wallet_method_specific_output.rb +38 -0
- data/lib/onlinepayments/sdk/domain/refund_error_response.rb +45 -0
- data/lib/onlinepayments/sdk/domain/refund_mobile_method_specific_output.rb +34 -0
- data/lib/onlinepayments/sdk/domain/refund_output.rb +82 -0
- data/lib/onlinepayments/sdk/domain/refund_payment_product840_customer_account.rb +34 -0
- data/lib/onlinepayments/sdk/domain/refund_payment_product840_specific_output.rb +30 -0
- data/lib/onlinepayments/sdk/domain/refund_redirect_method_specific_output.rb +30 -0
- data/lib/onlinepayments/sdk/domain/refund_request.rb +38 -0
- data/lib/onlinepayments/sdk/domain/refund_response.rb +46 -0
- data/lib/onlinepayments/sdk/domain/refunds_response.rb +33 -0
- data/lib/onlinepayments/sdk/domain/regular_expression_validator.rb +26 -0
- data/lib/onlinepayments/sdk/domain/sepa_direct_debit_payment_method_specific_input.rb +34 -0
- data/lib/onlinepayments/sdk/domain/sepa_direct_debit_payment_method_specific_input_base.rb +34 -0
- data/lib/onlinepayments/sdk/domain/sepa_direct_debit_payment_method_specific_output.rb +42 -0
- data/lib/onlinepayments/sdk/domain/sepa_direct_debit_payment_product771_specific_input.rb +34 -0
- data/lib/onlinepayments/sdk/domain/sepa_direct_debit_payment_product771_specific_input_base.rb +34 -0
- data/lib/onlinepayments/sdk/domain/session_request.rb +32 -0
- data/lib/onlinepayments/sdk/domain/session_response.rb +48 -0
- data/lib/onlinepayments/sdk/domain/shipping.rb +58 -0
- data/lib/onlinepayments/sdk/domain/shopping_cart.rb +64 -0
- data/lib/onlinepayments/sdk/domain/shopping_cart_extension.rb +52 -0
- data/lib/onlinepayments/sdk/domain/test_connection.rb +26 -0
- data/lib/onlinepayments/sdk/domain/three_d_secure.rb +78 -0
- data/lib/onlinepayments/sdk/domain/three_d_secure_base.rb +58 -0
- data/lib/onlinepayments/sdk/domain/three_d_secure_data.rb +34 -0
- data/lib/onlinepayments/sdk/domain/three_d_secure_results.rb +30 -0
- data/lib/onlinepayments/sdk/domain/token_card.rb +34 -0
- data/lib/onlinepayments/sdk/domain/token_card_data.rb +30 -0
- data/lib/onlinepayments/sdk/domain/token_card_specific_input.rb +30 -0
- data/lib/onlinepayments/sdk/domain/token_data.rb +30 -0
- data/lib/onlinepayments/sdk/domain/token_e_wallet.rb +34 -0
- data/lib/onlinepayments/sdk/domain/token_response.rb +58 -0
- data/lib/onlinepayments/sdk/domain/value_mapping_element.rb +37 -0
- data/lib/onlinepayments/sdk/endpoint_configuration.rb +127 -0
- data/lib/onlinepayments/sdk/exceptions.rb +8 -0
- data/lib/onlinepayments/sdk/factory.rb +136 -0
- data/lib/onlinepayments/sdk/idempotence_exception.rb +24 -0
- data/lib/onlinepayments/sdk/logging/communicator_logger.rb +22 -0
- data/lib/onlinepayments/sdk/logging/log_message_builder.rb +56 -0
- data/lib/onlinepayments/sdk/logging/logging_capable.rb +17 -0
- data/lib/onlinepayments/sdk/logging/logging_util.rb +286 -0
- data/lib/onlinepayments/sdk/logging/request_log_message_builder.rb +39 -0
- data/lib/onlinepayments/sdk/logging/response_log_message_builder.rb +34 -0
- data/lib/onlinepayments/sdk/logging/ruby_communicator_logger.rb +57 -0
- data/lib/onlinepayments/sdk/logging/stdout_communicator_logger.rb +34 -0
- data/lib/onlinepayments/sdk/logging.rb +10 -0
- data/lib/onlinepayments/sdk/marshaller.rb +24 -0
- data/lib/onlinepayments/sdk/marshaller_syntax_exception.rb +6 -0
- data/lib/onlinepayments/sdk/merchant/hostedcheckout/hosted_checkout_client.rb +86 -0
- data/lib/onlinepayments/sdk/merchant/hostedtokenization/hosted_tokenization_client.rb +86 -0
- data/lib/onlinepayments/sdk/merchant/mandates/mandates_client.rb +182 -0
- data/lib/onlinepayments/sdk/merchant/merchant_client.rb +89 -0
- data/lib/onlinepayments/sdk/merchant/payments/payments_client.rb +322 -0
- data/lib/onlinepayments/sdk/merchant/payouts/payouts_client.rb +86 -0
- data/lib/onlinepayments/sdk/merchant/productgroups/get_product_group_params.rb +57 -0
- data/lib/onlinepayments/sdk/merchant/productgroups/get_product_groups_params.rb +57 -0
- data/lib/onlinepayments/sdk/merchant/productgroups/product_groups_client.rb +87 -0
- data/lib/onlinepayments/sdk/merchant/products/get_payment_product_networks_params.rb +38 -0
- data/lib/onlinepayments/sdk/merchant/products/get_payment_product_params.rb +57 -0
- data/lib/onlinepayments/sdk/merchant/products/get_payment_products_params.rb +57 -0
- data/lib/onlinepayments/sdk/merchant/products/get_product_directory_params.rb +30 -0
- data/lib/onlinepayments/sdk/merchant/products/products_client.rb +155 -0
- data/lib/onlinepayments/sdk/merchant/services/services_client.rb +82 -0
- data/lib/onlinepayments/sdk/merchant/sessions/sessions_client.rb +54 -0
- data/lib/onlinepayments/sdk/merchant/tokens/tokens_client.rb +116 -0
- data/lib/onlinepayments/sdk/meta_data_provider.rb +150 -0
- data/lib/onlinepayments/sdk/modules.rb +62 -0
- data/lib/onlinepayments/sdk/not_found_exception.rb +16 -0
- data/lib/onlinepayments/sdk/param_request.rb +11 -0
- data/lib/onlinepayments/sdk/payment_platform_exception.rb +15 -0
- data/lib/onlinepayments/sdk/pooled_connection.rb +21 -0
- data/lib/onlinepayments/sdk/proxy_configuration.rb +74 -0
- data/lib/onlinepayments/sdk/reference_exception.rb +14 -0
- data/lib/onlinepayments/sdk/request_header.rb +50 -0
- data/lib/onlinepayments/sdk/request_param.rb +23 -0
- data/lib/onlinepayments/sdk/response_exception.rb +47 -0
- data/lib/onlinepayments/sdk/response_header.rb +42 -0
- data/lib/onlinepayments/sdk/validation_exception.rb +14 -0
- data/lib/onlinepayments/sdk/webhooks/api_version_mismatch_exception.rb +20 -0
- data/lib/onlinepayments/sdk/webhooks/in_memory_secret_key_store.rb +56 -0
- data/lib/onlinepayments/sdk/webhooks/secret_key_not_available_exception.rb +17 -0
- data/lib/onlinepayments/sdk/webhooks/secret_key_store.rb +16 -0
- data/lib/onlinepayments/sdk/webhooks/signature_validation_exception.rb +19 -0
- data/lib/onlinepayments/sdk/webhooks/webhooks.rb +22 -0
- data/lib/onlinepayments/sdk/webhooks/webhooks_event.rb +58 -0
- data/lib/onlinepayments/sdk/webhooks/webhooks_helper.rb +100 -0
- data/lib/onlinepayments/sdk/webhooks/webhooks_helper_builder.rb +25 -0
- data/lib/onlinepayments/sdk/webhooks.rb +11 -0
- data/lib/onlinepayments/sdk.rb +26 -0
- data/onlinepayments-sdk-ruby.gemspec +28 -0
- metadata +416 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
require 'onlinepayments/sdk/domain/shopping_cart_extension'
|
|
2
|
+
require 'base64'
|
|
3
|
+
|
|
4
|
+
module OnlinePayments::SDK
|
|
5
|
+
|
|
6
|
+
# Manages metadata about the server using the SDK
|
|
7
|
+
#
|
|
8
|
+
# @attr_reader [Array<OnlinePayments::SDK::RequestHeader>] meta_data_headers List of headers that should be used in all requests.
|
|
9
|
+
class MetaDataProvider
|
|
10
|
+
SDK_VERSION = '0.0.1'.freeze
|
|
11
|
+
SERVER_META_INFO_HEADER = 'X-GCS-ServerMetaInfo'.freeze
|
|
12
|
+
PROHIBITED_HEADERS = [SERVER_META_INFO_HEADER,
|
|
13
|
+
'X-GCS-Idempotence-Key', 'Date', 'Content-Type', 'Authorization'].sort!.freeze
|
|
14
|
+
CHARSET = 'utf-8'.freeze
|
|
15
|
+
|
|
16
|
+
# Stores metadata about the server so it can be sent to the Online Payments platform
|
|
17
|
+
class ServerMetaInfo < DataObject
|
|
18
|
+
@platform_identifier = nil
|
|
19
|
+
@sdk_identifier = nil
|
|
20
|
+
@sdk_creator = nil
|
|
21
|
+
@integrator = nil
|
|
22
|
+
@shopping_cart_extension = nil
|
|
23
|
+
|
|
24
|
+
# String containing system information (Operating system and Ruby version).
|
|
25
|
+
attr_accessor :platform_identifier
|
|
26
|
+
|
|
27
|
+
# String containing this SDK version.
|
|
28
|
+
attr_accessor :sdk_identifier
|
|
29
|
+
|
|
30
|
+
attr_accessor :sdk_creator
|
|
31
|
+
|
|
32
|
+
attr_accessor :integrator
|
|
33
|
+
|
|
34
|
+
attr_accessor :shopping_cart_extension
|
|
35
|
+
|
|
36
|
+
# Returns the values of all attributes as a hash.
|
|
37
|
+
def to_h
|
|
38
|
+
hash = super
|
|
39
|
+
hash['platformIdentifier'] = @platform_identifier if @platform_identifier
|
|
40
|
+
hash['sdkIdentifier'] = @sdk_identifier if @sdk_identifier
|
|
41
|
+
hash['sdkCreator'] = @sdk_creator if @sdk_creator
|
|
42
|
+
hash['integrator'] = @integrator if @integrator
|
|
43
|
+
hash['shoppingCartExtension'] = @shopping_cart_extension.to_h if @shopping_cart_extension
|
|
44
|
+
hash
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Initializes the ServerMetaInfo object with properties stored in the parameter hash
|
|
48
|
+
def from_hash(hash)
|
|
49
|
+
super
|
|
50
|
+
@platform_identifier = hash['platformIdentifier'] if hash.has_key? 'platformIdentifier'
|
|
51
|
+
@sdk_identifier = hash['sdkIdentifier'] if hash.has_key? 'sdkIdentifier'
|
|
52
|
+
@sdk_creator = hash['sdkCreator'] if hash.has_key? 'sdkCreator'
|
|
53
|
+
@integrator = hash['integrator'] if hash.has_key? 'integrator'
|
|
54
|
+
@shopping_cart_extension = Domain::ShoppingCartExtension.new_from_hash(hash['shoppingCartExtension']) if hash.has_key? 'shoppingCartExtension'
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Create a new MetaDataProvider instance that can be used to access platform-related information
|
|
59
|
+
#
|
|
60
|
+
# @param integrator [String] Name of the integrator
|
|
61
|
+
# @param shopping_cart_extension [OnlinePayments::SDK::Domain::ShoppingCartExtension] shopping cart-related metadata.
|
|
62
|
+
# @param additional_request_headers [Array<OnlinePayments::SDK::RequestHeader>] list of additional headers to include in all requests made.
|
|
63
|
+
# The following headers are not allowed due to conflicts with already added headers:
|
|
64
|
+
# 'X-GCS-Idempotence-Key', 'Date', 'Content-Type', 'Authorization' and 'X-GCS-ServerMetaInfo'
|
|
65
|
+
def initialize(integrator, shopping_cart_extension: nil, additional_request_headers: [].freeze)
|
|
66
|
+
|
|
67
|
+
MetaDataProvider.validate_additional_request_headers(additional_request_headers)
|
|
68
|
+
server_meta_info = ServerMetaInfo.new
|
|
69
|
+
server_meta_info.platform_identifier = get_platform_identifier
|
|
70
|
+
server_meta_info.sdk_identifier = get_sdk_identifier
|
|
71
|
+
server_meta_info.sdk_creator = 'OnlinePayments'
|
|
72
|
+
server_meta_info.integrator = integrator
|
|
73
|
+
server_meta_info.shopping_cart_extension = shopping_cart_extension if shopping_cart_extension
|
|
74
|
+
server_meta_info_string = DefaultImpl::DefaultMarshaller.INSTANCE.marshal(server_meta_info)
|
|
75
|
+
server_meta_info_header = RequestHeader.new(
|
|
76
|
+
SERVER_META_INFO_HEADER,
|
|
77
|
+
Base64.strict_encode64(server_meta_info_string.force_encoding('iso-8859-1').encode(CHARSET)))
|
|
78
|
+
if additional_request_headers.nil? || additional_request_headers.empty?
|
|
79
|
+
@meta_data_headers = [server_meta_info_header].freeze
|
|
80
|
+
else
|
|
81
|
+
request_headers = [server_meta_info_header]
|
|
82
|
+
request_headers += additional_request_headers
|
|
83
|
+
@meta_data_headers = request_headers.freeze
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Checks that none of the {OnlinePayments::SDK::RequestHeaders} in _additional_request_headers_ is equal to any of the forbidden headers.
|
|
88
|
+
# The forbidden headers are:
|
|
89
|
+
#'X-GCS-Idempotence-Key', 'Date', 'Content-Type', 'Authorization' and 'X-GCS-ServerMetaInfo'
|
|
90
|
+
# If a header is found that is equal to one of the forbidden headers an ArgumentError is raised.
|
|
91
|
+
def self.validate_additional_request_headers(additional_request_headers)
|
|
92
|
+
if additional_request_headers
|
|
93
|
+
additional_request_headers.each { |additional_request_header|
|
|
94
|
+
validate_additional_request_header(additional_request_header)
|
|
95
|
+
}
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# Checks that the {OnlinePayments::SDK::RequestHeaders} _additional_request_header_ is equal to any of the forbidden headers.
|
|
100
|
+
# The forbidden headers are:
|
|
101
|
+
#'X-GCS-Idempotence-Key', 'Date', 'Content-Type', 'Authorization' and 'X-GCS-ServerMetaInfo'
|
|
102
|
+
# If the header is equal to one of the forbidden headers an ArgumentError is raised.
|
|
103
|
+
def self.validate_additional_request_header(additional_request_header)
|
|
104
|
+
if MetaDataProvider.PROHIBITED_HEADERS.include? additional_request_header.name
|
|
105
|
+
raise ArgumentError, "request header '#{additional_request_header.name}' not allowed"
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
protected
|
|
110
|
+
|
|
111
|
+
# String containing information of the system using the SDK.
|
|
112
|
+
# It contains data like Operating System version and Ruby version
|
|
113
|
+
def get_platform_identifier
|
|
114
|
+
os_host = RbConfig::CONFIG['host_os']
|
|
115
|
+
if os_host.include? 'mingw'
|
|
116
|
+
s = 'Windows'
|
|
117
|
+
elsif os_host.include? 'linux'
|
|
118
|
+
s = 'Linux'
|
|
119
|
+
else
|
|
120
|
+
s = 'Mac OS X'
|
|
121
|
+
end
|
|
122
|
+
"#{s}/#{RUBY_DESCRIPTION}"
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# String describing the version of the SDK being used
|
|
126
|
+
def get_sdk_identifier
|
|
127
|
+
"RubyServerSDK/v#{SDK_VERSION}"
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
public
|
|
131
|
+
|
|
132
|
+
# Version of this SDK being used
|
|
133
|
+
def self.SDK_VERSION
|
|
134
|
+
SDK_VERSION
|
|
135
|
+
end
|
|
136
|
+
|
|
137
|
+
# A {OnlinePayments::SDK::RequestHeader} that contains serialized and encoded {OnlinePayments::SDK::MetaDataProvider::ServerMetaInfo}.
|
|
138
|
+
def self.SERVER_META_INFO_HEADER
|
|
139
|
+
SERVER_META_INFO_HEADER
|
|
140
|
+
end
|
|
141
|
+
|
|
142
|
+
# A list of header names that should not be used by any added headers.
|
|
143
|
+
# These headers are reserved for specific purposes.
|
|
144
|
+
def self.PROHIBITED_HEADERS
|
|
145
|
+
PROHIBITED_HEADERS
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
attr_reader :meta_data_headers
|
|
149
|
+
end
|
|
150
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# Main module of this SDK. All non-data classes that are used at multiple places in the SDK are placed in this module.
|
|
2
|
+
module OnlinePayments::SDK
|
|
3
|
+
end
|
|
4
|
+
|
|
5
|
+
# Contains provided implementations for abstract functionality in this SDK.
|
|
6
|
+
# These implementations can be replaced or adapted if desired to suit specific needs.
|
|
7
|
+
module OnlinePayments::SDK::DefaultImpl
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# Container for all data-containing modules.
|
|
11
|
+
# The data-classes contained within can be serialized and communicated with the Online Payments platform.
|
|
12
|
+
# These classes generally contain data used in processing requests or responses.
|
|
13
|
+
module OnlinePayments::SDK::Domain
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Contains all logging-related classes.
|
|
17
|
+
module OnlinePayments::SDK::Logging
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Contains interfaces to all Online Payments services. These services are accessed through a *OnlinePayments::SDK::Client* instance.
|
|
21
|
+
module OnlinePayments::SDK::Merchant
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Contains the client used to access the Hosted Checkout service.
|
|
25
|
+
module OnlinePayments::SDK::Merchant::HostedCheckout
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Contains the client used to access the Hosted Tokenization service.
|
|
29
|
+
module OnlinePayments::SDK::Merchant::HostedTokenization
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Contains the client used to access the Payment service.
|
|
33
|
+
module OnlinePayments::SDK::Merchant::Payments
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Contains the client used to access the Payout service.
|
|
37
|
+
module OnlinePayments::SDK::Merchant::Payouts
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Contains the client used to access the Product Groups service.
|
|
41
|
+
module OnlinePayments::SDK::Merchant::ProductGroups
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Contains the client used to access the Products service.
|
|
45
|
+
module OnlinePayments::SDK::Merchant::Products
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Contains the client to access miscellaneous services.
|
|
49
|
+
module OnlinePayments::SDK::Merchant::Services
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Contains the client used to access the Sessions service.
|
|
53
|
+
module OnlinePayments::SDK::Merchant::Sessions
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Contains the client used to access the Tokens service.
|
|
57
|
+
module OnlinePayments::SDK::Merchant::Tokens
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
# Contains data classes related to Webhooks functionality.
|
|
61
|
+
module OnlinePayments::SDK::Webhooks
|
|
62
|
+
end
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module OnlinePayments::SDK
|
|
2
|
+
|
|
3
|
+
# Raised when a resource is not found on the Online Payments platform.
|
|
4
|
+
# This error corresponds to a 404 HTTP response.
|
|
5
|
+
#
|
|
6
|
+
# @attr [Exception] cause The error that is the cause of this error.
|
|
7
|
+
class NotFoundException < RuntimeError
|
|
8
|
+
|
|
9
|
+
def initialize(cause, message = nil)
|
|
10
|
+
super(message)
|
|
11
|
+
@cause = cause
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
attr_accessor :cause
|
|
15
|
+
end
|
|
16
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module OnlinePayments::SDK
|
|
2
|
+
|
|
3
|
+
# Class that represents the URL request parameters.
|
|
4
|
+
# Contains a method to add a name and value pair to a parameter array as a {OnlinePayments::SDK::RequestParam}.
|
|
5
|
+
class ParamRequest
|
|
6
|
+
# @return [Array<OnlinePayments::SDK::RequestParam>]
|
|
7
|
+
def to_request_parameters
|
|
8
|
+
raise NotImplementedError
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module OnlinePayments::SDK
|
|
2
|
+
|
|
3
|
+
# This exception is thrown when a response from the payment platform indicates that an error occurred
|
|
4
|
+
# on the payment platform while processing the request.
|
|
5
|
+
# This corresponds to a HTTP status code of 500 or 502.
|
|
6
|
+
class PaymentPlatformException < ApiException
|
|
7
|
+
|
|
8
|
+
# Create a new PaymentPlatformException
|
|
9
|
+
# @see ApiException#initialize
|
|
10
|
+
def initialize(status_code, response_body, error_id, errors,
|
|
11
|
+
message = 'the Online Payments platform returned an error response')
|
|
12
|
+
super(status_code, response_body, error_id, errors, message)
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
module OnlinePayments::SDK
|
|
2
|
+
|
|
3
|
+
# {OnlinePayments::SDK::Connection} that supports connection pooling. This is used to more efficiently communicate using HTTP.
|
|
4
|
+
# Connection pooling means that a number of connections are kept alive after use so they can possibly be reused.
|
|
5
|
+
# If the Connection does not do so automatically,
|
|
6
|
+
# the methods _close_idle_connections_ and _close_expired_connections_ can be used to drop connections
|
|
7
|
+
# that are idle for a specified amount of time or that have expired.
|
|
8
|
+
# @see OnlinePayments::SDK::DefaultImpl::DefaultConnection
|
|
9
|
+
class PooledConnection < Connection
|
|
10
|
+
|
|
11
|
+
# Closes all connections that have not been used for _idle_time_ seconds.
|
|
12
|
+
def close_idle_connections(idle_time)
|
|
13
|
+
raise NotImplementedError
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
# Closes all connections that have expired.
|
|
17
|
+
def close_expired_connections
|
|
18
|
+
raise NotImplementedError
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module OnlinePayments::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 OnlinePayments::SDK
|
|
2
|
+
|
|
3
|
+
# This error is raised when the request refers to a resource or object that is not found by the Online Payments 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 Online Payments 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 OnlinePayments::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 {OnlinePayments::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 OnlinePayments::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 OnlinePayments::SDK
|
|
2
|
+
|
|
3
|
+
# Exception used internally in the SDK to indicate an error response was received from the Online Payments platform.
|
|
4
|
+
#
|
|
5
|
+
# @attr_reader [Integer] status_code HTTP status code that was returned by the Online Payments platform
|
|
6
|
+
# @attr_reader [String] body HTTP message body that was returned by the Online Payments platform
|
|
7
|
+
# @attr_reader [Array<OnlinePayments:SDK:ResponseHeader>] headers HTTP headers used in the response from the Online Payments platform
|
|
8
|
+
class ResponseException < RuntimeError
|
|
9
|
+
|
|
10
|
+
def initialize(status_code, headers, body)
|
|
11
|
+
super('the Online Payments 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 {OnlinePayments::SDK::ResponseHeader} that corresponds to the given _header_name_
|
|
29
|
+
# used in the HTTP response from the Online Payments 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 OnlinePayments::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 {OnlinePayments::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 OnlinePayments::SDK
|
|
2
|
+
|
|
3
|
+
# Raised when the request sent to the Online Payments platform returned a HTTP response with status code 400.
|
|
4
|
+
# This indicates the request received by the Online Payments 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 Online Payments 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,20 @@
|
|
|
1
|
+
module OnlinePayments::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 OnlinePayments::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 [OnlinePayments::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 OnlinePayments::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 OnlinePayments::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 [OnlinePayments::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
|