Skip to content

Commit

Permalink
Refactor the refund codes
Browse files Browse the repository at this point in the history
  • Loading branch information
seunex17 committed Nov 11, 2023
1 parent 2fd6a32 commit 34e8a3b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,13 @@ In the redrected page (method) add this below code to verify you payment.
### Refund a transaction

Whenever your customer pay you, it is advisable to store the transaction information return by flutterwave.
To create a refund we needed the amount paid and flutterwave references (flw_ref).
To create a refund we needed the amount paid and transaction id (transaction_id).

```php
$flutterwaveRef = "FLW-MOCK-a728cc7f95ecff4bc92388a2f1f69cc3";
$transactionId = "4717164";
$amount = 500;

Transaction::refund($flutterwaveRef, $amount);
Transaction::refund($transactionId, $amount);
```

<a id="contribution-guidelines"></a>
Expand Down
6 changes: 3 additions & 3 deletions src/Flutterwave/Transaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class Transaction
/**
* @throws \Exception
*/
public static function refund(string $references, int $amount)
public static function refund(string $transactionId, int $amount)
{
$flutterwave = new Flutterwave();
$client = Services::curlrequest();

$request = $client->request('POST', "{$flutterwave->baseUrl}/charges/{$references}/refund", [
$request = $client->request('POST', "{$flutterwave->baseUrl}/transactions/{$transactionId}/refund", [
'headers' => [
'Authorization' => 'Bearer ' . env('FLUTTERWAVE_SECRET_KEY'),
],
Expand All @@ -41,7 +41,7 @@ public static function refund(string $references, int $amount)
$response = json_decode($request->getBody());

if ($request->getStatusCode() !== 200) {
throw new Exception($response->message);
throw new Exception($response->data);
}

return $response;
Expand Down

0 comments on commit 34e8a3b

Please sign in to comment.