diff --git a/lib/checkout_sdk/common/customer_retry.rb b/lib/checkout_sdk/common/customer_retry.rb index ef5f253..d1a4270 100644 --- a/lib/checkout_sdk/common/customer_retry.rb +++ b/lib/checkout_sdk/common/customer_retry.rb @@ -1,11 +1,23 @@ # frozen_string_literal: true module CheckoutSdk - module Accounts + module Common + # Configures the parameters for customer retries. A customer retry is a payment attempt + # performed by the customer on the checkout page, used by hosted payments, payment links + # and payment sessions. + # # @!attribute max_attempts - # @return [Integer] + # @return [Integer] [Optional] The maximum number of customer retry attempts, excluding the + # initial payment attempt. Minimum 0, maximum 5. Default 5. + # Required when used in a payment sessions request. class CustomerRetry attr_accessor :max_attempts end end + + module Accounts + # @deprecated Please use {CheckoutSdk::Common::CustomerRetry} instead. This alias will be + # removed in the next major version. + CustomerRetry = CheckoutSdk::Common::CustomerRetry + end end diff --git a/lib/checkout_sdk/payments/downtime_retry_request.rb b/lib/checkout_sdk/payments/downtime_retry_request.rb new file mode 100644 index 0000000..1735c1a --- /dev/null +++ b/lib/checkout_sdk/payments/downtime_retry_request.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +module CheckoutSdk + module Payments + # Configuration of Downtime retries. + # + # @!attribute enabled + # @return [TrueClass, FalseClass] [Required] Indicates if Checkout.com retries the payment when it's declined + # due to issuer or acquirer downtime. + class DowntimeRetryRequest + attr_accessor :enabled + end + end +end diff --git a/lib/checkout_sdk/payments/dunning_retry_request.rb b/lib/checkout_sdk/payments/dunning_retry_request.rb new file mode 100644 index 0000000..1be7456 --- /dev/null +++ b/lib/checkout_sdk/payments/dunning_retry_request.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +module CheckoutSdk + module Payments + # Configuration of Dunning retries. + # + # @!attribute enabled + # @return [TrueClass, FalseClass] [Required] Indicates if Checkout.com retries the payment when it's declined + # with a supported decline code. + # @!attribute max_attempts + # @return [Integer] [Optional] The maximum number of authorization retry attempts, excluding the initial + # authorization. Minimum 1, maximum 15. Default 6. + # @!attribute end_after_days + # @return [Integer] [Optional] The maximum number of days between the initial request and the final retry + # attempt. Minimum 1, maximum 60. Default 30. + class DunningRetryRequest + attr_accessor :enabled, + :max_attempts, + :end_after_days + end + end +end diff --git a/lib/checkout_sdk/payments/hosted/hosted_payments_session.rb b/lib/checkout_sdk/payments/hosted/hosted_payments_session.rb index f319295..b0c8320 100644 --- a/lib/checkout_sdk/payments/hosted/hosted_payments_session.rb +++ b/lib/checkout_sdk/payments/hosted/hosted_payments_session.rb @@ -5,67 +5,78 @@ module CheckoutSdk module Payments # @!attribute currency - # @return [String] {CheckoutSdk::Common::Currency} + # @return [String] {CheckoutSdk::Common::Currency} [Required] The three-letter ISO currency code of the payment # @!attribute billing - # @return [BillingInformation] + # @return [BillingInformation] [Required] The billing details # @!attribute success_url - # @return [String] + # @return [String] [Required] For redirect payment methods, this overrides the default success redirect URL + # configured on your account # @!attribute cancel_url - # @return [String] + # @return [String] [Required] The URL to which the customer should be directed if they cancel the payment # @!attribute failure_url - # @return [String] + # @return [String] [Required] For redirect payment methods, this overrides the default failure redirect URL + # configured on your account # @!attribute amount - # @return [Integer] + # @return [Integer] [Optional] The payment amount. Minimum 0. # @!attribute payment_type - # @return [String] {PaymentType} + # @return [String] {PaymentType} [Optional] This must be specified for card payments where the cardholder is not + # present (i.e., recurring or mail order / telephone order) # @!attribute payment_ip - # @return [String] + # @return [String] [Optional] The Customers IP address. Only IPv4 and IPv6 addresses are accepted. + # @deprecated The Customers IP address is deprecated in the API reference. Will be removed in the next + # major version. # @!attribute billing_descriptor - # @return [BillingDescriptor] + # @return [BillingDescriptor] [Optional] An optional description that is displayed on the customer's statement + # identifying a purchase # @!attribute reference - # @return [String] + # @return [String] [Optional] A reference you can use to identify the payment. # @!attribute description - # @return [String] + # @return [String] [Optional] A description of the payment # @!attribute display_name - # @return [String] + # @return [String] [Optional] The merchant name to display to customers on the checkout page. # @!attribute processing_channel_id - # @return [String] + # @return [String] [Optional] The processing channel to be used for the payment # @!attribute amount_allocations - # @return [Array(CheckoutSdk::Common::AmountAllocations)] + # @return [Array(CheckoutSdk::Common::AmountAllocations)] [Optional] The sub-entities that the payment is being + # processed on behalf of # @!attribute customer - # @return [CheckoutSdk::Common::CustomerRequest] + # @return [CheckoutSdk::Common::CustomerRequest] [Optional] The customer's details # @!attribute shipping - # @return [ShippingDetails] + # @return [ShippingDetails] [Optional] The address any products are being sent to. # @!attribute recipient - # @return [PaymentRecipient] + # @return [PaymentRecipient] [Optional] Information about the recipient of the payment's funds. # @!attribute processing - # @return [ProcessingSettings] + # @return [ProcessingSettings] [Optional] Use the processing object to influence or override the data sent + # during card processing # @!attribute allow_payment_methods - # @return [Array(CheckoutSdk::Common::PaymentSourceType)] + # @return [Array(CheckoutSdk::Common::PaymentSourceType)] [Optional] Specifies which payment method options to + # present to the customer. # @!attribute disabled_payment_methods - # @return [Array(CheckoutSdk::Common::PaymentSourceType)] + # @return [Array(CheckoutSdk::Common::PaymentSourceType)] [Optional] Specifies which payment method options to + # not present to the customer. # @!attribute products - # @return [Array(CheckoutSdk::Common::Product)] + # @return [Array(CheckoutSdk::Common::Product)] [Optional] Contains details about the products in the order. # @!attribute risk - # @return [RiskRequest] + # @return [RiskRequest] [Optional] Configures the risk assessment performed during payment processing. # @!attribute customer_retry - # @return [PaymentRetryRequest] + # @return [CheckoutSdk::Common::CustomerRetry] [Optional] Configures the parameters for customer retries + # performed by the customer on the checkout page. # @!attribute sender - # @return [CheckoutSdk::Payments::Sender] + # @return [CheckoutSdk::Payments::Sender] [Optional] The sender of the payment. # @!attribute metadata - # @return [Hash(String=>Object)] + # @return [Hash(String=>Object)] [Optional] Allows you to store additional information about the transaction. # @!attribute locale - # @return [String] {LocaleType} + # @return [String] {LocaleType} [Optional] Creates a translated version of the page in the specified language # @!attribute three_ds - # @return [ThreeDSRequest] + # @return [ThreeDSRequest] [Optional] Information required for 3D Secure payments # @!attribute capture - # @return [TrueClass, FalseClass] + # @return [TrueClass, FalseClass] [Optional] Whether to capture the payment (if applicable). # @!attribute capture_on - # @return [Time] + # @return [Time] [Optional] A timestamp (ISO 8601 code) that determines when the payment should be captured. # @!attribute instruction - # @return [HostedPaymentInstruction] + # @return [HostedPaymentInstruction] [Optional] Details about the payment instruction. # @!attribute payment_method_configuration - # @return [PaymentMethodConfiguration] + # @return [PaymentMethodConfiguration] [Optional] Configuration options for specific payment methods. # @!attribute payment_plan # @return [PaymentPlan] [Optional] The information to process a recurring payment request. # To be used when the payment_type is Recurring. diff --git a/lib/checkout_sdk/payments/links/payment_link.rb b/lib/checkout_sdk/payments/links/payment_link.rb index 3679a28..7dc654b 100644 --- a/lib/checkout_sdk/payments/links/payment_link.rb +++ b/lib/checkout_sdk/payments/links/payment_link.rb @@ -5,64 +5,83 @@ module CheckoutSdk module Payments # @!attribute amount - # @return [Integer] + # @return [Integer] [Required] The payment amount. # @!attribute currency - # @return [String] {CheckoutSdk::Common::Currency} + # @return [String] {CheckoutSdk::Common::Currency} [Required] The three-letter ISO currency code of the + # payment. The `currency` and `billing.address.country` fields determine which payment methods are shown on the + # payment page. # @!attribute payment_type - # @return [String] {PaymentType} + # @return [String] {PaymentType} [Optional] This must be specified for card payments where the cardholder is not + # present (i.e., recurring or mail order / telephone order). Default: "Regular". # @!attribute payment_ip - # @return [String] + # @return [String] [Optional] The Customers IP address. Only IPv4 and IPv6 addresses are accepted. + # @deprecated The Customers IP address is deprecated in the API reference. Will be removed in the next + # major version. # @!attribute billing_descriptor - # @return [BillingDescriptor] + # @return [BillingDescriptor] [Optional] An optional description that is displayed on the customer's statement + # identifying a purchase # @!attribute reference - # @return [String] + # @return [String] [Optional] A reference you can use to identify the payment. # @!attribute description - # @return [String] + # @return [String] [Optional] A description of the payment. # @!attribute display_name - # @return [String] + # @return [String] [Optional] The merchant name to display to customers on the checkout page. # @!attribute processing_channel_id - # @return [String] - Not available on Previous. + # @return [String] [Optional] The processing channel to use for the payment. This field is required if you + # have more than one processing channel associated with your API key. # @!attribute amount_allocations - # @return [Array(CheckoutSdk::Common::AmountAllocations)] - Not available on Previous. + # @return [Array(CheckoutSdk::Common::AmountAllocations)] [Optional] The sub-entities that the payment is being + # processed on behalf of. # @!attribute expires_in - # @return [Integer] + # @return [Integer] [Optional] The time for which the link remains valid, in seconds. Minimum 1, maximum 5184000. + # Default: 86400. # @!attribute customer - # @return [CheckoutSdk::Common::CustomerRequest] + # @return [CheckoutSdk::Common::CustomerRequest] [Optional] The customer's details # @!attribute shipping - # @return [ShippingDetails] + # @return [ShippingDetails] [Optional] The address any products are being sent to. # @!attribute billing - # @return [BillingInformation] + # @return [BillingInformation] [Required] The billing details. # @!attribute recipient - # @return [PaymentRecipient] + # @return [PaymentRecipient] [Optional] Information about the recipient of the payment's funds. # @!attribute processing - # @return [ProcessingSettings] + # @return [ProcessingSettings] [Optional] Use the processing object to influence or override the data sent + # during card processing # @!attribute allow_payment_methods - # @return [Array(CheckoutSdk::Common::PaymentSourceType)] + # @return [Array(CheckoutSdk::Common::PaymentSourceType)] [Optional] Specifies which payment method options to + # present to the customer. # @!attribute disabled_payment_methods - # @return [Array(CheckoutSdk::Common::PaymentSourceType)] + # @return [Array(CheckoutSdk::Common::PaymentSourceType)] [Optional] Specifies which payment method options to + # not present to the customer. # @!attribute products - # @return [Array(CheckoutSdk::Common::Product)] + # @return [Array(CheckoutSdk::Common::Product)] [Optional] Contains details about the products in the order. # @!attribute metadata - # @return [Hash(String=>Object)] + # @return [Hash(String=>Object)] [Optional] Allows you to store additional information about the transaction. # @!attribute three_ds - # @return [ThreeDSRequest] + # @return [ThreeDSRequest] [Optional] Information required for 3D Secure payments. # @!attribute risk - # @return [RiskRequest] + # @return [RiskRequest] [Optional] Configures the risk assessment performed during payment processing. # @!attribute customer_retry - # @return [CheckoutSdk::Common::CustomerRetry] + # @return [CheckoutSdk::Common::CustomerRetry] [Optional] Configures the parameters for customer retries + # performed by the customer on the checkout page. # @!attribute sender - # @return [CheckoutSdk::Payments::Sender] + # @return [CheckoutSdk::Payments::Sender] [Optional] The sender of the payment. # @!attribute return_url - # @return [String] + # @return [String] [Optional] If provided, the success page will include a button that redirects your customer + # to the provided URL. # @!attribute locale - # @return [String] + # @return [String] [Optional] Creates a translated version of the page in the specified language. + # Default: "en-GB". # @!attribute capture - # @return [TrueClass, FalseClass] + # @return [TrueClass, FalseClass] [Optional] Whether to capture the payment (if applicable). # @!attribute capture_on - # @return [Time] + # @return [Time] [Optional] A timestamp (ISO 8601 code) that determines when the payment should be captured. # @!attribute payment_plan # @return [PaymentPlan] [Optional] The information to process a recurring payment request. # To be used when the payment_type is Recurring. + # @!attribute instruction + # @return [HostedPaymentInstruction] [Optional] Details about the payment instruction. + # @!attribute payment_method_configuration + # @return [PaymentMethodConfiguration] [Optional] Configuration options for specific payment methods. # @!attribute authorization_type # @return [String] [Optional] {AuthorizationType} Enum: "Final" "Estimated". Default: "Final". class PaymentLink @@ -95,7 +114,9 @@ class PaymentLink :capture, :capture_on, :payment_plan, - :authorization_type + :authorization_type, + :instruction, + :payment_method_configuration def initialize(payment_type: CheckoutSdk::Payments::PaymentType::REGULAR) @payment_type = payment_type diff --git a/lib/checkout_sdk/payments/payment_request.rb b/lib/checkout_sdk/payments/payment_request.rb index 9ce278b..b3a9a77 100644 --- a/lib/checkout_sdk/payments/payment_request.rb +++ b/lib/checkout_sdk/payments/payment_request.rb @@ -62,7 +62,7 @@ module Payments # @!attribute items # @return [Array(Product)] # @!attribute retry - # @return [PaymentRetryRequest] + # @return [PaymentRetryRequest] [Optional] Configuration of asynchronous retries. # @!attribute metadata # @return [Hash{String => Object}] # @!attribute instruction diff --git a/lib/checkout_sdk/payments/payment_retry_request.rb b/lib/checkout_sdk/payments/payment_retry_request.rb index b8fb06e..aea4767 100644 --- a/lib/checkout_sdk/payments/payment_retry_request.rb +++ b/lib/checkout_sdk/payments/payment_retry_request.rb @@ -2,16 +2,18 @@ module CheckoutSdk module Payments + # Configuration of asynchronous retries (POST /payments). + # # @!attribute enabled - # @return [TrueClass, FalseClass] - # @!attribute max_attempts - # @return [Integer] - # @!attribute end_after_days - # @return [Integer] + # @return [TrueClass, FalseClass] [Required] Indicates whether asynchronous retries are enabled for the payment. + # @!attribute dunning + # @return [DunningRetryRequest] [Optional] Configuration of asynchronous Dunning retries. + # @!attribute downtime + # @return [DowntimeRetryRequest] [Optional] Configuration of asynchronous Downtime retries. class PaymentRetryRequest attr_accessor :enabled, - :max_attempts, - :end_after_day + :dunning, + :downtime end end end diff --git a/lib/checkout_sdk/payments/payments.rb b/lib/checkout_sdk/payments/payments.rb index 6b7b907..021c41c 100644 --- a/lib/checkout_sdk/payments/payments.rb +++ b/lib/checkout_sdk/payments/payments.rb @@ -42,6 +42,9 @@ require 'checkout_sdk/payments/exemption' require 'checkout_sdk/payments/three_ds_flow_type' require 'checkout_sdk/payments/void_request' +require 'checkout_sdk/payments/dunning_retry_request' +require 'checkout_sdk/payments/downtime_retry_request' +require 'checkout_sdk/payments/payment_retry_request' require 'checkout_sdk/payments/payment_request' require 'checkout_sdk/payments/processing_settings' require 'checkout_sdk/payments/processing_data' diff --git a/lib/checkout_sdk/payments/sessions/payment_sessions_request.rb b/lib/checkout_sdk/payments/sessions/payment_sessions_request.rb index fa1ac45..4ea6b34 100644 --- a/lib/checkout_sdk/payments/sessions/payment_sessions_request.rb +++ b/lib/checkout_sdk/payments/sessions/payment_sessions_request.rb @@ -3,69 +3,90 @@ module CheckoutSdk module Payments # @!attribute amount - # @return [Integer] + # @return [Integer] [Required] The payment amount. # @!attribute currency - # @return [String] {CheckoutSdk::Common::Currency} + # @return [String] {CheckoutSdk::Common::Currency} [Required] The three-letter ISO currency code. # @!attribute payment_type - # @return [TrueClass, FalseClass] + # @return [String] {PaymentType} [Optional] Must be specified for card-not-present (CNP) payments. + # Enum: "Regular" "Recurring" "MOTO" "Installment" "Unscheduled". Default: "Regular". # @!attribute billing - # @return [BillingInformation] + # @return [BillingInformation] [Required] The billing details. # @!attribute billing_descriptor - # @return [BillingDescriptor] + # @return [BillingDescriptor] [Optional] A description of the purchase, which is displayed on the customer's + # statement. # @!attribute reference - # @return [String] + # @return [String] [Optional] A reference you can use to identify the payment. # @!attribute description - # @return [String] + # @return [String] [Optional] A description for the payment. # @!attribute customer - # @return [CheckoutSdk::Common::CustomerRequest] + # @return [CheckoutSdk::Common::CustomerRequest] [Optional] The customer's details. # @!attribute shipping - # @return [ShippingDetails] + # @return [ShippingDetails] [Optional] The shipping details # @!attribute recipient - # @return [PaymentRecipient] + # @return [PaymentRecipient] [Optional] Information about the recipient of the payment's funds. # @!attribute processing - # @return [ProcessingSettings] + # @return [ProcessingSettings] [Optional] Use the processing object to influence or override the data sent + # during card processing # @!attribute processing_channel_id - # @return [String] + # @return [String] [Optional] The processing channel to use for the payment. # @!attribute expires_on - # @return [Time] + # @return [Time] [Optional] A timestamp specifying when the `PaymentSession` should expire, as an ISO 8601 code. # @!attribute payment_method_configuration - # @return [PaymentMethodConfiguration] + # @return [PaymentMethodConfiguration] [Optional] Configurations for payment method-specific settings. # @!attribute enabled_payment_methods - # @return [Array(PaymentMethodsType)] + # @return [Array(PaymentMethodsType)] [Optional] Specifies which payment method options to present to the + # customer. # @!attribute disabled_payment_methods - # @return [Array(PaymentMethodsType)] + # @return [Array(PaymentMethodsType)] [Optional] Specifies which payment method options to not present to the + # customer. # @!attribute items - # @return [Array(Product)] + # @return [Array(Product)] [Optional] The line items in the order. # @!attribute amount_allocations - # @return [Array(CheckoutSdk::Common::AmountAllocations)] + # @return [Array(CheckoutSdk::Common::AmountAllocations)] [Optional] The sub-entities that the payment is being + # processed on behalf of. # @!attribute risk - # @return [RiskRequest] + # @return [RiskRequest] [Optional] Configures the risk assessment performed during payment processing. # @!attribute retry - # @return [PaymentRetryRequest] + # @return [PaymentRetryRequest] [Optional] Configuration of asynchronous retries. + # @deprecated Not part of the payment sessions request; the API ignores it. Will be removed in the next + # major version. + # @!attribute customer_retry + # @return [CheckoutSdk::Common::CustomerRetry] [Optional] Configures the parameters for customer retries + # performed by the customer on the checkout page. max_attempts is the maximum number of customer retry + # attempts, excluding the initial payment attempt (minimum 0, maximum 5, default 5); it is required + # when customer_retry is set. # @!attribute display_name - # @return [String] + # @return [String] [Optional] The merchant's display name. # @!attribute success_url - # @return [String] + # @return [String] [Required] Overrides the default success redirect URL configured on your account, for payment + # methods that require a redirect. # @!attribute failure_url - # @return [String] + # @return [String] [Required] Overrides the default failure redirect URL configured on your account, for payment + # methods that require a redirect. # @!attribute metadata - # @return [Hash{String => Object}] + # @return [Hash{String => Object}] [Optional] Allows you to store additional information about a transaction + # with custom fields and up to five user-defined fields, which can be used for reporting purposes. # @!attribute locale - # @return [String] + # @return [String] [Optional] Creates a translated version of the page in the specified language. # @!attribute three_ds - # @return [ThreeDSRequest] + # @return [ThreeDSRequest] [Optional] Information required for 3D Secure authentication payments. # @!attribute sender - # @return [Sender] + # @return [Sender] [Optional] The sender of the payment. # @!attribute capture - # @return [TrueClass, FalseClass] + # @return [TrueClass, FalseClass] [Optional] Specifies whether to capture the payment, if applicable. # @!attribute ip_address - # @return [String] + # @return [String] [Optional] The Customers IP address. Only IPv4 and IPv6 addresses are accepted. + # @deprecated The Customers IP address is deprecated in the API reference. Will be removed in the next + # major version. # @!attribute capture_on - # @return [Time] + # @return [Time] [Optional] A timestamp specifying when to capture the payment, as an ISO 8601 code. # @!attribute tax_amount - # @return [Integer] + # @return [Integer] [Optional] The total tax amount, in the minor currency unit. Not in the + # payment sessions request specification. # @!attribute authorization_type # @return [String] [Optional] {AuthorizationType} Enum: "Final" "Estimated". Default: "Final". + # @!attribute instruction + # @return [HostedPaymentInstruction] [Optional] Details about the payment instruction. # @!attribute payment_plan # @return [PaymentPlan] [Optional] The information to process a recurring payment request. # To be used when the payment_type is Recurring. @@ -90,6 +111,7 @@ class PaymentSessionsRequest :amount_allocations, :risk, :retry, + :customer_retry, :display_name, :success_url, :failure_url, @@ -102,7 +124,8 @@ class PaymentSessionsRequest :capture_on, :tax_amount, :authorization_type, - :payment_plan + :payment_plan, + :instruction end end end diff --git a/spec/checkout_sdk/payments/hosted/hosted_payments_integration_spec.rb b/spec/checkout_sdk/payments/hosted/hosted_payments_integration_spec.rb index 7cd6ff5..33052d5 100644 --- a/spec/checkout_sdk/payments/hosted/hosted_payments_integration_spec.rb +++ b/spec/checkout_sdk/payments/hosted/hosted_payments_integration_spec.rb @@ -78,7 +78,7 @@ def create_hosted_payments_request billing_descriptor.name = "The Jewelry Shop" billing_descriptor.reference = "ORD-123A" - customer_retry = CheckoutSdk::Payments::PaymentRetryRequest.new + customer_retry = CheckoutSdk::Common::CustomerRetry.new customer_retry.max_attempts = 2 sender = CheckoutSdk::Payments::InstrumentSender.new diff --git a/spec/checkout_sdk/payments/retry_request_serialization_spec.rb b/spec/checkout_sdk/payments/retry_request_serialization_spec.rb new file mode 100644 index 0000000..2074576 --- /dev/null +++ b/spec/checkout_sdk/payments/retry_request_serialization_spec.rb @@ -0,0 +1,96 @@ +# frozen_string_literal: true + +def retry_to_json_hash(obj) + JSON.parse(CheckoutSdk::JsonSerializer.to_custom_hash(obj).to_json) +end + +def build_full_retry_request + dunning = CheckoutSdk::Payments::DunningRetryRequest.new + dunning.enabled = true + dunning.max_attempts = 6 + dunning.end_after_days = 30 + downtime = CheckoutSdk::Payments::DowntimeRetryRequest.new + downtime.enabled = false + request = CheckoutSdk::Payments::PaymentRetryRequest.new + request.enabled = true + request.dunning = dunning + request.downtime = downtime + request +end + +RSpec.describe CheckoutSdk::Payments::PaymentRetryRequest do + it 'serializes all properties to the expected JSON' do + expected = JSON.parse('{"enabled":true,"dunning":{"enabled":true,"max_attempts":6,"end_after_days":30},' \ + '"downtime":{"enabled":false}}') + expect(retry_to_json_hash(build_full_retry_request)).to eq(expected) + end + + it 'serializes enabled false' do + request = described_class.new + request.enabled = false + expect(retry_to_json_hash(request)).to eq(JSON.parse('{"enabled":false}')) + end +end + +RSpec.describe CheckoutSdk::Payments::DunningRetryRequest do + it 'serializes all properties with enabled false' do + request = described_class.new + request.enabled = false + request.max_attempts = 15 + request.end_after_days = 60 + expect(retry_to_json_hash(request)).to eq(JSON.parse('{"enabled":false,"max_attempts":15,"end_after_days":60}')) + end +end + +RSpec.describe CheckoutSdk::Payments::DowntimeRetryRequest do + it 'serializes enabled false' do + request = described_class.new + request.enabled = false + expect(retry_to_json_hash(request)).to eq(JSON.parse('{"enabled":false}')) + end +end + +RSpec.describe CheckoutSdk::Common::CustomerRetry do + it 'serializes the swagger example' do + expect(retry_to_json_hash(described_class.new.tap { |c| c.max_attempts = 2 })) + .to eq(JSON.parse('{"max_attempts":2}')) + end + + it 'serializes max_attempts 0' do + expect(retry_to_json_hash(described_class.new.tap { |c| c.max_attempts = 0 })) + .to eq(JSON.parse('{"max_attempts":0}')) + end + + it 'keeps the deprecated Accounts alias pointing to the same class' do + expect(CheckoutSdk::Accounts::CustomerRetry).to equal(described_class) + end + + it 'is used by hosted payments, payment links and payment sessions' do + [CheckoutSdk::Payments::HostedPaymentsSession, CheckoutSdk::Payments::PaymentLink, + CheckoutSdk::Payments::PaymentSessionsRequest].each do |klass| + request = klass.new + request.customer_retry = described_class.new.tap { |c| c.max_attempts = 2 } + expect(retry_to_json_hash(request)['customer_retry']).to eq(JSON.parse('{"max_attempts":2}')) + end + end +end + +RSpec.describe 'instruction and payment_method_configuration on payment links and payment sessions' do + it 'serializes instruction on payment links and payment sessions' do + [CheckoutSdk::Payments::PaymentLink, CheckoutSdk::Payments::PaymentSessionsRequest].each do |klass| + request = klass.new + request.instruction = CheckoutSdk::Payments::HostedPaymentInstruction.new.tap { |i| i.purpose = 'donations' } + expect(retry_to_json_hash(request)['instruction']).to eq(JSON.parse('{"purpose":"donations"}')) + end + end + + it 'serializes payment_method_configuration on payment links' do + request = CheckoutSdk::Payments::PaymentLink.new + card = CheckoutSdk::Payments::Card.new + card.store_payment_details = 'collect_consent' + request.payment_method_configuration = CheckoutSdk::Payments::PaymentMethodConfiguration.new + request.payment_method_configuration.card = card + expect(retry_to_json_hash(request)['payment_method_configuration']) + .to eq(JSON.parse('{"card":{"store_payment_details":"collect_consent"}}')) + end +end