From 8dea195b8f4c050f88b9077a7ab1074ac1b4c7df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Armando=20Rodr=C3=ADguez?= <127134616+armando-rodriguez-cko@users.noreply.github.com> Date: Thu, 1 Aug 2024 09:52:18 +0200 Subject: [PATCH] Add partial authorization in payment request --- .../Payments/Request/PartialAuthorization.php | 11 ++++++++++ .../Payments/Request/PaymentRequest.php | 5 +++++ .../IncrementPaymentsAuthorizationsTest.php | 22 ++++++++++++++++--- 3 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 lib/Checkout/Payments/Request/PartialAuthorization.php diff --git a/lib/Checkout/Payments/Request/PartialAuthorization.php b/lib/Checkout/Payments/Request/PartialAuthorization.php new file mode 100644 index 0000000..1081e6b --- /dev/null +++ b/lib/Checkout/Payments/Request/PartialAuthorization.php @@ -0,0 +1,11 @@ +reference = uniqid(); $authorizationRequest->metadata = array("param1" => "value1", "param2" => "value2"); - $authorizationResponse = $this->checkoutApi->getPaymentsClient()->incrementPaymentAuthorization($paymentResponse["id"], $authorizationRequest); + $authorizationResponse = $this->checkoutApi->getPaymentsClient()->incrementPaymentAuthorization( + $paymentResponse["id"], + $authorizationRequest + ); $this->assertResponse( $authorizationResponse, @@ -60,8 +64,16 @@ public function shouldIncrementPaymentAuthorizationIdempotent() $idempotencyKey = $this->idempotencyKey(); - $authorizationResponse = $this->checkoutApi->getPaymentsClient()->incrementPaymentAuthorization($paymentResponse["id"], $authorizationRequest, $idempotencyKey); - $authorizationResponse2 = $this->checkoutApi->getPaymentsClient()->incrementPaymentAuthorization($paymentResponse["id"], $authorizationRequest, $idempotencyKey); + $authorizationResponse = $this->checkoutApi->getPaymentsClient()->incrementPaymentAuthorization( + $paymentResponse["id"], + $authorizationRequest, + $idempotencyKey + ); + $authorizationResponse2 = $this->checkoutApi->getPaymentsClient()->incrementPaymentAuthorization( + $paymentResponse["id"], + $authorizationRequest, + $idempotencyKey + ); $this->assertEquals($authorizationResponse["action_id"], $authorizationResponse2["action_id"]); } @@ -91,12 +103,16 @@ private function makeEstimatedAuthorizedPayment() $paymentIndividualSender->last_name = "Test"; $paymentIndividualSender->address = $address; + $partialAuthorization = new PartialAuthorization(); + $partialAuthorization->enabled = true; + $paymentRequest = new PaymentRequest(); $paymentRequest->source = $requestCardSource; $paymentRequest->capture = false; $paymentRequest->reference = uniqid(); $paymentRequest->amount = 10; $paymentRequest->authorization_type = AuthorizationType::$estimated; + $paymentRequest->partial_authorization = $partialAuthorization; $paymentRequest->currency = Currency::$EUR; $paymentRequest->customer = $customerRequest; $paymentRequest->sender = $paymentIndividualSender;