2020-06-09 13:17:26 +02:00
|
|
|
<?php
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-06-09 13:17:26 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-06-09 13:17:26 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-06-09 13:17:26 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\PaymentDrivers;
|
|
|
|
|
2023-02-23 01:14:14 +01:00
|
|
|
use App\Utils\Ninja;
|
|
|
|
use App\Utils\Number;
|
2023-02-17 22:36:51 +01:00
|
|
|
use App\Models\Client;
|
2023-02-23 01:14:14 +01:00
|
|
|
use App\Utils\Helpers;
|
2023-02-17 22:36:51 +01:00
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\SystemLog;
|
2023-02-23 01:14:14 +01:00
|
|
|
use App\Models\GatewayType;
|
|
|
|
use App\Models\PaymentHash;
|
|
|
|
use Illuminate\Support\Str;
|
2023-02-17 22:36:51 +01:00
|
|
|
use Illuminate\Http\Request;
|
2023-02-23 01:14:14 +01:00
|
|
|
use App\Models\ClientContact;
|
|
|
|
use App\Jobs\Mail\NinjaMailer;
|
|
|
|
use App\Models\CompanyGateway;
|
2023-02-17 22:36:51 +01:00
|
|
|
use Illuminate\Support\Carbon;
|
2023-02-23 01:14:14 +01:00
|
|
|
use App\Factory\PaymentFactory;
|
|
|
|
use App\Jobs\Util\SystemLogger;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use App\Exceptions\PaymentFailed;
|
|
|
|
use App\Jobs\Mail\NinjaMailerJob;
|
|
|
|
use App\Models\ClientGatewayToken;
|
2023-03-01 00:54:56 +01:00
|
|
|
use Illuminate\Support\Facades\App;
|
2023-02-23 01:14:14 +01:00
|
|
|
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 App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
2020-06-09 13:17:26 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Class BaseDriver.
|
2020-06-09 13:17:26 +02:00
|
|
|
*/
|
2020-06-09 14:54:22 +02:00
|
|
|
class BaseDriver extends AbstractPaymentDriver
|
2020-06-09 13:17:26 +02:00
|
|
|
{
|
|
|
|
use SystemLogTrait;
|
|
|
|
use MakesHash;
|
|
|
|
|
|
|
|
/* The company gateway instance*/
|
|
|
|
public $company_gateway;
|
|
|
|
|
|
|
|
/* The Invitation */
|
2020-06-15 13:42:46 +02:00
|
|
|
public $invitation;
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2023-02-17 10:33:47 +01:00
|
|
|
/* The client */
|
|
|
|
public $client;
|
|
|
|
|
2020-06-09 13:17:26 +02:00
|
|
|
/* Gateway capabilities */
|
2020-06-15 13:42:46 +02:00
|
|
|
public $refundable = false;
|
2020-06-09 13:17:26 +02:00
|
|
|
|
|
|
|
/* Token billing */
|
2020-06-15 13:42:46 +02:00
|
|
|
public $token_billing = false;
|
2020-06-09 13:17:26 +02:00
|
|
|
|
|
|
|
/* Authorise payment methods */
|
2020-06-15 13:42:46 +02:00
|
|
|
public $can_authorise_credit_card = false;
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2020-11-25 22:07:09 +01:00
|
|
|
/* The initialized gateway driver class*/
|
2020-06-15 13:42:46 +02:00
|
|
|
public $payment_method;
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2023-02-17 10:33:47 +01:00
|
|
|
/**
|
|
|
|
* @var PaymentHash
|
|
|
|
*/
|
2021-11-07 10:31:03 +01:00
|
|
|
public $payment_hash;
|
2020-10-27 12:53:35 +01:00
|
|
|
|
2023-02-17 10:33:47 +01:00
|
|
|
/**
|
|
|
|
* @var Helpers`
|
|
|
|
*/
|
2023-02-02 08:19:37 +01:00
|
|
|
public $helpers;
|
|
|
|
|
2020-11-25 22:07:09 +01:00
|
|
|
/* Array of payment methods */
|
2020-06-16 05:49:45 +02:00
|
|
|
public static $methods = [];
|
2021-01-13 13:31:00 +01:00
|
|
|
|
2020-11-25 14:38:49 +01:00
|
|
|
/** @var array */
|
|
|
|
public $required_fields = [];
|
2020-06-16 02:21:40 +02:00
|
|
|
|
2023-02-17 11:05:01 +01:00
|
|
|
public function __construct(CompanyGateway $company_gateway, ?Client $client = null, $invitation = null)
|
2020-06-09 13:17:26 +02:00
|
|
|
{
|
|
|
|
$this->company_gateway = $company_gateway;
|
|
|
|
$this->invitation = $invitation;
|
|
|
|
$this->client = $client;
|
2023-02-02 08:19:37 +01:00
|
|
|
$this->helpers = new Helpers();
|
2020-06-09 13:17:26 +02:00
|
|
|
}
|
|
|
|
|
2023-02-14 21:41:21 +01:00
|
|
|
public function init()
|
|
|
|
{
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function updateCustomer()
|
|
|
|
{
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2023-02-17 10:33:47 +01:00
|
|
|
/**
|
|
|
|
* Required fields for client to fill, to proceed with gateway actions.
|
|
|
|
*
|
|
|
|
* @return array[]
|
|
|
|
*/
|
2021-01-13 13:31:00 +01:00
|
|
|
public function getClientRequiredFields(): array
|
|
|
|
{
|
2023-02-02 08:19:37 +01:00
|
|
|
$fields = [];
|
|
|
|
|
|
|
|
if ($this->company_gateway->require_client_name) {
|
|
|
|
$fields[] = ['name' => 'client_name', 'label' => ctrans('texts.client_name'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->company_gateway->require_contact_name) {
|
|
|
|
$fields[] = ['name' => 'contact_first_name', 'label' => ctrans('texts.first_name'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
$fields[] = ['name' => 'contact_last_name', 'label' => ctrans('texts.last_name'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->company_gateway->require_contact_email) {
|
|
|
|
$fields[] = ['name' => 'contact_email', 'label' => ctrans('texts.email'), 'type' => 'text', 'validation' => 'required,email:rfc'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->company_gateway->require_client_phone) {
|
|
|
|
$fields[] = ['name' => 'client_phone', 'label' => ctrans('texts.client_phone'), 'type' => 'tel', 'validation' => 'required'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->company_gateway->require_billing_address) {
|
|
|
|
$fields[] = ['name' => 'client_address_line_1', 'label' => ctrans('texts.address1'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
$fields[] = ['name' => 'client_city', 'label' => ctrans('texts.city'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
$fields[] = ['name' => 'client_state', 'label' => ctrans('texts.state'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
$fields[] = ['name' => 'client_country_id', 'label' => ctrans('texts.country'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->company_gateway->require_postal_code) {
|
|
|
|
$fields[] = ['name' => 'client_postal_code', 'label' => ctrans('texts.postal_code'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->company_gateway->require_shipping_address) {
|
|
|
|
$fields[] = ['name' => 'client_shipping_address_line_1', 'label' => ctrans('texts.shipping_address1'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
$fields[] = ['name' => 'client_shipping_city', 'label' => ctrans('texts.shipping_city'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
$fields[] = ['name' => 'client_shipping_state', 'label' => ctrans('texts.shipping_state'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
$fields[] = ['name' => 'client_shipping_postal_code', 'label' => ctrans('texts.shipping_postal_code'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
$fields[] = ['name' => 'client_shipping_country_id', 'label' => ctrans('texts.shipping_country'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
2021-01-13 13:31:00 +01:00
|
|
|
}
|
|
|
|
|
2020-06-12 02:19:26 +02:00
|
|
|
/**
|
|
|
|
* Authorize a payment method.
|
|
|
|
*
|
|
|
|
* Returns a reusable token for storage for future payments
|
2020-11-27 12:08:42 +01:00
|
|
|
*
|
2020-11-25 22:07:09 +01:00
|
|
|
* @param array $data
|
|
|
|
* @return mixed Return a view for collecting payment method information
|
2020-06-12 02:19:26 +02:00
|
|
|
*/
|
2020-11-27 12:08:42 +01:00
|
|
|
public function authorizeView(array $data)
|
|
|
|
{
|
|
|
|
}
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-06-12 02:19:26 +02:00
|
|
|
/**
|
2020-11-25 22:07:09 +01:00
|
|
|
* The payment authorization response
|
2020-11-27 12:08:42 +01:00
|
|
|
*
|
|
|
|
* @param Request $request
|
2020-11-25 22:07:09 +01:00
|
|
|
* @return mixed Return a response for collecting payment method information
|
2020-06-12 02:19:26 +02:00
|
|
|
*/
|
2020-11-27 12:08:42 +01:00
|
|
|
public function authorizeResponse(Request $request)
|
|
|
|
{
|
|
|
|
}
|
2020-11-25 22:07:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process a payment
|
2020-11-27 12:08:42 +01:00
|
|
|
*
|
|
|
|
* @param array $data
|
2020-11-25 22:07:09 +01:00
|
|
|
* @return mixed Return a view for the payment
|
|
|
|
*/
|
2020-11-27 12:08:42 +01:00
|
|
|
public function processPaymentView(array $data)
|
|
|
|
{
|
|
|
|
}
|
2020-11-25 22:07:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process payment response
|
2020-11-27 12:08:42 +01:00
|
|
|
*
|
2020-11-25 22:07:09 +01:00
|
|
|
* @param Request $request
|
|
|
|
* @return mixed Return a response for the payment
|
|
|
|
*/
|
2020-11-27 12:08:42 +01:00
|
|
|
public function processPaymentResponse(Request $request)
|
|
|
|
{
|
|
|
|
}
|
2020-06-12 02:19:26 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Executes a refund attempt for a given amount with a transaction_reference.
|
|
|
|
*
|
2020-06-24 03:15:51 +02:00
|
|
|
* @param Payment $payment The Payment Object
|
2020-06-12 02:19:26 +02:00
|
|
|
* @param float $amount The amount to be refunded
|
2020-10-12 06:10:34 +02:00
|
|
|
* @param bool $return_client_response Whether the method needs to return a response (otherwise we assume an unattended payment)
|
2020-09-06 11:38:10 +02:00
|
|
|
* @return mixed
|
2020-06-12 02:19:26 +02:00
|
|
|
*/
|
2020-11-27 12:08:42 +01:00
|
|
|
public function refund(Payment $payment, $amount, $return_client_response = false)
|
|
|
|
{
|
|
|
|
}
|
2020-11-25 22:07:09 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Process an unattended payment.
|
|
|
|
*
|
|
|
|
* @param ClientGatewayToken $cgt The client gateway token object
|
|
|
|
* @param PaymentHash $payment_hash The Payment hash containing the payment meta data
|
|
|
|
* @return void The payment response
|
|
|
|
*/
|
2020-11-27 12:08:42 +01:00
|
|
|
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
|
|
|
|
{
|
|
|
|
}
|
2020-06-09 13:17:26 +02:00
|
|
|
|
2021-06-20 12:24:11 +02:00
|
|
|
/**
|
|
|
|
* Detaches a payment method from the gateway
|
2022-06-21 11:57:17 +02:00
|
|
|
*
|
2021-06-20 12:24:11 +02:00
|
|
|
* @param ClientGatewayToken $token The gateway token
|
|
|
|
* @return bool boolean response
|
|
|
|
*/
|
|
|
|
public function detach(ClientGatewayToken $token)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-06-15 13:42:46 +02:00
|
|
|
/**
|
|
|
|
* Set the inbound request payment method type for access.
|
2020-09-06 11:38:10 +02:00
|
|
|
*
|
2020-06-15 13:42:46 +02:00
|
|
|
* @param int $payment_method_id The Payment Method ID
|
|
|
|
*/
|
2020-11-27 12:08:42 +01:00
|
|
|
public function setPaymentMethod($payment_method_id)
|
|
|
|
{
|
|
|
|
}
|
2020-11-25 22:07:09 +01:00
|
|
|
|
2022-02-15 05:58:37 +01:00
|
|
|
public function setClient(Client $client)
|
|
|
|
{
|
|
|
|
$this->client = $client;
|
|
|
|
}
|
2020-11-25 22:07:09 +01:00
|
|
|
/************************** Helper methods *************************************/
|
2020-06-16 02:21:40 +02:00
|
|
|
|
2020-10-27 12:53:35 +01:00
|
|
|
public function setPaymentHash(PaymentHash $payment_hash)
|
|
|
|
{
|
|
|
|
$this->payment_hash = $payment_hash;
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2020-10-27 12:53:35 +01:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2020-06-16 15:31:08 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Helper method to attach invoices to a payment.
|
|
|
|
*
|
2020-10-28 11:10:49 +01:00
|
|
|
* @param Payment $payment The payment
|
|
|
|
* @param PaymentHash $payment_hash
|
2020-06-16 15:31:08 +02:00
|
|
|
* @return Payment The payment object
|
|
|
|
*/
|
2020-09-01 01:28:37 +02:00
|
|
|
public function attachInvoices(Payment $payment, PaymentHash $payment_hash): Payment
|
2020-06-16 15:31:08 +02:00
|
|
|
{
|
2020-09-01 01:28:37 +02:00
|
|
|
$paid_invoices = $payment_hash->invoices();
|
2021-06-20 00:14:56 +02:00
|
|
|
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($paid_invoices, 'invoice_id')))->withTrashed()->get();
|
2020-06-16 15:31:08 +02:00
|
|
|
$payment->invoices()->sync($invoices);
|
2020-08-12 00:17:32 +02:00
|
|
|
|
2021-12-17 12:11:36 +01:00
|
|
|
$payment->service()->applyNumber()->save();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$invoices->each(function ($invoice) use ($payment) {
|
2021-01-24 21:55:04 +01:00
|
|
|
event(new InvoiceWasPaid($invoice, $payment, $payment->company, Ninja::eventVars()));
|
2020-08-12 04:02:21 +02:00
|
|
|
});
|
|
|
|
|
2021-12-17 12:11:36 +01:00
|
|
|
return $payment;
|
2020-06-16 15:31:08 +02:00
|
|
|
}
|
2020-07-08 04:20:44 +02:00
|
|
|
|
2020-08-17 00:58:52 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Create a payment from an online payment.
|
|
|
|
*
|
2020-08-17 00:58:52 +02:00
|
|
|
* @param array $data Payment data
|
|
|
|
* @param int $status The payment status_id
|
|
|
|
* @return Payment The payment object
|
|
|
|
*/
|
|
|
|
public function createPayment($data, $status = Payment::STATUS_COMPLETED): Payment
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
if (in_array($status, [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING])) {
|
2022-01-15 12:08:48 +01:00
|
|
|
$this->confirmGatewayFee();
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-03-17 16:12:25 +01:00
|
|
|
|
2021-10-24 06:14:36 +02:00
|
|
|
/*Never create a payment with a duplicate transaction reference*/
|
2022-06-21 11:57:17 +02:00
|
|
|
if (array_key_exists('transaction_reference', $data)) {
|
2021-10-24 06:14:36 +02:00
|
|
|
$_payment = Payment::where('transaction_reference', $data['transaction_reference'])
|
|
|
|
->where('client_id', $this->client->id)
|
2021-11-29 11:59:48 +01:00
|
|
|
->first();
|
2021-10-24 06:14:36 +02:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($_payment) {
|
|
|
|
return $_payment;
|
|
|
|
}
|
2021-10-24 06:14:36 +02:00
|
|
|
}
|
|
|
|
|
2020-08-17 00:58:52 +02:00
|
|
|
$payment = PaymentFactory::create($this->client->company->id, $this->client->user->id);
|
|
|
|
$payment->client_id = $this->client->id;
|
|
|
|
$payment->company_gateway_id = $this->company_gateway->id;
|
|
|
|
$payment->status_id = $status;
|
|
|
|
$payment->currency_id = $this->client->getSetting('currency_id');
|
|
|
|
$payment->date = Carbon::now();
|
2021-01-28 05:21:04 +01:00
|
|
|
$payment->gateway_type_id = $data['gateway_type_id'];
|
2021-01-27 11:38:28 +01:00
|
|
|
|
2020-10-25 18:51:26 +01:00
|
|
|
$client_contact = $this->getContact();
|
|
|
|
$client_contact_id = $client_contact ? $client_contact->id : null;
|
|
|
|
|
|
|
|
$payment->amount = $data['amount'];
|
|
|
|
$payment->type_id = $data['payment_type'];
|
2020-11-01 15:56:17 +01:00
|
|
|
$payment->transaction_reference = $data['transaction_reference'];
|
2020-10-25 18:51:26 +01:00
|
|
|
$payment->client_contact_id = $client_contact_id;
|
2021-10-15 09:47:41 +02:00
|
|
|
$payment->saveQuietly();
|
2020-10-25 18:51:26 +01:00
|
|
|
|
2022-02-18 06:31:17 +01:00
|
|
|
/* Return early if the payment is not completed or pending*/
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! in_array($status, [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING])) {
|
2022-01-15 12:08:48 +01:00
|
|
|
return $payment;
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-01-15 12:08:48 +01:00
|
|
|
|
2020-10-25 18:51:26 +01:00
|
|
|
$this->payment_hash->payment_id = $payment->id;
|
|
|
|
$this->payment_hash->save();
|
|
|
|
|
2022-01-06 11:06:46 +01:00
|
|
|
$this->attachInvoices($payment, $this->payment_hash);
|
2022-06-21 11:57:17 +02:00
|
|
|
|
|
|
|
if ($this->payment_hash->credits_total() > 0) {
|
2021-01-06 06:54:04 +01:00
|
|
|
$payment = $payment->service()->applyCredits($this->payment_hash)->save();
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-01-06 06:54:04 +01:00
|
|
|
|
2020-10-25 18:51:26 +01:00
|
|
|
$payment->service()->updateInvoicePayment($this->payment_hash);
|
|
|
|
|
2021-10-15 09:47:41 +02:00
|
|
|
event('eloquent.created: App\Models\Payment', $payment);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($this->client->getSetting('client_online_payment_notification') && in_array($status, [Payment::STATUS_COMPLETED, Payment::STATUS_PENDING])) {
|
2021-01-17 22:31:49 +01:00
|
|
|
$payment->service()->sendEmail();
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-01-17 22:31:49 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
//todo
|
|
|
|
//catch any payment failures here also and fire a subsequent failure email if necessary? note only need for delayed payment forms
|
|
|
|
//perhaps this type of functionality should be handled higher up to provide better context?
|
2021-12-04 12:58:49 +01:00
|
|
|
|
2020-10-25 18:51:26 +01:00
|
|
|
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
|
|
|
|
|
2021-12-04 12:50:12 +01:00
|
|
|
if (property_exists($this->payment_hash->data, 'billing_context') && $status == Payment::STATUS_COMPLETED) {
|
2023-02-17 22:36:51 +01:00
|
|
|
if (is_int($this->payment_hash->data->billing_context->subscription_id)) {
|
2023-02-05 22:20:32 +01:00
|
|
|
$billing_subscription = \App\Models\Subscription::find($this->payment_hash->data->billing_context->subscription_id);
|
2023-02-17 22:36:51 +01:00
|
|
|
} else {
|
2023-02-05 22:20:32 +01:00
|
|
|
$billing_subscription = \App\Models\Subscription::find($this->decodePrimaryKey($this->payment_hash->data->billing_context->subscription_id));
|
2023-02-17 22:36:51 +01:00
|
|
|
}
|
2021-03-22 11:14:56 +01:00
|
|
|
|
2021-05-29 13:17:02 +02:00
|
|
|
// To access campaign hash => $this->payment_hash->data->billing_context->campaign;
|
2021-05-29 13:19:36 +02:00
|
|
|
// To access campaign data => Cache::get(CAMPAIGN_HASH)
|
2021-05-29 13:17:02 +02:00
|
|
|
// To access utm data => session()->get('utm-' . CAMPAIGN_HASH);
|
|
|
|
|
2021-03-25 11:55:59 +01:00
|
|
|
(new SubscriptionService($billing_subscription))->completePurchase($this->payment_hash);
|
2021-03-22 11:14:56 +01:00
|
|
|
}
|
2021-03-17 16:12:25 +01:00
|
|
|
|
2020-08-17 00:58:52 +02:00
|
|
|
return $payment->service()->applyNumber()->save();
|
|
|
|
}
|
|
|
|
|
2020-08-30 00:00:57 +02:00
|
|
|
/**
|
|
|
|
* When a successful payment is made, we need to append the gateway fee
|
2020-09-06 11:38:10 +02:00
|
|
|
* to an invoice.
|
|
|
|
*
|
2020-08-30 00:00:57 +02:00
|
|
|
* @param PaymentResponseRequest $request The incoming payment request
|
|
|
|
* @return void Success/Failure
|
|
|
|
*/
|
2021-01-28 05:21:04 +01:00
|
|
|
public function confirmGatewayFee() :void
|
2020-08-30 00:00:57 +02:00
|
|
|
{
|
|
|
|
/*Payment invoices*/
|
2021-01-28 05:21:04 +01:00
|
|
|
$payment_invoices = $this->payment_hash->invoices();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-11-25 22:07:09 +01:00
|
|
|
/*Fee charged at gateway*/
|
2021-01-28 05:21:04 +01:00
|
|
|
$fee_total = $this->payment_hash->fee_total;
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-08-30 00:00:57 +02:00
|
|
|
/*Hydrate invoices*/
|
2021-07-20 01:30:12 +02:00
|
|
|
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_invoices, 'invoice_id')))->withTrashed()->get();
|
2020-08-30 00:00:57 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$invoices->each(function ($invoice) use ($fee_total) {
|
|
|
|
if (collect($invoice->line_items)->contains('type_id', '3')) {
|
2021-09-26 12:17:09 +02:00
|
|
|
$invoice->service()->toggleFeesPaid()->save();
|
2020-08-31 04:00:43 +02:00
|
|
|
}
|
|
|
|
});
|
2020-08-30 00:00:57 +02:00
|
|
|
}
|
2020-09-09 12:05:10 +02:00
|
|
|
|
2020-09-11 00:30:12 +02:00
|
|
|
/**
|
2020-10-28 11:10:49 +01:00
|
|
|
* In case of a payment failure we should always
|
2020-09-11 00:30:12 +02:00
|
|
|
* return the invoice to its original state
|
2020-10-28 11:10:49 +01:00
|
|
|
*
|
2020-09-11 00:30:12 +02:00
|
|
|
* @param PaymentHash $payment_hash The payment hash containing the list of invoices
|
2020-10-28 11:10:49 +01:00
|
|
|
* @return void
|
2020-09-11 00:30:12 +02:00
|
|
|
*/
|
|
|
|
public function unWindGatewayFees(PaymentHash $payment_hash)
|
|
|
|
{
|
2021-07-20 01:30:12 +02:00
|
|
|
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
|
2020-09-11 00:30:12 +02:00
|
|
|
|
|
|
|
$invoices->each(function ($invoice) {
|
2022-04-02 07:13:31 +02:00
|
|
|
$invoice->service()->removeUnpaidGatewayFees();
|
2020-09-11 00:30:12 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-09-09 12:05:10 +02:00
|
|
|
/**
|
|
|
|
* Return the contact if possible.
|
|
|
|
*
|
|
|
|
* @return ClientContact The ClientContact object
|
|
|
|
*/
|
|
|
|
public function getContact()
|
|
|
|
{
|
|
|
|
if ($this->invitation) {
|
|
|
|
return ClientContact::find($this->invitation->client_contact_id);
|
|
|
|
} elseif (auth()->guard('contact')->user()) {
|
|
|
|
return auth()->user();
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 14:40:50 +01:00
|
|
|
/**
|
|
|
|
* Store payment method as company gateway token.
|
2020-10-28 11:10:49 +01:00
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @return null|ClientGatewayToken
|
2020-10-26 14:40:50 +01:00
|
|
|
*/
|
2020-10-28 16:48:24 +01:00
|
|
|
public function storeGatewayToken(array $data, array $additional = []): ?ClientGatewayToken
|
2020-10-26 14:40:50 +01:00
|
|
|
{
|
|
|
|
$company_gateway_token = new ClientGatewayToken();
|
|
|
|
$company_gateway_token->company_id = $this->client->company->id;
|
|
|
|
$company_gateway_token->client_id = $this->client->id;
|
|
|
|
$company_gateway_token->token = $data['token'];
|
|
|
|
$company_gateway_token->company_gateway_id = $this->company_gateway->id;
|
|
|
|
$company_gateway_token->gateway_type_id = $data['payment_method_id'];
|
|
|
|
$company_gateway_token->meta = $data['payment_meta'];
|
2020-10-28 16:48:24 +01:00
|
|
|
|
|
|
|
foreach ($additional as $key => $value) {
|
|
|
|
$company_gateway_token->{$key} = $value;
|
|
|
|
}
|
|
|
|
|
2020-10-26 14:40:50 +01:00
|
|
|
$company_gateway_token->save();
|
|
|
|
|
|
|
|
if ($this->client->gateway_tokens->count() == 1) {
|
|
|
|
$this->client->gateway_tokens()->update(['is_default' => 0]);
|
|
|
|
|
|
|
|
$company_gateway_token->is_default = 1;
|
|
|
|
$company_gateway_token->save();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $company_gateway_token;
|
|
|
|
}
|
2020-10-27 12:53:35 +01:00
|
|
|
|
|
|
|
public function processInternallyFailedPayment($gateway, $e)
|
|
|
|
{
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! is_null($this->payment_hash)) {
|
2021-08-27 16:19:10 +02:00
|
|
|
$this->unWindGatewayFees($this->payment_hash);
|
|
|
|
}
|
2021-02-01 22:33:04 +01:00
|
|
|
|
2022-06-16 03:21:10 +02:00
|
|
|
$error = $e->getMessage();
|
2020-10-27 12:53:35 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! $this->payment_hash) {
|
2021-11-06 06:05:56 +01:00
|
|
|
throw new PaymentFailed($error, $e->getCode());
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-11-06 06:05:56 +01:00
|
|
|
|
2021-10-17 04:49:32 +02:00
|
|
|
$amount = array_sum(array_column($this->payment_hash->invoices(), 'amount')) + $this->payment_hash->fee_total;
|
|
|
|
|
2021-10-17 12:40:40 +02:00
|
|
|
$this->sendFailureMail($error);
|
2020-10-27 12:53:35 +01:00
|
|
|
|
2021-10-13 11:24:15 +02:00
|
|
|
SystemLogger::dispatch(
|
|
|
|
$gateway->payment_hash,
|
|
|
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
|
|
|
SystemLog::EVENT_GATEWAY_ERROR,
|
|
|
|
$gateway::SYSTEM_LOG_TYPE,
|
|
|
|
$gateway->client,
|
|
|
|
$gateway->client->company,
|
|
|
|
);
|
|
|
|
|
|
|
|
throw new PaymentFailed($error, $e->getCode());
|
|
|
|
}
|
|
|
|
|
2022-01-24 04:45:57 +01:00
|
|
|
public function sendFailureMail($error)
|
2021-10-17 12:40:40 +02:00
|
|
|
{
|
2023-02-17 22:36:51 +01:00
|
|
|
if (is_object($error)) {
|
2022-08-07 23:35:00 +02:00
|
|
|
$error = 'Payment Aborted';
|
|
|
|
}
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! is_null($this->payment_hash)) {
|
2021-10-27 06:40:14 +02:00
|
|
|
$this->unWindGatewayFees($this->payment_hash);
|
|
|
|
}
|
2022-01-24 04:45:57 +01:00
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! $error) {
|
2022-01-24 04:45:57 +01:00
|
|
|
$error = '';
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
|
|
|
|
2021-10-17 12:40:40 +02:00
|
|
|
PaymentFailedMailer::dispatch(
|
|
|
|
$this->payment_hash,
|
|
|
|
$this->client->company,
|
|
|
|
$this->client,
|
|
|
|
$error
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-10-13 11:24:15 +02:00
|
|
|
public function clientPaymentFailureMailer($error)
|
|
|
|
{
|
2021-10-13 09:56:10 +02:00
|
|
|
if ($this->payment_hash && is_array($this->payment_hash->invoices())) {
|
2021-08-27 16:19:10 +02:00
|
|
|
$nmo = new NinjaMailerObject;
|
2021-10-13 11:24:15 +02:00
|
|
|
$nmo->mailable = new NinjaMailer((new ClientPaymentFailureObject($this->client, $error, $this->client->company, $this->payment_hash))->build());
|
|
|
|
$nmo->company = $this->client->company;
|
|
|
|
$nmo->settings = $this->client->company->settings;
|
2021-04-23 07:26:58 +02:00
|
|
|
|
2021-08-27 16:19:10 +02:00
|
|
|
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
|
2021-04-23 07:26:58 +02:00
|
|
|
|
2021-08-27 16:19:10 +02:00
|
|
|
$invoices->each(function ($invoice) {
|
2022-01-10 02:47:16 +01:00
|
|
|
$invoice->service()->touchPdf();
|
2021-08-27 16:19:10 +02:00
|
|
|
});
|
2021-02-16 11:14:53 +01:00
|
|
|
|
2021-08-27 16:19:10 +02:00
|
|
|
$invoices->first()->invitations->each(function ($invitation) use ($nmo) {
|
2022-06-21 11:57:17 +02:00
|
|
|
if ((bool) $invitation->contact->send_email !== false && $invitation->contact->email) {
|
2021-08-27 16:19:10 +02:00
|
|
|
$nmo->to_user = $invitation->contact;
|
|
|
|
NinjaMailerJob::dispatch($nmo);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-10-27 12:53:35 +01:00
|
|
|
}
|
2020-11-25 14:38:49 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Wrapper method for checking if resource is good.
|
2020-11-27 12:08:42 +01:00
|
|
|
*
|
|
|
|
* @param mixed $resource
|
|
|
|
* @return bool
|
2020-11-25 14:38:49 +01:00
|
|
|
*/
|
|
|
|
public function checkRequiredResource($resource): bool
|
|
|
|
{
|
|
|
|
if (is_null($resource) || empty($resource)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-07-21 10:18:14 +02:00
|
|
|
/*Generic Global unsuccessful transaction method when the client is present*/
|
|
|
|
public function processUnsuccessfulTransaction($response, $client_present = true)
|
2021-07-21 09:04:44 +02:00
|
|
|
{
|
2022-04-28 04:40:07 +02:00
|
|
|
$error = array_key_exists('error', $response) ? $response['error'] : 'Undefined Error';
|
|
|
|
$error_code = array_key_exists('error_code', $response) ? $response['error_code'] : 'Undefined Error Code';
|
2021-07-21 09:04:44 +02:00
|
|
|
|
|
|
|
$this->unWindGatewayFees($this->payment_hash);
|
|
|
|
|
2021-10-17 12:40:40 +02:00
|
|
|
$this->sendFailureMail($error);
|
2021-07-21 09:04:44 +02:00
|
|
|
|
|
|
|
$nmo = new NinjaMailerObject;
|
2022-06-21 11:57:17 +02:00
|
|
|
$nmo->mailable = new NinjaMailer((new ClientPaymentFailureObject($this->client, $error, $this->client->company, $this->payment_hash))->build());
|
2021-07-21 09:04:44 +02:00
|
|
|
$nmo->company = $this->client->company;
|
|
|
|
$nmo->settings = $this->client->company->settings;
|
|
|
|
|
|
|
|
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($this->payment_hash->invoices(), 'invoice_id')))->withTrashed()->get();
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$invoices->each(function ($invoice) {
|
2022-01-10 02:47:16 +01:00
|
|
|
$invoice->service()->touchPdf();
|
2021-07-21 09:04:44 +02:00
|
|
|
});
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
$invoices->first()->invitations->each(function ($invitation) use ($nmo) {
|
|
|
|
if (! $invitation->contact->trashed()) {
|
2021-07-21 09:04:44 +02:00
|
|
|
$nmo->to_user = $invitation->contact;
|
|
|
|
NinjaMailerJob::dispatch($nmo);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
$message = [
|
|
|
|
'server_response' => $response,
|
|
|
|
'data' => $this->payment_hash->data,
|
|
|
|
];
|
|
|
|
|
|
|
|
SystemLogger::dispatch(
|
|
|
|
$message,
|
|
|
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
|
|
|
SystemLog::EVENT_GATEWAY_FAILURE,
|
2021-09-06 07:48:31 +02:00
|
|
|
SystemLog::TYPE_PAYTRACE,
|
2021-07-21 09:04:44 +02:00
|
|
|
$this->client,
|
|
|
|
$this->client->company,
|
|
|
|
);
|
|
|
|
|
2022-06-21 11:57:17 +02:00
|
|
|
if ($client_present) {
|
2021-07-21 10:18:14 +02:00
|
|
|
throw new PaymentFailed($error, 500);
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-07-21 09:04:44 +02:00
|
|
|
}
|
|
|
|
|
2020-11-25 14:38:49 +01:00
|
|
|
public function checkRequirements()
|
|
|
|
{
|
|
|
|
if ($this->company_gateway->require_billing_address) {
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->address1)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'billing_address1';
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->address2)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'billing_address2';
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->city)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'billing_city';
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->state)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'billing_state';
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->postal_code)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'billing_postal_code';
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->country_id)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'billing_country';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->company_gateway->require_shipping_address) {
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->shipping_address1)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'shipping_address1';
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->shipping_address2)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'shipping_address2';
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->shipping_city)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'shipping_city';
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->shipping_state)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'shipping_state';
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->shipping_postal_code)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'shipping_postal_code';
|
|
|
|
}
|
|
|
|
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->shipping_country_id)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'shipping_country';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->company_gateway->require_client_name) {
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->name)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'name';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->company_gateway->require_client_phone) {
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->phone)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'phone';
|
|
|
|
}
|
|
|
|
}
|
2023-02-02 08:19:37 +01:00
|
|
|
|
2020-11-25 14:38:49 +01:00
|
|
|
|
|
|
|
if ($this->company_gateway->require_postal_code) {
|
|
|
|
// In case "require_postal_code" is true, we don't need billing address.
|
|
|
|
|
|
|
|
foreach ($this->required_fields as $position => $field) {
|
|
|
|
if (Str::startsWith($field, 'billing')) {
|
|
|
|
unset($this->required_fields[$position]);
|
|
|
|
}
|
2020-11-27 12:08:42 +01:00
|
|
|
}
|
2020-11-25 14:38:49 +01:00
|
|
|
|
2021-10-06 05:47:17 +02:00
|
|
|
if ($this->checkRequiredResource($this->client->postal_code)) {
|
2020-11-25 14:38:49 +01:00
|
|
|
$this->required_fields[] = 'postal_code';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2020-12-09 15:17:48 +01:00
|
|
|
|
|
|
|
public function getCompanyGatewayId(): int
|
|
|
|
{
|
|
|
|
return $this->company_gateway->id;
|
|
|
|
}
|
2021-01-11 23:06:56 +01:00
|
|
|
|
|
|
|
public function logSuccessfulGatewayResponse($response, $gateway_const)
|
|
|
|
{
|
|
|
|
SystemLogger::dispatch(
|
|
|
|
$response,
|
|
|
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
|
|
|
SystemLog::EVENT_GATEWAY_SUCCESS,
|
|
|
|
$gateway_const,
|
|
|
|
$this->client,
|
2021-05-19 03:12:23 +02:00
|
|
|
$this->client->company,
|
2021-01-11 23:06:56 +01:00
|
|
|
);
|
|
|
|
}
|
2021-07-05 00:59:52 +02:00
|
|
|
|
|
|
|
public function genericWebhookUrl()
|
|
|
|
{
|
|
|
|
return route('payment_notification_webhook', [
|
2022-06-21 11:57:17 +02:00
|
|
|
'company_key' => $this->client->company->company_key,
|
|
|
|
'company_gateway_id' => $this->encodePrimaryKey($this->company_gateway->id),
|
2021-07-05 02:30:47 +02:00
|
|
|
'client' => $this->encodePrimaryKey($this->client->id),
|
2021-07-05 00:59:52 +02:00
|
|
|
]);
|
2021-07-05 02:23:42 +02:00
|
|
|
}
|
2021-07-05 02:30:47 +02:00
|
|
|
|
2021-06-30 13:21:46 +02:00
|
|
|
/* Performs an extra iterate on the gatewayTypes() array and passes back only the enabled gateways*/
|
2021-06-30 14:03:13 +02:00
|
|
|
public function gatewayTypeEnabled($type)
|
2021-06-30 13:21:46 +02:00
|
|
|
{
|
|
|
|
$types = [];
|
|
|
|
|
2021-06-30 14:14:16 +02:00
|
|
|
$types[] = GatewayType::CREDIT_CARD;
|
|
|
|
$types[] = GatewayType::BANK_TRANSFER;
|
2021-06-30 13:21:46 +02:00
|
|
|
|
|
|
|
return $types;
|
2021-07-05 00:59:52 +02:00
|
|
|
}
|
2021-08-17 06:01:11 +02:00
|
|
|
|
2021-10-13 05:04:14 +02:00
|
|
|
/**
|
|
|
|
* Generic description handler
|
|
|
|
*/
|
|
|
|
public function getDescription(bool $abbreviated = true)
|
|
|
|
{
|
2023-03-01 00:54:56 +01:00
|
|
|
App::forgetInstance('translator');
|
|
|
|
$t = app('translator');
|
|
|
|
$t->replace(Ninja::transformTranslations($this->client->getMergedSettings()));
|
|
|
|
App::setLocale($this->client->company->locale());
|
|
|
|
|
2023-02-23 01:14:14 +01:00
|
|
|
if (! $this->payment_hash || !$this->client) {
|
|
|
|
return 'No description';
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-10-13 05:04:14 +02:00
|
|
|
|
2023-02-23 01:14:14 +01:00
|
|
|
$invoices_string = \implode(', ', collect($this->payment_hash->invoices())->pluck('invoice_number')->toArray()) ?: null;
|
|
|
|
$amount = Number::formatMoney($this->payment_hash?->amount_with_fee() ?: 0, $this->client);
|
|
|
|
|
|
|
|
if ($abbreviated || ! $invoices_string) {
|
|
|
|
return ctrans('texts.gateway_payment_text_no_invoice', [
|
|
|
|
'amount' => $amount,
|
|
|
|
'client' => $this->client->present()->name(),
|
|
|
|
]);
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2021-10-13 05:04:14 +02:00
|
|
|
|
2023-02-23 01:14:14 +01:00
|
|
|
return ctrans('texts.gateway_payment_text', [
|
|
|
|
'invoices' => $invoices_string,
|
|
|
|
'amount' => $amount,
|
|
|
|
'client' => $this->client->present()->name(),
|
|
|
|
]);
|
|
|
|
|
2021-10-13 05:04:14 +02:00
|
|
|
return sprintf('%s: %s', ctrans('texts.invoices'), \implode(', ', collect($this->payment_hash->invoices())->pluck('invoice_number')->toArray()));
|
|
|
|
|
2023-02-23 01:14:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stub for disconnecting from the gateway.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2021-08-17 06:01:11 +02:00
|
|
|
public function disconnect()
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
2020-06-09 13:17:26 +02:00
|
|
|
}
|