From 96257475bc1706b23a8497fb64a4b4d0b8af5b1e Mon Sep 17 00:00:00 2001 From: Gloria Chen Date: Wed, 25 Mar 2026 10:29:33 +1100 Subject: [PATCH 1/2] Add refund_standalone function with tests - Implements standalone refund functionality without requiring original transaction ID - Supports refunding to a card token directly - Includes comprehensive validation for all parameters - Adds 3 test cases covering valid refunds, invalid tokens, and extra parameters - Follows existing code patterns and documentation standards --- src/Gateway.php | 30 ++++++++++++++++++++++++++++++ test/GatewayTest.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/src/Gateway.php b/src/Gateway.php index 994b0b2..df5ee2a 100644 --- a/src/Gateway.php +++ b/src/Gateway.php @@ -363,6 +363,36 @@ public function refund($transaction_id, $amount, $reference, $extra = null) return $this->do_request("POST", "/refunds", $payload); } + /** + * Performs a standalone refund against the FatZebra gateway without an original transaction + * @param float $amount the amount to be refunded + * @param string $reference the refund reference + * @param string $card_token the card token to refund to + * @param array $extra an assoc. array of extra params to merge into the request (e.g. metadata, fraud etc) + * @return \StdObject + */ + public function refund_standalone($amount, $reference, $card_token, $extra = null) + { + if (is_null($amount) || strlen($amount) === 0) throw new \InvalidArgumentException("Amount is required"); + if (intval($amount) < 1) throw new \InvalidArgumentException("Amount is invalid - must be a positive value"); + if (is_null($reference) || strlen($reference) === 0) throw new \InvalidArgumentException("Reference is required"); + if (is_null($card_token) || strlen($card_token) === 0) throw new \InvalidArgumentException("Card token is required"); + + $int_amount = self::floatToInt($amount); + + $payload = array( + "amount" => $int_amount, + "reference" => $reference, + "card_token" => $card_token + ); + + if (is_array($extra)) { + $payload = array_merge_recursive($payload, $extra); + } + + return $this->do_request("POST", "/refunds", $payload); + } + /** * Retrieves a purchase from the FatZebra gateway * @param string $reference the purchase ID diff --git a/test/GatewayTest.php b/test/GatewayTest.php index dfad8af..fa683f4 100644 --- a/test/GatewayTest.php +++ b/test/GatewayTest.php @@ -331,4 +331,47 @@ public function test_create_customer() $this->assertTrue($result->successful); $this->assertNotNull($result->response->id); } + + /** + * Test a standalone refund with a valid card token (mocked) + */ + public function test_refund_standalone() + { + $stubbed_response = '{"successful":true,"response":{"id":"refund123","successful":true,"message":"Refund processed"},"errors":[],"test":true}'; + $stub = $this->createMock(FatZebra\Gateway::class); + $stub->method('refund_standalone')->willReturn(json_decode($stubbed_response)); + $result = $stub->refund_standalone(50.00, "UNITTEST" . rand(), "TOK123"); + + $this->assertTrue($result->successful); + $this->assertTrue($result->response->successful); + $this->assertEquals($result->response->message, "Refund processed"); + } + + /** + * Test standalone refund with an invalid card token + */ + public function test_refund_standalone_invalid_token() + { + $gw = new FatZebra\Gateway("TEST", "TEST", true, GW_URL); + $gw->timeout = 30; + + $result = $gw->refund_standalone(50.00, "UNITTEST" . rand(), "INVALID_TOKEN"); + + $this->assertFalse($result->successful); + } + + /** + * Test standalone refund with extra parameters (mocked) + */ + public function test_refund_standalone_with_extra() + { + $stubbed_response = '{"successful":true,"response":{"id":"refund456","successful":true,"message":"Refund processed"},"errors":[],"test":true}'; + $stub = $this->createMock(FatZebra\Gateway::class); + $stub->method('refund_standalone')->willReturn(json_decode($stubbed_response)); + $extra = array("metadata" => "test_metadata"); + $result = $stub->refund_standalone(50.00, "UNITTEST" . rand(), "TOK123", $extra); + + $this->assertTrue($result->successful); + $this->assertTrue($result->response->successful); + } } From c0777b3696e4595ef0705b4dce6745fbab484736 Mon Sep 17 00:00:00 2001 From: Gloria Chen Date: Wed, 25 Mar 2026 10:43:03 +1100 Subject: [PATCH 2/2] Updated composer and README --- README.markdown | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.markdown b/README.markdown index 6b7b84c..cae60b1 100644 --- a/README.markdown +++ b/README.markdown @@ -1,7 +1,7 @@ PHP API Library for Fat Zebra ============================== -Release 1.2.3 for API version 1.0 +Release 1.2.4 for API version 1.0 A PHP library for the [Fat Zebra](https://www.fatzebra.com.au) Online Payment Gateway (for Australian Merchants) Now supports recurring billing (subscriptions, plans, customers) diff --git a/composer.json b/composer.json index 55cf597..046e845 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,6 @@ { "name": "fatzebra/fatzebra-php", - "version": "1.2.3", + "version": "1.2.4", "repositories": [ { "type": "vcs",