Skip to content

Commit

Permalink
Add partial authorization in payment request (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
armando-rodriguez-cko authored Aug 1, 2024
1 parent 91797be commit 4b3f825
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
11 changes: 11 additions & 0 deletions lib/Checkout/Payments/Request/PartialAuthorization.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Checkout\Payments\Request;

class PartialAuthorization
{
/**
* @var bool
*/
public $enabled;
}
5 changes: 5 additions & 0 deletions lib/Checkout/Payments/Request/PaymentRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ class PaymentRequest
*/
public $authorization_type;

/**
* @var PartialAuthorization
*/
public $partial_authorization;

/**
* @var bool
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Checkout\Common\CustomerRequest;
use Checkout\Payments\AuthorizationRequest;
use Checkout\Payments\AuthorizationType;
use Checkout\Payments\Request\PartialAuthorization;
use Checkout\Payments\Request\PaymentRequest;
use Checkout\Payments\Request\Source\RequestCardSource;
use Checkout\Payments\Sender\PaymentIndividualSender;
Expand All @@ -27,7 +28,10 @@ public function shouldIncrementPaymentAuthorization()
$authorizationRequest->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,
Expand Down Expand Up @@ -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"]);
}
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 4b3f825

Please sign in to comment.