diff --git a/checkout_sdk/payments/hosted/hosted_payments.py b/checkout_sdk/payments/hosted/hosted_payments.py index c4f5ed3..f6468a2 100644 --- a/checkout_sdk/payments/hosted/hosted_payments.py +++ b/checkout_sdk/payments/hosted/hosted_payments.py @@ -3,7 +3,7 @@ from checkout_sdk.common.common import CustomerRequest, CustomerRetry from checkout_sdk.common.enums import Currency from checkout_sdk.payments.payments import BillingDescriptor, PaymentInstruction, PaymentType, ShippingDetails, \ - ThreeDsRequest, RiskRequest, PaymentRecipient, ProcessingSettings, PaymentSender + ThreeDsRequest, RiskRequest, PaymentRecipient, ProcessingSettings, PaymentSender, AuthorizationType, PaymentPlan from checkout_sdk.payments.payments_previous import BillingInformation from checkout_sdk.payments.sessions.sessions import SessionPaymentMethodConfiguration @@ -40,3 +40,5 @@ class HostedPaymentsSessionRequest: capture_on: datetime instruction: PaymentInstruction payment_method_configuration: SessionPaymentMethodConfiguration + authorization_type: AuthorizationType + payment_plan: PaymentPlan diff --git a/checkout_sdk/payments/links/payments_links.py b/checkout_sdk/payments/links/payments_links.py index c2a3623..cc370ff 100644 --- a/checkout_sdk/payments/links/payments_links.py +++ b/checkout_sdk/payments/links/payments_links.py @@ -3,7 +3,7 @@ from checkout_sdk.common.common import CustomerRequest, CustomerRetry from checkout_sdk.common.enums import Currency from checkout_sdk.payments.payments import BillingDescriptor, PaymentInstruction, PaymentType, ShippingDetails, \ - ThreeDsRequest, RiskRequest, PaymentRecipient, ProcessingSettings, PaymentSender + ThreeDsRequest, RiskRequest, PaymentRecipient, ProcessingSettings, PaymentSender, AuthorizationType, PaymentPlan from checkout_sdk.payments.payments_previous import BillingInformation from checkout_sdk.payments.sessions.sessions import SessionPaymentMethodConfiguration @@ -39,3 +39,5 @@ class PaymentLinkRequest: capture_on: datetime instruction: PaymentInstruction payment_method_configuration: SessionPaymentMethodConfiguration + authorization_type: AuthorizationType + payment_plan: PaymentPlan diff --git a/checkout_sdk/payments/sessions/sessions.py b/checkout_sdk/payments/sessions/sessions.py index 1d6d546..e6b397e 100644 --- a/checkout_sdk/payments/sessions/sessions.py +++ b/checkout_sdk/payments/sessions/sessions.py @@ -3,7 +3,7 @@ from checkout_sdk.common.enums import Currency from checkout_sdk.payments.payments import PaymentType, BillingDescriptor, ShippingDetails, \ - PaymentRecipient, ProcessingSettings, RiskRequest, ThreeDsRequest, PaymentSender + PaymentRecipient, ProcessingSettings, RiskRequest, ThreeDsRequest, PaymentSender, AuthorizationType, PaymentPlan from checkout_sdk.sessions.sessions import SessionsBillingDescriptor @@ -252,6 +252,8 @@ class PaymentSessionsRequest: disabled_payment_methods: list # PaymentMethodsType customer_retry: CustomerRetry ip_address: str + authorization_type: AuthorizationType + payment_plan: PaymentPlan class PaymentSessionWithPaymentRequest: diff --git a/tests/payments/payment_request_fields_serialization_test.py b/tests/payments/payment_request_fields_serialization_test.py new file mode 100644 index 0000000..f1628f2 --- /dev/null +++ b/tests/payments/payment_request_fields_serialization_test.py @@ -0,0 +1,51 @@ +import json + +from checkout_sdk.json_serializer import JsonSerializer +from checkout_sdk.payments.payments import AuthorizationType, PaymentPlan +from checkout_sdk.payments.hosted.hosted_payments import HostedPaymentsSessionRequest +from checkout_sdk.payments.links.payments_links import PaymentLinkRequest +from checkout_sdk.payments.sessions.sessions import PaymentSessionsRequest + + +def _serialize(obj): + return json.loads(json.dumps(obj, cls=JsonSerializer)) + + +def _payment_plan(): + plan = PaymentPlan() + plan.days_between_payments = 30 + plan.total_number_of_payments = 12 + return plan + + +class TestPaymentRequestFieldsSerialization: + + def test_hosted_payments_request_serializes_authorization_type_and_payment_plan(self): + request = HostedPaymentsSessionRequest() + request.authorization_type = AuthorizationType.ESTIMATED + request.payment_plan = _payment_plan() + + assert _serialize(request) == { + 'authorization_type': 'Estimated', + 'payment_plan': {'days_between_payments': 30, 'total_number_of_payments': 12}, + } + + def test_payment_link_request_serializes_authorization_type_and_payment_plan(self): + request = PaymentLinkRequest() + request.authorization_type = AuthorizationType.INCREMENTAL + request.payment_plan = _payment_plan() + + assert _serialize(request) == { + 'authorization_type': 'Incremental', + 'payment_plan': {'days_between_payments': 30, 'total_number_of_payments': 12}, + } + + def test_payment_sessions_request_serializes_authorization_type_and_payment_plan(self): + request = PaymentSessionsRequest() + request.authorization_type = AuthorizationType.FINAL + request.payment_plan = _payment_plan() + + assert _serialize(request) == { + 'authorization_type': 'Final', + 'payment_plan': {'days_between_payments': 30, 'total_number_of_payments': 12}, + }