From b6de99b2b72c84494b8e6aa68ad5fddb195a524c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Fri, 19 Jun 2026 11:34:18 +0200 Subject: [PATCH] feat: add authorization_type and payment_plan to hosted, link and session payment requests Adds the authorization_type (Final/Estimated) and payment_plan properties to HostedPaymentsSessionRequest, PaymentLinkRequest and PaymentSessionsRequest, matching the swagger additions to HostedPaymentsRequest, PaymentLinksRequest and CreatePaymentSessionsBaseRequest. payment_plan is typed as the existing Checkout\Payments\PaymentPlan, which already maps the PaymentSessionPaymentPlanRecurring schema; added the missing amount_variability field to it. Adds serialization tests for the new fields. --- .../Hosted/HostedPaymentsSessionRequest.php | 15 ++++ .../Payments/Links/PaymentLinkRequest.php | 15 ++++ lib/Checkout/Payments/PaymentPlan.php | 8 +++ .../Sessions/PaymentSessionsRequest.php | 15 ++++ .../PaymentRequestFieldsSerializationTest.php | 72 +++++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 test/Checkout/Tests/Payments/PaymentRequestFieldsSerializationTest.php diff --git a/lib/Checkout/Payments/Hosted/HostedPaymentsSessionRequest.php b/lib/Checkout/Payments/Hosted/HostedPaymentsSessionRequest.php index 7d66ea1..b6ab69b 100644 --- a/lib/Checkout/Payments/Hosted/HostedPaymentsSessionRequest.php +++ b/lib/Checkout/Payments/Hosted/HostedPaymentsSessionRequest.php @@ -174,4 +174,19 @@ class HostedPaymentsSessionRequest * @var array values of AmountAllocations */ public $amount_allocations; + + /** + * The authorization type. + * [Optional] + * Allowed values: "Final", "Estimated". Defaults to "Final". + * @var string|null $authorization_type + */ + public $authorization_type; + + /** + * The payment plan details. To be used when the payment_type is Recurring. + * [Optional] + * @var \Checkout\Payments\PaymentPlan|null $payment_plan + */ + public $payment_plan; } diff --git a/lib/Checkout/Payments/Links/PaymentLinkRequest.php b/lib/Checkout/Payments/Links/PaymentLinkRequest.php index 03c5993..28acfe7 100644 --- a/lib/Checkout/Payments/Links/PaymentLinkRequest.php +++ b/lib/Checkout/Payments/Links/PaymentLinkRequest.php @@ -182,4 +182,19 @@ class PaymentLinkRequest * @var array values of AmountAllocations */ public $amount_allocations; + + /** + * The authorization type. + * [Optional] + * Allowed values: "Final", "Estimated". Defaults to "Final". + * @var string|null $authorization_type + */ + public $authorization_type; + + /** + * The payment plan details. To be used when the payment_type is Recurring. + * [Optional] + * @var \Checkout\Payments\PaymentPlan|null $payment_plan + */ + public $payment_plan; } diff --git a/lib/Checkout/Payments/PaymentPlan.php b/lib/Checkout/Payments/PaymentPlan.php index d815199..98a938d 100644 --- a/lib/Checkout/Payments/PaymentPlan.php +++ b/lib/Checkout/Payments/PaymentPlan.php @@ -4,6 +4,14 @@ class PaymentPlan { + /** + * Specifies whether the amount is fixed or variable for each recurrence. + * [Optional] + * Allowed values: "Fixed", "Variable". + * @var string|null $amount_variability + */ + public $amount_variability; + /** * Indicates the minimum number of days between payments. * [Optional] diff --git a/lib/Checkout/Payments/Sessions/PaymentSessionsRequest.php b/lib/Checkout/Payments/Sessions/PaymentSessionsRequest.php index 98be5c7..4e80f9a 100644 --- a/lib/Checkout/Payments/Sessions/PaymentSessionsRequest.php +++ b/lib/Checkout/Payments/Sessions/PaymentSessionsRequest.php @@ -175,4 +175,19 @@ class PaymentSessionsRequest * @var string */ public $ip_address; + + /** + * The authorization type. + * [Optional] + * Allowed values: "Final", "Estimated". Defaults to "Final". + * @var string|null $authorization_type + */ + public $authorization_type; + + /** + * The payment plan details. To be used when the payment_type is Recurring. + * [Optional] + * @var \Checkout\Payments\PaymentPlan|null $payment_plan + */ + public $payment_plan; } diff --git a/test/Checkout/Tests/Payments/PaymentRequestFieldsSerializationTest.php b/test/Checkout/Tests/Payments/PaymentRequestFieldsSerializationTest.php new file mode 100644 index 0000000..c9c70f8 --- /dev/null +++ b/test/Checkout/Tests/Payments/PaymentRequestFieldsSerializationTest.php @@ -0,0 +1,72 @@ +amount_variability = 'Variable'; + $plan->days_between_payments = 28; + $plan->total_number_of_payments = 5; + $plan->current_payment_number = 3; + return $plan; + } + + public function testHostedPaymentsSessionRequestSerializesAuthorizationTypeAndPaymentPlan() + { + $request = new HostedPaymentsSessionRequest(); + $request->authorization_type = "Estimated"; + $request->payment_plan = $this->paymentPlan(); + + $decoded = json_decode((new JsonSerializer())->serialize($request), true); + + $this->assertSame("Estimated", $decoded['authorization_type']); + $this->assertSame('Variable', $decoded['payment_plan']['amount_variability']); + $this->assertSame(28, $decoded['payment_plan']['days_between_payments']); + $this->assertSame(5, $decoded['payment_plan']['total_number_of_payments']); + } + + public function testPaymentLinkRequestSerializesAuthorizationTypeAndPaymentPlan() + { + $request = new PaymentLinkRequest(); + $request->authorization_type = "Final"; + $request->payment_plan = $this->paymentPlan(); + + $decoded = json_decode((new JsonSerializer())->serialize($request), true); + + $this->assertSame("Final", $decoded['authorization_type']); + $this->assertSame('Variable', $decoded['payment_plan']['amount_variability']); + $this->assertSame(28, $decoded['payment_plan']['days_between_payments']); + } + + public function testPaymentSessionsRequestSerializesAuthorizationTypeAndPaymentPlan() + { + $request = new PaymentSessionsRequest(); + $request->authorization_type = "Estimated"; + $request->payment_plan = $this->paymentPlan(); + + $decoded = json_decode((new JsonSerializer())->serialize($request), true); + + $this->assertSame("Estimated", $decoded['authorization_type']); + $this->assertSame('Variable', $decoded['payment_plan']['amount_variability']); + $this->assertSame(3, $decoded['payment_plan']['current_payment_number']); + } + + public function testUnsetFieldsAreOmittedFromSerialization() + { + $request = new PaymentSessionsRequest(); + $decoded = json_decode((new JsonSerializer())->serialize($request), true); + + $this->assertArrayNotHasKey('authorization_type', $decoded); + $this->assertArrayNotHasKey('payment_plan', $decoded); + } +}