onlinepayments-sdk-ruby 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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,300 @@
|
|
1
|
+
require 'uri'
|
2
|
+
|
3
|
+
module OnlinePayments::SDK
|
4
|
+
# Class responsible for facilitating communication with the Online Payments platform.
|
5
|
+
# It combines the following classes to provide communication functionality:
|
6
|
+
#
|
7
|
+
# api_endpoint:: The base URI ({URI::HTTP}) to the Online Payments platform
|
8
|
+
# connection:: {OnlinePayments::SDK::Connection} used to communicate with the Online Payments platform
|
9
|
+
# authenticator:: {OnlinePayments::SDK::Authenticator} used for authenticating messages sent
|
10
|
+
# meta_data_provider:: {OnlinePayments::SDK::MetaDataProvider} object containing information relevant for sending requests
|
11
|
+
# marshaller:: {OnlinePayments::SDK::Marshaller} that is used to marshal and unmarshal data to and from JSON format
|
12
|
+
#
|
13
|
+
# @attr_reader [OnlinePayments::SDK::Marshaller] marshaller A Marshaller instance used by the communicator for serializing/deserializing to/from JSON
|
14
|
+
#
|
15
|
+
class Communicator
|
16
|
+
include Logging::LoggingCapable
|
17
|
+
|
18
|
+
# Creates a new Communicator based on the given arguments.
|
19
|
+
#
|
20
|
+
# @param api_endpoint [String] the base URL to the Online Payments platform
|
21
|
+
# @param connection [OnlinePayments::SDK::Connection] used to communicate with the Online Payments platform
|
22
|
+
# @param authenticator [OnlinePayments::SDK::Authenticator] used for authenticating messages sent
|
23
|
+
# @param meta_data_provider [OnlinePayments::SDK::MetaDataProvider] object containing information relevant for sending requests
|
24
|
+
# @param marshaller [OnlinePayments::SDK::Marshaller] used to marshal and unmarshal data to and from JSON format
|
25
|
+
#
|
26
|
+
def initialize(api_endpoint, connection, authenticator, meta_data_provider, marshaller)
|
27
|
+
raise ArgumentError, 'api_endpoint is required' unless api_endpoint
|
28
|
+
raise ArgumentError, 'connection is required' unless connection
|
29
|
+
raise ArgumentError, 'authenticator is required' unless authenticator
|
30
|
+
raise ArgumentError, 'meta_data_provider is required' unless meta_data_provider
|
31
|
+
raise ArgumentError('marshaller is required') unless marshaller
|
32
|
+
|
33
|
+
@api_endpoint = URI(api_endpoint)
|
34
|
+
if @api_endpoint.path.length.positive? || @api_endpoint.query || @api_endpoint.fragment
|
35
|
+
raise ArgumentError, "Base URL should not contain a path, query or fragment #{@api_endpoint}"
|
36
|
+
end
|
37
|
+
@connection = connection
|
38
|
+
@authenticator = authenticator
|
39
|
+
@meta_data_provider = meta_data_provider
|
40
|
+
@marshaller = marshaller
|
41
|
+
end
|
42
|
+
|
43
|
+
# Performs a GET request to the Online Payments platform and returns the response as the given response type.
|
44
|
+
#
|
45
|
+
# @param relative_path [String] path relative to the API endpoint
|
46
|
+
# @param request_headers [Array<OnlinePayments::SDK::RequestHeader>, nil] optional array of request headers
|
47
|
+
# @param request_parameters [OnlinePayments::SDK::ParamRequest, nil] optional request parameters
|
48
|
+
# @param response_type [Type] the response type.
|
49
|
+
# @param context [OnlinePayments::SDK::CallContext, nil] optional call context.
|
50
|
+
# @return the response of the GET request as the given response type
|
51
|
+
# @raise [OnlinePayments::SDK::ResponseException] if the request could not be fulfilled successfully.
|
52
|
+
# This occurs for example if the request is not authenticated correctly
|
53
|
+
# @raise [OnlinePayments::SDK::NotFoundException] if the requested resource is not found
|
54
|
+
# @raise [OnlinePayments::SDK::CommunicationException] if there is an error in communicating with the Online Payments platform.
|
55
|
+
# This occurs for example if a timeout occurs.
|
56
|
+
def get(relative_path, request_headers, request_parameters, response_type, context)
|
57
|
+
connection = @connection
|
58
|
+
request_parameter_list = request_parameters&.to_request_parameters
|
59
|
+
uri = to_absolute_uri(relative_path, request_parameter_list)
|
60
|
+
|
61
|
+
request_headers ||= []
|
62
|
+
add_generic_headers('GET', uri, request_headers, context)
|
63
|
+
|
64
|
+
response_status_code, response_headers, response_body = nil
|
65
|
+
connection.get(uri, request_headers) do |status_code, headers, content|
|
66
|
+
response_status_code = status_code
|
67
|
+
response_headers = headers
|
68
|
+
response_body = content.read.force_encoding('UTF-8')
|
69
|
+
end
|
70
|
+
process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
|
71
|
+
end
|
72
|
+
|
73
|
+
# Performs a DELETE request to the Online Payments platform and returns the response as the given response type.
|
74
|
+
#
|
75
|
+
# @param relative_path [String] Path relative to the API endpoint
|
76
|
+
# @param request_headers [Array<OnlinePayments::SDK::RequestHeader>, nil] Optional array of request headers
|
77
|
+
# @param request_parameters [OnlinePayments::SDK::ParamRequest, nil] Optional request parameters
|
78
|
+
# @param response_type [Type] The response type.
|
79
|
+
# @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
|
80
|
+
# @return The response of the DELETE request as the given response type
|
81
|
+
# @raise [OnlinePayments::SDK::ResponseException] if the request could not be fulfilled successfully.
|
82
|
+
# This occurs for example if the request is not authenticated correctly
|
83
|
+
# @raise [OnlinePayments::SDK::NotFoundException] if the requested resource is not found
|
84
|
+
# @raise [OnlinePayments::SDK::CommunicationException] if there is an error in communicating with the Online Payments platform.
|
85
|
+
# This occurs for example if a timeout occurs.
|
86
|
+
def delete(relative_path, request_headers, request_parameters, response_type, context)
|
87
|
+
connection = @connection
|
88
|
+
request_parameter_list = request_parameters&.to_request_parameters
|
89
|
+
uri = to_absolute_uri(relative_path, request_parameter_list)
|
90
|
+
request_headers ||= []
|
91
|
+
add_generic_headers('DELETE', uri, request_headers, context)
|
92
|
+
|
93
|
+
response_status_code, response_headers, response_body = nil
|
94
|
+
connection.delete(uri, request_headers) do |status_code, headers, content|
|
95
|
+
response_status_code = status_code
|
96
|
+
response_headers = headers
|
97
|
+
response_body = content.read.force_encoding('UTF-8')
|
98
|
+
end
|
99
|
+
process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
|
100
|
+
end
|
101
|
+
|
102
|
+
# Performs a POST request to the Online Payments platform and returns the response as the given response type.
|
103
|
+
#
|
104
|
+
# @param relative_path [String] Path relative to the API endpoint
|
105
|
+
# @param request_headers [Array<OnlinePayments::SDK::RequestHeader>, nil] Optional array of request headers
|
106
|
+
# @param request_parameters [OnlinePayments::SDK::ParamRequest, nil] Optional request parameters
|
107
|
+
# @param request_body [OnlinePayments::SDK::DataObject] The optional request body
|
108
|
+
# @param response_type [Type] The response type.
|
109
|
+
# @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
|
110
|
+
# @return The response of the POST request as the given response type
|
111
|
+
# @raise [OnlinePayments::SDK::ResponseException] if the request could not be fulfilled successfully.
|
112
|
+
# This occurs for example if the request is not authenticated correctly
|
113
|
+
# @raise [OnlinePayments::SDK::NotFoundException] if the requested resource is not found
|
114
|
+
# @raise [OnlinePayments::SDK::CommunicationException] if there is an error in communicating with the Online Payments platform.
|
115
|
+
# This occurs for example if a timeout occurs.
|
116
|
+
def post(relative_path, request_headers, request_parameters, request_body, response_type, context)
|
117
|
+
request_parameter_list = request_parameters&.to_request_parameters
|
118
|
+
uri = to_absolute_uri(relative_path, request_parameter_list)
|
119
|
+
request_headers ||= []
|
120
|
+
|
121
|
+
body = nil
|
122
|
+
if request_body
|
123
|
+
request_headers.push(RequestHeader.new('Content-Type', 'application/json'))
|
124
|
+
body = @marshaller.marshal(request_body)
|
125
|
+
else
|
126
|
+
# Set the content-type, even though there is no body, to prevent the httpClient from
|
127
|
+
# adding a content-type header after authentication has been generated.
|
128
|
+
request_headers.push(RequestHeader.new('Content-Type', 'text/plain'))
|
129
|
+
end
|
130
|
+
|
131
|
+
add_generic_headers('POST', uri, request_headers, context)
|
132
|
+
|
133
|
+
response_status_code, response_headers, response_body = nil
|
134
|
+
@connection.post(uri, request_headers, body) do |status_code, headers, content|
|
135
|
+
response_status_code = status_code
|
136
|
+
response_headers = headers
|
137
|
+
response_body = content.read.force_encoding('UTF-8')
|
138
|
+
end
|
139
|
+
process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
|
140
|
+
end
|
141
|
+
|
142
|
+
# Performs a PUT request to the Online Payments platform and returns the response as the given response type.
|
143
|
+
#
|
144
|
+
# @param relative_path [String] Path relative to the API endpoint
|
145
|
+
# @param request_headers [Array<OnlinePayments::SDK::RequestHeader>, nil] Optional array of request headers
|
146
|
+
# @param request_parameters [OnlinePayments::SDK::ParamRequest, nil] Optional request parameters
|
147
|
+
# @param request_body [OnlinePayments::SDK::DataObject]
|
148
|
+
# The optional request body
|
149
|
+
# @param response_type [Type] The response type.
|
150
|
+
# @param context [OnlinePayments::SDK::CallContext, nil] Optional call context.
|
151
|
+
# @return The response of the PUT request as the given response type
|
152
|
+
# @raise [OnlinePayments::SDK::ResponseException] if the request could not be fulfilled successfully.
|
153
|
+
# This occurs for example if the request is not authenticated correctly
|
154
|
+
# @raise [OnlinePayments::SDK::NotFoundException] if the requested resource is not found
|
155
|
+
# @raise [OnlinePayments::SDK::CommunicationException] if there is an error in communicating with the Online Payments platform.
|
156
|
+
# This occurs for example if a timeout occurs.
|
157
|
+
def put(relative_path, request_headers, request_parameters, request_body, response_type, context)
|
158
|
+
request_parameter_list = request_parameters&.to_request_parameters
|
159
|
+
uri = to_absolute_uri(relative_path, request_parameter_list)
|
160
|
+
request_headers ||= []
|
161
|
+
|
162
|
+
body = nil
|
163
|
+
if request_body
|
164
|
+
request_headers.push(RequestHeader.new('Content-Type', 'application/json'))
|
165
|
+
body = @marshaller.marshal(request_body)
|
166
|
+
else
|
167
|
+
# Set the content-type, even though there is no body, to prevent the httpClient from
|
168
|
+
# adding a content-type header after authentication has been generated.
|
169
|
+
request_headers.push(RequestHeader.new('Content-Type', 'text/plain'))
|
170
|
+
end
|
171
|
+
add_generic_headers('PUT', uri, request_headers, context)
|
172
|
+
|
173
|
+
response_status_code, response_headers, response_body = nil
|
174
|
+
@connection.put(uri, request_headers, body) do |status_code, headers, content|
|
175
|
+
response_status_code = status_code
|
176
|
+
response_headers = headers
|
177
|
+
response_body = content.read.force_encoding('UTF-8')
|
178
|
+
end
|
179
|
+
process_response(response_body, response_status_code, response_headers, response_type, relative_path, context)
|
180
|
+
end
|
181
|
+
|
182
|
+
# Closes any connections idle for more than _idle_time_ seconds.
|
183
|
+
# Will not have any effect if the connection is not a pooled connection (an instance of {OnlinePayments::SDK::PooledConnection}).
|
184
|
+
def close_idle_connections(idle_time)
|
185
|
+
@connection.close_idle_connections(idle_time) if connection.is_a? PooledConnection
|
186
|
+
end
|
187
|
+
|
188
|
+
# Closes any connections that have expired.
|
189
|
+
# Will not have any effect if the connection is not a pooled connection (an instance of {OnlinePayments::SDK::PooledConnection}).
|
190
|
+
def close_expired_connections
|
191
|
+
@connection.close_expired_connections if connection.is_a? PooledConnection
|
192
|
+
end
|
193
|
+
|
194
|
+
# Enables logging outgoing requests and incoming responses by registering the _communicator_logger_.
|
195
|
+
# Note that only one logger can be registered at a time and calling _enable_logging_
|
196
|
+
# a second time will override the old logger instance with the new one.
|
197
|
+
#
|
198
|
+
# @param communicator_logger [OnlinePayments::SDK::Logging::CommunicatorLogger] The communicator logger the requests and responses are logged to
|
199
|
+
def enable_logging(communicator_logger)
|
200
|
+
@connection.enable_logging(communicator_logger)
|
201
|
+
end
|
202
|
+
|
203
|
+
# Disables logging by unregistering any previous logger that might be registered.
|
204
|
+
def disable_logging
|
205
|
+
@connection.disable_logging
|
206
|
+
end
|
207
|
+
|
208
|
+
# Frees networking resources by closing the underlying network connections.
|
209
|
+
# After calling _close_, any use of the _get_, _delete_, _post_ and _put_ methods will not function
|
210
|
+
# and likely result in an error.
|
211
|
+
def close
|
212
|
+
@connection.close
|
213
|
+
end
|
214
|
+
|
215
|
+
attr_reader :api_endpoint
|
216
|
+
attr_reader :connection
|
217
|
+
attr_reader :authenticator
|
218
|
+
attr_reader :meta_data_provider
|
219
|
+
attr_reader :marshaller
|
220
|
+
|
221
|
+
protected
|
222
|
+
|
223
|
+
# Constructs a full URL using the base URL and the given relative path and request_parameters.
|
224
|
+
# The returned URL is a *URI* object.
|
225
|
+
#
|
226
|
+
# @param relative_path [String] The relative path of the URL.
|
227
|
+
# @param request_parameters [Array<OnlinePayments::SDK::RequestParam>, nil] A list of request parameters that each have #name and #value
|
228
|
+
# which represent the parameter name and value respectively.
|
229
|
+
def to_absolute_uri(relative_path, request_parameters)
|
230
|
+
raise RuntimeError('api_endpoint should not contain a path') unless @api_endpoint.path.nil? || @api_endpoint.path.empty?
|
231
|
+
|
232
|
+
if @api_endpoint.userinfo || @api_endpoint.query || @api_endpoint.fragment
|
233
|
+
raise RuntimeError, 'api_endpoint should not contain user info, query or fragment'
|
234
|
+
end
|
235
|
+
absolute_path = relative_path.start_with?('/') ? relative_path : "/#{relative_path}"
|
236
|
+
uri = URI::HTTP.new(@api_endpoint.scheme, nil, @api_endpoint.host,
|
237
|
+
@api_endpoint.port, nil, absolute_path, nil, nil, nil)
|
238
|
+
request_parameters&.each do |nvp|
|
239
|
+
parameters = URI.decode_www_form(uri.query || '') << [nvp.name, nvp.value]
|
240
|
+
uri.query = URI.encode_www_form(parameters)
|
241
|
+
end
|
242
|
+
uri
|
243
|
+
end
|
244
|
+
|
245
|
+
# Adds several standard headers to the http headers.
|
246
|
+
# This method will add the 'Date' and 'Authorization' header;
|
247
|
+
# the 'X-GCS-Idempotence-Key' header will also be added if an idempotence context is given
|
248
|
+
#
|
249
|
+
# @param http_method [String] 'GET', 'DELETE', 'POST' or 'PUT' depending on the HTTP method being used
|
250
|
+
# @param uri [URI::HTTP] The full URI to the Online Payments platform,
|
251
|
+
# including the relative path and request parameters.
|
252
|
+
# @param request_headers [Array<OnlinePayments::SDK::RequestHeader>] List of request headers in which which new headers will be added
|
253
|
+
# @param context [OnlinePayments::SDK::CallContext, nil] object that will be used to produce
|
254
|
+
# an Idempotence header to prevent accidental request duplication.
|
255
|
+
def add_generic_headers(http_method, uri, request_headers, context = nil)
|
256
|
+
request_headers.concat(meta_data_provider.meta_data_headers)
|
257
|
+
request_headers.push(RequestHeader.new('Date', get_header_date_string))
|
258
|
+
if context&.idempotence_key
|
259
|
+
request_headers.push(RequestHeader.new('X-GCS-Idempotence-Key', context.idempotence_key))
|
260
|
+
end
|
261
|
+
authentication_signature = @authenticator.create_simple_authentication_signature(http_method, uri, request_headers)
|
262
|
+
request_headers.push(RequestHeader.new('Authorization', authentication_signature))
|
263
|
+
end
|
264
|
+
|
265
|
+
def get_header_date_string
|
266
|
+
Time.now.utc.strftime('%a, %d %b %Y %H:%M:%S GMT')
|
267
|
+
end
|
268
|
+
|
269
|
+
def process_response(body, status, headers, response_type, request_path, context)
|
270
|
+
update_context(headers, context) if context
|
271
|
+
|
272
|
+
throw_exception_if_necessary(body, status, headers, request_path)
|
273
|
+
@marshaller.unmarshal(body, response_type)
|
274
|
+
end
|
275
|
+
|
276
|
+
def update_context(headers, context)
|
277
|
+
context.idempotence_request_timestamp = ResponseHeader.get_header_value(headers, 'X-GCS-Idempotence-Request-Timestamp')
|
278
|
+
end
|
279
|
+
|
280
|
+
def throw_exception_if_necessary(body, status_code, headers, request_path)
|
281
|
+
return if status_code >= 200 && status_code < 300
|
282
|
+
raise ResponseException.new status_code, headers, body unless body && !is_json(headers)
|
283
|
+
|
284
|
+
cause = ResponseException.new(status_code, headers, body)
|
285
|
+
if status_code == 404
|
286
|
+
raise NotFoundException, cause, "The requested resource was not found; invalid path: #{request_path}"
|
287
|
+
end
|
288
|
+
|
289
|
+
raise CommunicationException, cause
|
290
|
+
end
|
291
|
+
|
292
|
+
private
|
293
|
+
|
294
|
+
def is_json(headers)
|
295
|
+
content_type = ResponseHeader.get_header_value(headers, 'Content-Type')
|
296
|
+
content_type.nil? || 'application/json'.casecmp(content_type).zero? ||
|
297
|
+
content_type.downcase.start_with?('application/json')
|
298
|
+
end
|
299
|
+
end
|
300
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
module OnlinePayments::SDK
|
2
|
+
|
3
|
+
# A CommunicatorConfiguration stores all data used to initialize an {OnlinePayments::SDK::Communicator}.
|
4
|
+
#
|
5
|
+
# @attr [String] api_endpoint Base URL to the Online Payments platform
|
6
|
+
# @attr [String] api_key_id Identifier of the _secret_api_key_ used in authentication.
|
7
|
+
# @attr [String] secret_api_key Secret key used in authentication
|
8
|
+
# @attr [String] authorization_type String representing the authentication algorithm used
|
9
|
+
class CommunicatorConfiguration < EndpointConfiguration
|
10
|
+
|
11
|
+
# Creates a new CommunicatorConfiguration instance.
|
12
|
+
#
|
13
|
+
# If a _properties_ object is given, it will be parsed like a hash in order to read these attributes.
|
14
|
+
# If a value is given in both the _properties_ hash and as a separate parameter,
|
15
|
+
# the separate parameter will take precedence over the value in the properties.
|
16
|
+
#
|
17
|
+
# @param properties [Hash] hash that may contain any of the other parameters.
|
18
|
+
# @param api_endpoint [String] the base URL to the Online Payments platform.
|
19
|
+
# @param api_key_id [String] the identifier of the _secret_api_key_ used to authenticate requests.
|
20
|
+
# @param secret_api_key [String] the key used to authenticate requests sent to the Online Payments platform.
|
21
|
+
# @param authorization_type [String] string describing the authorization protocol to follow.
|
22
|
+
# @param connect_timeout [Integer] the number of seconds before a connection attempt with the Online Payments platform times out.
|
23
|
+
# @param socket_timeout [Integer] the number of seconds before a timeout occurs when transmitting data to or from the Online Payments platform.
|
24
|
+
# @param max_connections [Integer] the number of connections with the Online Payments platform that are kept alive in the connection pool.
|
25
|
+
# These connections will be reused when possible.
|
26
|
+
# @param proxy_configuration [OnlinePayments::SDK::ProxyConfiguration] stores the URL to a proxy to be used in all communication,
|
27
|
+
# or nil if no proxy should be used.
|
28
|
+
# @param integrator [String] name of the integrator
|
29
|
+
# @param shopping_cart_extension [OnlinePayments::SDK::Domain::ShoppingCartExtension] stores shopping cart-related metadata.
|
30
|
+
# @see EndpointConfiguration#initialize
|
31
|
+
def initialize(properties: nil, api_endpoint: nil, api_key_id: nil,
|
32
|
+
secret_api_key: nil, authorization_type: nil,
|
33
|
+
connect_timeout: nil, socket_timeout: nil,
|
34
|
+
max_connections: nil, proxy_configuration: nil,
|
35
|
+
integrator: nil, shopping_cart_extension: nil)
|
36
|
+
if properties
|
37
|
+
super(properties, 'onlinePayments.api')
|
38
|
+
@authorization_type = properties['onlinePayments.api.authorizationType'] ?
|
39
|
+
DefaultImpl::AuthorizationType.get_authorization(properties['onlinePayments.api.authorizationType']) :
|
40
|
+
DefaultImpl::AuthorizationType::V1HMAC
|
41
|
+
end
|
42
|
+
@api_endpoint = api_endpoint if api_endpoint
|
43
|
+
@api_key_id = api_key_id if api_key_id
|
44
|
+
@secret_api_key = secret_api_key if secret_api_key
|
45
|
+
@authorization_type = DefaultImpl::AuthorizationType.get_authorization(authorization_type) if authorization_type
|
46
|
+
@connect_timeout = connect_timeout if connect_timeout
|
47
|
+
@socket_timeout = socket_timeout if socket_timeout
|
48
|
+
@max_connections = max_connections if max_connections
|
49
|
+
@proxy_configuration = proxy_configuration if proxy_configuration
|
50
|
+
@integrator = integrator if integrator
|
51
|
+
@shopping_cart_extension = shopping_cart_extension if shopping_cart_extension
|
52
|
+
end
|
53
|
+
|
54
|
+
attr_accessor :api_endpoint
|
55
|
+
attr_accessor :api_key_id
|
56
|
+
attr_accessor :secret_api_key
|
57
|
+
attr_accessor :authorization_type
|
58
|
+
end
|
59
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module OnlinePayments::SDK
|
2
|
+
|
3
|
+
# Class used to communicate using the HTTP (or HTTPS) protocol.
|
4
|
+
# Performs GET, DELETE, POST and PUT requests given a target uri and request headers.
|
5
|
+
# @see OnlinePayments::SDK::DefaultImpl::DefaultConnection
|
6
|
+
class Connection
|
7
|
+
include OnlinePayments::SDK::Logging::LoggingCapable
|
8
|
+
|
9
|
+
# Performs a GET request to _uri_ using _request_headers_,
|
10
|
+
# and yields the response as the status code, headers and body.
|
11
|
+
#
|
12
|
+
# @yield (Integer, Array<OnlinePayments::SDK::ResponseHeader>, IO) The status code, headers and body of the response.
|
13
|
+
def get(uri, request_headers)
|
14
|
+
raise NotImplementedError
|
15
|
+
end
|
16
|
+
|
17
|
+
# Performs a DELETE request to _uri_ using _request_headers_,
|
18
|
+
# and yields the response as the status code, headers and body.
|
19
|
+
#
|
20
|
+
# @yield (Integer, Array<OnlinePayments::SDK::ResponseHeader>, IO) The status code, headers and body of the response.
|
21
|
+
def delete(uri, request_headers)
|
22
|
+
raise NotImplementedError
|
23
|
+
end
|
24
|
+
|
25
|
+
# Performs a POST request to _uri_ using _request_headers_ and _body_,
|
26
|
+
# and yields the response as the status code, headers and body.
|
27
|
+
#
|
28
|
+
# @yield (Integer, Array<OnlinePayments::SDK::ResponseHeader>, IO) The status code, headers and body of the response.
|
29
|
+
def post(uri, request_headers, body)
|
30
|
+
raise NotImplementedError
|
31
|
+
end
|
32
|
+
|
33
|
+
# Performs a PUT request to _uri_ using _request_headers_ and _body_,
|
34
|
+
# and yields the response as the status code, headers and body.
|
35
|
+
#
|
36
|
+
# @yield (Integer, Array<OnlinePayments::SDK::ResponseHeader>, IO) The status code, headers and body of the response.
|
37
|
+
def put(uri, request_headers, body)
|
38
|
+
raise NotImplementedError
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module OnlinePayments::SDK
|
4
|
+
|
5
|
+
# Base class for all SDK data objects, supports marshalling and unmarshalling the data object to and from JSON.
|
6
|
+
class DataObject
|
7
|
+
|
8
|
+
# Returns a hash representation of the DataObject.
|
9
|
+
# The hash contains camelCase representations of the variables, and their values.
|
10
|
+
# Should be overridden to add all instance variables of the object.
|
11
|
+
#
|
12
|
+
# @return [Hash]
|
13
|
+
def to_h
|
14
|
+
{}
|
15
|
+
end
|
16
|
+
|
17
|
+
# Create a new instance of this object (DataObject or descendant)
|
18
|
+
# from a hash containing attribute values in camelCase.
|
19
|
+
# Note that the hash contains Strings as keys instead of more commonly used tokens.
|
20
|
+
def self.new_from_hash(hash)
|
21
|
+
obj = self.new
|
22
|
+
obj.from_hash(hash)
|
23
|
+
obj
|
24
|
+
end
|
25
|
+
|
26
|
+
# Set attributes from values in parameter hash.
|
27
|
+
# Should be overridden by descendants in order to properly restore their attributes from the hash.
|
28
|
+
# Note that the hash contains Strings as keys instead of more commonly used tokens.
|
29
|
+
def from_hash(hash) end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module OnlinePayments::SDK
|
2
|
+
|
3
|
+
# Indicates that a payment is declined by the Online Payments platform or one of its downstream partners/acquirers.
|
4
|
+
class DeclinedPaymentException < DeclinedTransactionException
|
5
|
+
|
6
|
+
# Create a new DeclinedPaymentException.
|
7
|
+
# @see ApiException#initialize
|
8
|
+
def initialize(status_code, response_body, errors)
|
9
|
+
super(status_code, response_body, errors&.error_id, errors&.errors, build_message(errors))
|
10
|
+
@errors = errors
|
11
|
+
end
|
12
|
+
|
13
|
+
# The declined payment result returned by the Online Payments platform.
|
14
|
+
# @return [OnlinePayments::SDK::Domain::CreatePaymentResult, nil]
|
15
|
+
def payment_result
|
16
|
+
@errors&.payment_result
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def build_message(errors)
|
22
|
+
payment = errors&.payment_result&.payment
|
23
|
+
if payment
|
24
|
+
"declined payment '#{payment.id}' with status '#{payment.status}'"
|
25
|
+
else
|
26
|
+
'the Online Payments platform returned a declined payment response'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'onlinepayments/sdk/declined_transaction_exception'
|
2
|
+
|
3
|
+
module OnlinePayments::SDK
|
4
|
+
|
5
|
+
# Indicates that a payout is declined by the Online Payments platform or one of its downstream partners/acquirers.
|
6
|
+
class DeclinedPayoutException < DeclinedTransactionException
|
7
|
+
|
8
|
+
# Create a new DeclinedPayoutException
|
9
|
+
# @see ApiException#initialize
|
10
|
+
def initialize(status_code, response_body, errors)
|
11
|
+
super(status_code, response_body, errors&.error_id, errors&.errors, build_message(errors))
|
12
|
+
@errors = errors
|
13
|
+
end
|
14
|
+
|
15
|
+
# The declined payout result as returned by the Online Payments platform.
|
16
|
+
# @return [OnlinePayments::SDK::Domain::PayoutResult, nil]
|
17
|
+
def payout_result
|
18
|
+
@errors&.payout_result
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def build_message(errors)
|
24
|
+
payout = errors&.payout_result
|
25
|
+
if payout
|
26
|
+
"declined payout '#{payout.id}' with status '#{payout.status}'"
|
27
|
+
else
|
28
|
+
'the Online Payments platform returned a declined payout response'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'onlinepayments/sdk/declined_transaction_exception'
|
2
|
+
|
3
|
+
module OnlinePayments::SDK
|
4
|
+
|
5
|
+
# Indicates that a refund is declined by the Online Payments platform or one of its downstream partners/acquirers.
|
6
|
+
class DeclinedRefundException < DeclinedTransactionException
|
7
|
+
|
8
|
+
# Create a new DeclinedRefundException
|
9
|
+
# @see ApiException#initialize
|
10
|
+
def initialize(status_code, response_body, errors)
|
11
|
+
super(status_code, response_body, errors&.error_id, errors&.errors, build_message(errors))
|
12
|
+
@errors = errors
|
13
|
+
end
|
14
|
+
|
15
|
+
# The declined refund result as returned by the Online Payments platform.
|
16
|
+
# @return [OnlinePayments::SDK::Domain::RefundResult, nil]
|
17
|
+
def refund_result
|
18
|
+
@errors&.refund_result
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def build_message(errors)
|
24
|
+
refund = errors&.refund_result
|
25
|
+
if refund
|
26
|
+
"declined refund '#{refund.id}' with status '#{refund.status}'"
|
27
|
+
else
|
28
|
+
'the Online Payments platform returned a declined refund response'
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module OnlinePayments::SDK
|
2
|
+
|
3
|
+
# Indicates that a transaction is declined by the Online Payments platform or one of its downstream partners/acquirers.
|
4
|
+
class DeclinedTransactionException < ApiException
|
5
|
+
|
6
|
+
# Create a new DeclinedTransactionException.
|
7
|
+
# @see ApiException#initialize
|
8
|
+
def initialize(status_code, response_body, error_id, errors, message = nil)
|
9
|
+
if message
|
10
|
+
super(status_code, response_body, error_id, errors, message)
|
11
|
+
else
|
12
|
+
super(status_code, response_body, error_id, errors)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module OnlinePayments::SDK
|
2
|
+
module DefaultImpl
|
3
|
+
|
4
|
+
# Contains all authentication schemes supported by the GlobabCollect platform.
|
5
|
+
class AuthorizationType
|
6
|
+
V1HMAC = 'v1HMAC'
|
7
|
+
|
8
|
+
# @return [String] the authorization string that belongs to the parameter _authorization_, or _nil_ if not found.
|
9
|
+
def self.get_authorization(authorization)
|
10
|
+
case authorization.downcase
|
11
|
+
when V1HMAC.downcase
|
12
|
+
return V1HMAC
|
13
|
+
else
|
14
|
+
raise ArgumentError "Unknown authorization type '#{authorization}'"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
# @return [String]
|
19
|
+
def self.get_signature_string
|
20
|
+
V1HMAC
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|