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); }