From 022d6a66c8d8c65d05305db6a641225856236969 Mon Sep 17 00:00:00 2001 From: nafezly Date: Wed, 8 Mar 2023 03:43:53 +0200 Subject: [PATCH] updates --- src/Classes/TapPayment.php | 2 ++ src/Traits/SetRequiredFields.php | 18 +++++++++--------- src/Traits/SetVariables.php | 14 +++++++------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/Classes/TapPayment.php b/src/Classes/TapPayment.php index 34d32cc..7949148 100644 --- a/src/Classes/TapPayment.php +++ b/src/Classes/TapPayment.php @@ -43,7 +43,9 @@ public function __construct() public function pay($amount = null, $user_id = null, $user_first_name = null, $user_last_name = null, $user_email = null, $user_phone = null, $source = null) { $this->setPassedVariablesToGlobal($amount,$user_id,$user_first_name,$user_last_name,$user_email,$user_phone,$source); + $required_fields = ['amount', 'user_first_name', 'user_last_name', 'user_email', 'user_phone']; + $this->checkRequiredFields($required_fields, 'Tap', func_get_args()); $unique_id = uniqid(); diff --git a/src/Traits/SetRequiredFields.php b/src/Traits/SetRequiredFields.php index 1f3617b..670edd1 100644 --- a/src/Traits/SetRequiredFields.php +++ b/src/Traits/SetRequiredFields.php @@ -10,18 +10,18 @@ trait SetRequiredFields * * @param array $required_fields * @param string $gatway_name - * @param array $arguments * @return void */ - public function checkRequiredFields($required_fields, $gatway_name, $arguments) + public function checkRequiredFields($required_fields, $gatway_name) { - $amount = $arguments[0] ?? null; - $user_id = $arguments[1] ?? null; - $user_first_name = $arguments[2] ?? null; - $user_last_name = $arguments[3] ?? null; - $user_email = $arguments[4] ?? null; - $user_phone = $arguments[5] ?? null; - $source = $arguments[6] ?? null; + + $amount = $this->amount ?? null; + $user_id = $this->user_id ?? null; + $user_first_name = $this->user_first_name ?? null; + $user_last_name = $this->user_last_name ?? null; + $user_email = $this->user_email ?? null; + $user_phone = $this->user_phone ?? null; + $source = $this->source ?? null; foreach($required_fields as $field){ $this->{$field} = $this->{$field} ?? ${$field}; if (is_null($this->{$field})) throw new MissingPaymentInfoException($field, $gatway_name); diff --git a/src/Traits/SetVariables.php b/src/Traits/SetVariables.php index 7d85ded..53f9cb7 100644 --- a/src/Traits/SetVariables.php +++ b/src/Traits/SetVariables.php @@ -122,13 +122,13 @@ public function setAmount($value) */ public function setPassedVariablesToGlobal($amount = null, $user_id = null, $user_first_name = null, $user_last_name = null, $user_email = null, $user_phone = null, $source = null) { - $this->setAmount($amount); - $this->setUserId($user_id); - $this->setUserFirstName($user_first_name); - $this->setUserLastName($user_last_name); - $this->setUserEmail($user_email); - $this->setUserPhone($user_phone); - $this->setSource($source); + if($amount!=null)$this->setAmount($amount); + if($user_id!=null)$this->setUserId($user_id); + if($user_first_name!=null)$this->setUserFirstName($user_first_name); + if($user_last_name!=null)$this->setUserLastName($user_last_name); + if($user_email!=null)$this->setUserEmail($user_email); + if($user_phone!=null)$this->setUserPhone($user_phone); + if($source!=null)$this->setSource($source); }