From 1193661dab059ff0a82c53f22996a1ca1fed3148 Mon Sep 17 00:00:00 2001 From: Amir Mehrabian Date: Thu, 25 Jul 2024 01:32:17 +0330 Subject: [PATCH 1/3] Add ability to process metadata in the requests --- src/Transaction.php | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/Transaction.php b/src/Transaction.php index 8f4cb4c..569377f 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -22,6 +22,7 @@ class Transaction extends Base $amount = 0, $email = null, $reference = null, + $metadata = null, $transactionResponse = [ 'verify' => null, @@ -82,6 +83,12 @@ public function initialize( array $data = [], $rawResponse = false ) $this->email = $data['email']; } + + // add metadata if provided + if ( ! is_null( $this->metadata ) ) { + $data['metadata'] = $this->metadata; + } + $this->transactionResponse['initialize'] = $this ->setAction( 'initialize' ) @@ -284,4 +291,19 @@ public function setCallbackUrl( $callbackUrl ) return $this; } - } \ No newline at end of file + + /** + * Sets the metadata + * + * @param array $metadata + * + * @return $this + */ + public function setMetadata( array $metadata ) + { + $this->metadata = $metadata; + + return $this; + } + + } From d04bf1ce323f63ad62b15b810d7f9c90888ed417 Mon Sep 17 00:00:00 2001 From: Amir Mehrabian Date: Thu, 25 Jul 2024 01:36:02 +0330 Subject: [PATCH 2/3] Update README.md to reflect the changes regarding setting metadata --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2ac3ba8..0ca5042 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,7 @@ $response = ->setCallbackUrl('http://michaelakanji.com') // to override/set callback_url, it can also be set on your dashboard ->setEmail( 'matscode@gmail.com' ) ->setAmount( 75000 ) // amount is treated in Naira while using this method + ->setMetadata(['custom_field1' => 'value1', 'custom_field2' => 'value2']) ->initialize(); ``` If you want to get the 200OK raw Object as it is sent by Paystack, Set the 2nd argument of the `initialize()` to `true`, example below From 656871c2c30a441d4c55a6c08a439e2b0a54cd73 Mon Sep 17 00:00:00 2001 From: Amir Mehrabian Date: Thu, 25 Jul 2024 12:35:49 +0330 Subject: [PATCH 3/3] Removing the type from method input --- src/Transaction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Transaction.php b/src/Transaction.php index 569377f..bc2fd66 100644 --- a/src/Transaction.php +++ b/src/Transaction.php @@ -299,7 +299,7 @@ public function setCallbackUrl( $callbackUrl ) * * @return $this */ - public function setMetadata( array $metadata ) + public function setMetadata( $metadata ) { $this->metadata = $metadata;