Skip to content

Commit 0cef7df

Browse files
authored
add void transaction (#24)
1 parent a896f01 commit 0cef7df

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

lib/Gr4vyConfig.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public static function getToken($private_key, $scopes = array(), $embed = array(
119119
$now = new DateTimeImmutable();
120120
$tokenBuilder = $config->builder()
121121
// Configures the issuer (iss claim)
122-
->issuedBy('Gr4vy SDK 0.20.0')
122+
->issuedBy('Gr4vy SDK 0.21.0')
123123
// Configures the id (jti claim)
124124
->identifiedBy(self::gen_uuid())
125125
// Configures the time that the token was issue (iat claim)
@@ -415,6 +415,10 @@ public function refundTransaction($transaction_id, $refund_request) {
415415
$response = $this->post("/transactions/" . $transaction_id . "/refunds", $refund_request);
416416
return $response;
417417
}
418+
public function voidTransaction($transaction_id, $request = array()) {
419+
$response = $this->post("/transactions/" . $transaction_id . "/void", $request);
420+
return $response;
421+
}
418422
public function newCheckoutSession($request = array()) {
419423
$response = $this->post("/checkout/sessions", $request);
420424
return $response;

test/Api/TransactionsApiTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,4 +201,29 @@ public function testRefundTransaction()
201201
$this->fail("Exception thrown: " . $e->getMessage());
202202
}
203203
}
204+
205+
/**
206+
* Test case for voidTransaction
207+
*
208+
* Void transaction.
209+
*
210+
*/
211+
public function testVoidTransaction()
212+
{
213+
214+
try {
215+
$config = new Gr4vyConfig(self::$gr4vyId, self::$privateKeyLocation);
216+
$transaction_request = array("amount"=>100,"currency"=>"USD", "intent"=>"authorize", "payment_method"=>array("method"=>"card", "number"=>"4111111111111111", "expiration_date"=> "01/28", "security_code"=>"555"));
217+
$result = $config->authorizeNewTransaction($transaction_request);
218+
$this->assertArrayHasKey("id", $result);
219+
$this->assertEquals($result["type"], "transaction");
220+
221+
$result = $config->voidTransaction($result["id"]);
222+
$this->assertArrayHasKey("id", $result);
223+
$this->assertEquals($result["status"], "authorization_voided");
224+
// print_r($result);
225+
} catch (Exception $e) {
226+
$this->fail("Exception thrown: " . $e->getMessage());
227+
}
228+
}
204229
}

0 commit comments

Comments
 (0)