Skip to content

Commit

Permalink
add void transaction (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-gr4vy authored Nov 28, 2023
1 parent a896f01 commit 0cef7df
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/Gr4vyConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down
25 changes: 25 additions & 0 deletions test/Api/TransactionsApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
}

0 comments on commit 0cef7df

Please sign in to comment.