From 0cef7df4824eb267c5ee925d4b239a9fba904876 Mon Sep 17 00:00:00 2001 From: Steve Nester <82510386+steve-gr4vy@users.noreply.github.com> Date: Tue, 28 Nov 2023 14:05:28 +0000 Subject: [PATCH] add void transaction (#24) --- lib/Gr4vyConfig.php | 6 +++++- test/Api/TransactionsApiTest.php | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/lib/Gr4vyConfig.php b/lib/Gr4vyConfig.php index 2c8eb7f..e8d6b5a 100644 --- a/lib/Gr4vyConfig.php +++ b/lib/Gr4vyConfig.php @@ -119,7 +119,7 @@ public static function getToken($private_key, $scopes = array(), $embed = array( $now = new DateTimeImmutable(); $tokenBuilder = $config->builder() // Configures the issuer (iss claim) - ->issuedBy('Gr4vy SDK 0.20.0') + ->issuedBy('Gr4vy SDK 0.21.0') // Configures the id (jti claim) ->identifiedBy(self::gen_uuid()) // Configures the time that the token was issue (iat claim) @@ -415,6 +415,10 @@ public function refundTransaction($transaction_id, $refund_request) { $response = $this->post("/transactions/" . $transaction_id . "/refunds", $refund_request); return $response; } + public function voidTransaction($transaction_id, $request = array()) { + $response = $this->post("/transactions/" . $transaction_id . "/void", $request); + return $response; + } public function newCheckoutSession($request = array()) { $response = $this->post("/checkout/sessions", $request); return $response; diff --git a/test/Api/TransactionsApiTest.php b/test/Api/TransactionsApiTest.php index c03b8c2..18fcf12 100644 --- a/test/Api/TransactionsApiTest.php +++ b/test/Api/TransactionsApiTest.php @@ -201,4 +201,29 @@ public function testRefundTransaction() $this->fail("Exception thrown: " . $e->getMessage()); } } + + /** + * Test case for voidTransaction + * + * Void transaction. + * + */ + public function testVoidTransaction() + { + + try { + $config = new Gr4vyConfig(self::$gr4vyId, self::$privateKeyLocation); + $transaction_request = array("amount"=>100,"currency"=>"USD", "intent"=>"authorize", "payment_method"=>array("method"=>"card", "number"=>"4111111111111111", "expiration_date"=> "01/28", "security_code"=>"555")); + $result = $config->authorizeNewTransaction($transaction_request); + $this->assertArrayHasKey("id", $result); + $this->assertEquals($result["type"], "transaction"); + + $result = $config->voidTransaction($result["id"]); + $this->assertArrayHasKey("id", $result); + $this->assertEquals($result["status"], "authorization_voided"); + // print_r($result); + } catch (Exception $e) { + $this->fail("Exception thrown: " . $e->getMessage()); + } + } }