1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-20 16:31:33 +02:00

Improve gateway descriptions for Stripe

This commit is contained in:
David Bomba 2023-02-23 11:14:14 +11:00
parent 1a75d115e0
commit 070b4fa6cf
5 changed files with 61 additions and 80 deletions

View File

@ -25,6 +25,11 @@ class PaymentHash extends Model
{
return $this->data->invoices;
}
public function amount_with_fee()
{
return $this->data->amount_with_fee;
}
public function credits_total()
{

View File

@ -11,34 +11,35 @@
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 App\Utils\Ninja;
use App\Utils\Number;
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 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\Exceptions\PaymentFailed;
use App\Jobs\Mail\NinjaMailerJob;
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 App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
/**
* Class BaseDriver.
@ -725,17 +726,35 @@ class BaseDriver extends AbstractPaymentDriver
*/
public function getDescription(bool $abbreviated = true)
{
if (! $this->payment_hash) {
return '';
if (! $this->payment_hash || !$this->client) {
return 'No description';
}
if ($abbreviated) {
return \implode(', ', collect($this->payment_hash->invoices())->pluck('invoice_number')->toArray());
$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(),
]);
}
return ctrans('texts.gateway_payment_text', [
'invoices' => $invoices_string,
'amount' => $amount,
'client' => $this->client->present()->name(),
]);
return sprintf('%s: %s', ctrans('texts.invoices'), \implode(', ', collect($this->payment_hash->invoices())->pluck('invoice_number')->toArray()));
}
}
/**
* Stub for disconnecting from the gateway.
*
* @return void
*/
public function disconnect()
{
return true;

View File

@ -20,13 +20,11 @@ use App\Jobs\Util\SystemLogger;
use App\Mail\Gateways\ACHVerificationNotification;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentHash;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\StripePaymentDriver;
use App\Utils\Number;
use App\Utils\Traits\MakesHash;
use Exception;
use Stripe\Customer;
@ -158,20 +156,6 @@ class ACH
$bank_account = Customer::retrieveSource($request->customer, $request->source, [], $this->stripe->stripe_connect_auth);
// /* Catch externally validated bank accounts and mark them as verified */
// if(isset($bank_account->status) && $bank_account->status == 'verified'){
// $meta = $token->meta;
// $meta->state = 'authorized';
// $token->meta = $meta;
// $token->save();
// return redirect()
// ->route('client.payment_methods.show', $token->hashed_id)
// ->with('message', __('texts.payment_method_verified'));
// }
try {
$bank_account->verify(['amounts' => request()->transactions]);
@ -198,18 +182,8 @@ class ACH
$data['payment_method_id'] = GatewayType::BANK_TRANSFER;
$data['customer'] = $this->stripe->findOrCreateCustomer();
$data['amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency());
$amount = $data['total']['amount_with_fee'];
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->stripe->payment_hash->invoices(), 'invoice_id')))
->withTrashed()
->first();
if ($invoice) {
$description = ctrans('texts.stripe_payment_text', ['invoicenumber' => $invoice->number, 'amount' => Number::formatMoney($amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()], $this->stripe->client->company->locale());
} else {
$description = ctrans('texts.stripe_payment_text_without_invoice', ['amount' => Number::formatMoney($amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()], $this->stripe->client->company->locale());
}
$description = $this->stripe->getDescription(false);
$intent = false;
@ -239,18 +213,11 @@ class ACH
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))
->withTrashed()
->first();
if ($invoice) {
$description = ctrans('texts.stripe_payment_text', ['invoicenumber' => $invoice->number, 'amount' => Number::formatMoney($amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()], $this->stripe->client->company->locale());
} else {
$description = ctrans('texts.stripe_payment_text_without_invoice', ['amount' => Number::formatMoney($amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()], $this->stripe->client->company->locale());
}
$description = $this->stripe->getDescription(false);
if (substr($cgt->token, 0, 2) === 'pm') {
return $this->paymentIntentTokenBilling($amount, $invoice, $description, $cgt, false);
return $this->paymentIntentTokenBilling($amount, $description, $cgt, false);
}
$this->stripe->init();
@ -291,7 +258,7 @@ class ACH
}
}
public function paymentIntentTokenBilling($amount, $invoice, $description, $cgt, $client_present = true)
public function paymentIntentTokenBilling($amount, $description, $cgt, $client_present = true)
{
$this->stripe->init();
@ -483,18 +450,11 @@ class ACH
$this->stripe->payment_hash->save();
$amount = array_sum(array_column($this->stripe->payment_hash->invoices(), 'amount')) + $this->stripe->payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->stripe->payment_hash->invoices(), 'invoice_id')))
->withTrashed()
->first();
if ($invoice) {
$description = ctrans('texts.stripe_payment_text', ['invoicenumber' => $invoice->number, 'amount' => Number::formatMoney($amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()], $this->stripe->client->company->locale());
} else {
$description = ctrans('texts.stripe_payment_text_without_invoice', ['amount' => Number::formatMoney($amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()], $this->stripe->client->company->locale());
}
$description = $this->stripe->getDescription(false);
if (substr($source->token, 0, 2) === 'pm') {
return $this->paymentIntentTokenBilling($amount, $invoice, $description, $source);
return $this->paymentIntentTokenBilling($amount, $description, $source);
}
try {

View File

@ -55,13 +55,8 @@ class Charge
}
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$invoice = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->withTrashed()->first();
if ($invoice) {
$description = ctrans('texts.stripe_payment_text', ['invoicenumber' => $invoice->number, 'amount' => Number::formatMoney($amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()], $this->stripe->client->company->locale());
} else {
$description = ctrans('texts.stripe_payment_text_without_invoice', ['amount' => Number::formatMoney($amount, $this->stripe->client), 'client' => $this->stripe->client->present()->name()], $this->stripe->client->company->locale());
}
$description = $this->stripe->getDescription(false);
$this->stripe->init();

View File

@ -4998,6 +4998,8 @@ $LANG = array(
'failed' => 'Failed',
'client_contacts' => 'Client Contacts',
'sync_from' => 'Sync From',
'gateway_payment_text' => 'Invoices: :invoices for :amount for client :client',
'gateway_payment_text_no_invoice' => 'Payment with no invoice for amount :amount for client :client',
);