diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 8321961048ad..83a1ced0c5fd 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -11,34 +11,39 @@ namespace App\PaymentDrivers; -use App\Events\Invoice\InvoiceWasPaid; -use App\Events\Payment\PaymentWasCreated; -use App\Exceptions\PaymentFailed; -use App\Factory\PaymentFactory; -use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use App\Jobs\Mail\NinjaMailer; -use App\Jobs\Mail\NinjaMailerJob; -use App\Jobs\Mail\NinjaMailerObject; -use App\Jobs\Mail\PaymentFailedMailer; -use App\Jobs\Util\SystemLogger; -use App\Mail\Admin\ClientPaymentFailureObject; +use Exception; +use App\Utils\Ninja; use App\Models\Client; -use App\Models\ClientContact; -use App\Models\ClientGatewayToken; -use App\Models\CompanyGateway; -use App\Models\GatewayType; +use App\Utils\Helpers; use App\Models\Invoice; use App\Models\Payment; -use App\Models\PaymentHash; use App\Models\SystemLog; -use App\Services\Subscription\SubscriptionService; -use App\Utils\Helpers; -use App\Utils\Ninja; -use App\Utils\Traits\MakesHash; -use App\Utils\Traits\SystemLogTrait; -use Illuminate\Http\Request; -use Illuminate\Support\Carbon; +use App\Models\GatewayType; +use App\Models\PaymentHash; +use App\Models\PaymentType; use Illuminate\Support\Str; +use Illuminate\Http\Request; +use App\Models\ClientContact; +use App\Jobs\Mail\NinjaMailer; +use App\Models\CompanyGateway; +use Illuminate\Support\Carbon; +use App\Factory\PaymentFactory; +use App\Jobs\Util\SystemLogger; +use App\Utils\Traits\MakesHash; +use App\Models\TransactionEvent; +use App\Exceptions\PaymentFailed; +use App\Jobs\Mail\NinjaMailerJob; +use App\Jobs\Ninja\TransactionLog; +use App\Models\ClientGatewayToken; +use App\Jobs\Mail\NinjaMailerObject; +use App\Utils\Traits\SystemLogTrait; +use App\Events\Invoice\InvoiceWasPaid; +use App\Jobs\Mail\PaymentFailedMailer; +use App\Events\Payment\PaymentWasCreated; +use App\Mail\Admin\ClientPaymentFailureObject; +use App\Services\Subscription\SubscriptionService; +use Checkout\Library\Exceptions\CheckoutHttpException; +use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; /** * Class BaseDriver. @@ -54,6 +59,10 @@ class BaseDriver extends AbstractPaymentDriver /* The Invitation */ public $invitation; + + /* The client */ + public $client; + /* Gateway capabilities */ public $refundable = false; @@ -63,15 +72,17 @@ class BaseDriver extends AbstractPaymentDriver /* Authorise payment methods */ public $can_authorise_credit_card = false; - /* The client */ - public $client; - /* The initialized gateway driver class*/ public $payment_method; - /* PaymentHash */ + /** + * @var PaymentHash + */ public $payment_hash; + /** + * @var Helpers` + */ public $helpers; /* Array of payment methods */ @@ -80,7 +91,7 @@ class BaseDriver extends AbstractPaymentDriver /** @var array */ public $required_fields = []; - public function __construct(CompanyGateway $company_gateway, Client $client = null, $invitation = false) + public function __construct(CompanyGateway $company_gateway, ?Client $client = null, $invitation = false) { $this->company_gateway = $company_gateway; $this->invitation = $invitation; @@ -88,12 +99,6 @@ class BaseDriver extends AbstractPaymentDriver $this->helpers = new Helpers(); } - /** - * Required fields for client to fill, to proceed with gateway actions. - * - * @return array[] - */ - public function init() { return $this; @@ -104,6 +109,11 @@ class BaseDriver extends AbstractPaymentDriver return $this; } + /** + * Required fields for client to fill, to proceed with gateway actions. + * + * @return array[] + */ public function getClientRequiredFields(): array { $fields = []; @@ -145,24 +155,33 @@ class BaseDriver extends AbstractPaymentDriver } if ($this->company_gateway->require_custom_value1) { + $fields[] = ['name' => 'client_custom_value1', 'label' => $this->helpers->makeCustomField($this->client->company->custom_fields, 'client1'), 'type' => 'text', 'validation' => 'required']; + } if ($this->company_gateway->require_custom_value2) { + $fields[] = ['name' => 'client_custom_value2', 'label' => $this->helpers->makeCustomField($this->client->company->custom_fields, 'client2'), 'type' => 'text', 'validation' => 'required']; + } if ($this->company_gateway->require_custom_value3) { + $fields[] = ['name' => 'client_custom_value3', 'label' => $this->helpers->makeCustomField($this->client->company->custom_fields, 'client3'), 'type' => 'text', 'validation' => 'required']; + } if ($this->company_gateway->require_custom_value4) { + $fields[] = ['name' => 'client_custom_value4', 'label' => $this->helpers->makeCustomField($this->client->company->custom_fields, 'client4'), 'type' => 'text', 'validation' => 'required']; + } return $fields; + } /** @@ -355,11 +374,11 @@ class BaseDriver extends AbstractPaymentDriver event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); if (property_exists($this->payment_hash->data, 'billing_context') && $status == Payment::STATUS_COMPLETED) { - if (is_int($this->payment_hash->data->billing_context->subscription_id)) { + + if(is_int($this->payment_hash->data->billing_context->subscription_id)) $billing_subscription = \App\Models\Subscription::find($this->payment_hash->data->billing_context->subscription_id); - } else { + else $billing_subscription = \App\Models\Subscription::find($this->decodePrimaryKey($this->payment_hash->data->billing_context->subscription_id)); - } // To access campaign hash => $this->payment_hash->data->billing_context->campaign; // To access campaign data => Cache::get(CAMPAIGN_HASH) @@ -380,6 +399,7 @@ class BaseDriver extends AbstractPaymentDriver */ public function confirmGatewayFee() :void { + /*Payment invoices*/ $payment_invoices = $this->payment_hash->invoices(); @@ -393,6 +413,7 @@ class BaseDriver extends AbstractPaymentDriver if (collect($invoice->line_items)->contains('type_id', '3')) { $invoice->service()->toggleFeesPaid()->save(); } + }); } @@ -490,7 +511,7 @@ class BaseDriver extends AbstractPaymentDriver public function sendFailureMail($error) { - if (is_object($error)) { + if(is_object($error)){ $error = 'Payment Aborted'; }