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 diff --git a/src/Transaction.php b/src/Transaction.php index 8f4cb4c..bc2fd66 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( $metadata ) + { + $this->metadata = $metadata; + + return $this; + } + + }