mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 10:14:36 -04:00
Improve gateway descriptions for Stripe
This commit is contained in:
parent
1a75d115e0
commit
070b4fa6cf
@ -25,6 +25,11 @@ class PaymentHash extends Model
|
|||||||
{
|
{
|
||||||
return $this->data->invoices;
|
return $this->data->invoices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function amount_with_fee()
|
||||||
|
{
|
||||||
|
return $this->data->amount_with_fee;
|
||||||
|
}
|
||||||
|
|
||||||
public function credits_total()
|
public function credits_total()
|
||||||
{
|
{
|
||||||
|
@ -11,34 +11,35 @@
|
|||||||
|
|
||||||
namespace App\PaymentDrivers;
|
namespace App\PaymentDrivers;
|
||||||
|
|
||||||
use App\Events\Invoice\InvoiceWasPaid;
|
use App\Utils\Ninja;
|
||||||
use App\Events\Payment\PaymentWasCreated;
|
use App\Utils\Number;
|
||||||
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\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\ClientContact;
|
use App\Utils\Helpers;
|
||||||
use App\Models\ClientGatewayToken;
|
|
||||||
use App\Models\CompanyGateway;
|
|
||||||
use App\Models\GatewayType;
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\PaymentHash;
|
|
||||||
use App\Models\SystemLog;
|
use App\Models\SystemLog;
|
||||||
use App\Services\Subscription\SubscriptionService;
|
use App\Models\GatewayType;
|
||||||
use App\Utils\Helpers;
|
use App\Models\PaymentHash;
|
||||||
use App\Utils\Ninja;
|
|
||||||
use App\Utils\Traits\MakesHash;
|
|
||||||
use App\Utils\Traits\SystemLogTrait;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Support\Carbon;
|
|
||||||
use Illuminate\Support\Str;
|
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.
|
* Class BaseDriver.
|
||||||
@ -725,17 +726,35 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
*/
|
*/
|
||||||
public function getDescription(bool $abbreviated = true)
|
public function getDescription(bool $abbreviated = true)
|
||||||
{
|
{
|
||||||
if (! $this->payment_hash) {
|
if (! $this->payment_hash || !$this->client) {
|
||||||
return '';
|
return 'No description';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($abbreviated) {
|
$invoices_string = \implode(', ', collect($this->payment_hash->invoices())->pluck('invoice_number')->toArray()) ?: null;
|
||||||
return \implode(', ', collect($this->payment_hash->invoices())->pluck('invoice_number')->toArray());
|
$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()));
|
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()
|
public function disconnect()
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
|
@ -20,13 +20,11 @@ use App\Jobs\Util\SystemLogger;
|
|||||||
use App\Mail\Gateways\ACHVerificationNotification;
|
use App\Mail\Gateways\ACHVerificationNotification;
|
||||||
use App\Models\ClientGatewayToken;
|
use App\Models\ClientGatewayToken;
|
||||||
use App\Models\GatewayType;
|
use App\Models\GatewayType;
|
||||||
use App\Models\Invoice;
|
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\PaymentHash;
|
use App\Models\PaymentHash;
|
||||||
use App\Models\PaymentType;
|
use App\Models\PaymentType;
|
||||||
use App\Models\SystemLog;
|
use App\Models\SystemLog;
|
||||||
use App\PaymentDrivers\StripePaymentDriver;
|
use App\PaymentDrivers\StripePaymentDriver;
|
||||||
use App\Utils\Number;
|
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
use Exception;
|
use Exception;
|
||||||
use Stripe\Customer;
|
use Stripe\Customer;
|
||||||
@ -158,20 +156,6 @@ class ACH
|
|||||||
|
|
||||||
$bank_account = Customer::retrieveSource($request->customer, $request->source, [], $this->stripe->stripe_connect_auth);
|
$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 {
|
try {
|
||||||
$bank_account->verify(['amounts' => request()->transactions]);
|
$bank_account->verify(['amounts' => request()->transactions]);
|
||||||
|
|
||||||
@ -198,18 +182,8 @@ class ACH
|
|||||||
$data['payment_method_id'] = GatewayType::BANK_TRANSFER;
|
$data['payment_method_id'] = GatewayType::BANK_TRANSFER;
|
||||||
$data['customer'] = $this->stripe->findOrCreateCustomer();
|
$data['customer'] = $this->stripe->findOrCreateCustomer();
|
||||||
$data['amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency());
|
$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;
|
$intent = false;
|
||||||
|
|
||||||
@ -239,18 +213,11 @@ class ACH
|
|||||||
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
|
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
|
||||||
{
|
{
|
||||||
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
|
$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 = $this->stripe->getDescription(false);
|
||||||
$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());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (substr($cgt->token, 0, 2) === 'pm') {
|
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();
|
$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();
|
$this->stripe->init();
|
||||||
|
|
||||||
@ -483,18 +450,11 @@ class ACH
|
|||||||
$this->stripe->payment_hash->save();
|
$this->stripe->payment_hash->save();
|
||||||
|
|
||||||
$amount = array_sum(array_column($this->stripe->payment_hash->invoices(), 'amount')) + $this->stripe->payment_hash->fee_total;
|
$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 = $this->stripe->getDescription(false);
|
||||||
$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());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (substr($source->token, 0, 2) === 'pm') {
|
if (substr($source->token, 0, 2) === 'pm') {
|
||||||
return $this->paymentIntentTokenBilling($amount, $invoice, $description, $source);
|
return $this->paymentIntentTokenBilling($amount, $description, $source);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -55,13 +55,8 @@ class Charge
|
|||||||
}
|
}
|
||||||
|
|
||||||
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
|
$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 = $this->stripe->getDescription(false);
|
||||||
$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());
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->stripe->init();
|
$this->stripe->init();
|
||||||
|
|
||||||
|
@ -4998,6 +4998,8 @@ $LANG = array(
|
|||||||
'failed' => 'Failed',
|
'failed' => 'Failed',
|
||||||
'client_contacts' => 'Client Contacts',
|
'client_contacts' => 'Client Contacts',
|
||||||
'sync_from' => 'Sync From',
|
'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',
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user