mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-31 15:04:37 -04:00
Generic handling page for unsuccessful payments
This commit is contained in:
parent
f7dc573551
commit
c55f660f7f
@ -45,6 +45,8 @@ class InvoicePaidActivity implements ShouldQueue
|
|||||||
{
|
{
|
||||||
MultiDB::setDb($event->company->db);
|
MultiDB::setDb($event->company->db);
|
||||||
|
|
||||||
|
$event->invoice->service()->touchPdf();
|
||||||
|
|
||||||
$fields = new \stdClass;
|
$fields = new \stdClass;
|
||||||
|
|
||||||
$fields->invoice_id = $event->invoice->id;
|
$fields->invoice_id = $event->invoice->id;
|
||||||
|
@ -194,6 +194,24 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In case of a payment failure we should always
|
||||||
|
* return the invoice to its original state
|
||||||
|
*
|
||||||
|
* @param PaymentHash $payment_hash The payment hash containing the list of invoices
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function unWindGatewayFees(PaymentHash $payment_hash)
|
||||||
|
{
|
||||||
|
|
||||||
|
$invoices = Invoice::whereIn('id', $this->transformKeys(array_column($payment_hash->invoices(), 'invoice_id')))->get();
|
||||||
|
|
||||||
|
$invoices->each(function ($invoice) {
|
||||||
|
$invoice->service()->removeUnpaidGatewayFees();
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the contact if possible.
|
* Return the contact if possible.
|
||||||
*
|
*
|
||||||
|
@ -253,7 +253,7 @@ class CheckoutComPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
$payment = $this->createPayment($data, Payment::STATUS_PENDING);
|
$payment = $this->createPayment($data, Payment::STATUS_PENDING);
|
||||||
|
|
||||||
$this->attachInvoices($payment, $state['hashed_ids']);
|
$this->attachInvoices($payment, $state['payment_hash']);
|
||||||
|
|
||||||
$payment->service()->updateInvoicePayment();
|
$payment->service()->updateInvoicePayment();
|
||||||
|
|
||||||
@ -269,9 +269,16 @@ class CheckoutComPaymentDriver extends BaseDriver
|
|||||||
try {
|
try {
|
||||||
return redirect($state['payment_response']->_links['redirect']['href']);
|
return redirect($state['payment_response']->_links['redirect']['href']);
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_CHECKOUT, $this->client);
|
SystemLogger::dispatch($logger_message, SystemLog::CATEGORY_GATEWAY_RESPONSE, SystemLog::EVENT_GATEWAY_FAILURE, SystemLog::TYPE_CHECKOUT, $this->client);
|
||||||
|
|
||||||
throw new \Exception('Failed to process the payment.', 1);
|
$this->unWindGatewayFees($state['payment_hash']);
|
||||||
|
|
||||||
|
return render('gateways.unsuccessful', [
|
||||||
|
'code' => $state['payment_response']->response_code,
|
||||||
|
'message' => ctrans('texts.payment_error'),
|
||||||
|
]);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -290,6 +297,7 @@ class CheckoutComPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
return render('gateways.unsuccessful', [
|
return render('gateways.unsuccessful', [
|
||||||
'code' => $state['payment_response']->response_code,
|
'code' => $state['payment_response']->response_code,
|
||||||
|
'message' => ctrans('texts.payment_error'),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -308,7 +316,12 @@ class CheckoutComPaymentDriver extends BaseDriver
|
|||||||
|
|
||||||
//todo push to a error page with the exception message.
|
//todo push to a error page with the exception message.
|
||||||
|
|
||||||
throw new \Exception('Failed to process the payment.', 1);
|
//throw new \Exception('Failed to process the payment.', 1);
|
||||||
|
|
||||||
|
return render('gateways.unsuccessful', [
|
||||||
|
'code' => '500',
|
||||||
|
'message' => ctrans('texts.payment_error'),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function createPayment($data, $status = Payment::STATUS_COMPLETED): Payment
|
public function createPayment($data, $status = Payment::STATUS_COMPLETED): Payment
|
||||||
|
@ -11,6 +11,7 @@
|
|||||||
|
|
||||||
namespace App\Services\Invoice;
|
namespace App\Services\Invoice;
|
||||||
|
|
||||||
|
use App\Jobs\Invoice\CreateInvoicePdf;
|
||||||
use App\Models\CompanyGateway;
|
use App\Models\CompanyGateway;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
@ -211,6 +212,8 @@ class InvoiceService
|
|||||||
return $item;
|
return $item;
|
||||||
})->toArray();
|
})->toArray();
|
||||||
|
|
||||||
|
$this->invoice = $this->invoice->calc()->getInvoice();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -221,6 +224,8 @@ class InvoiceService
|
|||||||
return $item->type_id == '3';
|
return $item->type_id == '3';
|
||||||
})->toArray();
|
})->toArray();
|
||||||
|
|
||||||
|
$this->invoice = $this->invoice->calc()->getInvoice();
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,6 +246,20 @@ class InvoiceService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sometimes we need to refresh the
|
||||||
|
* PDF when it is updated etc.
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function touchPdf()
|
||||||
|
{
|
||||||
|
$this->invoice->invitations->each(function ($invitation){
|
||||||
|
CreateInvoicePdf::dispatch($invitation);
|
||||||
|
});
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/*When a reminder is sent we want to touch the dates they were sent*/
|
/*When a reminder is sent we want to touch the dates they were sent*/
|
||||||
public function touchReminder(string $reminder_template)
|
public function touchReminder(string $reminder_template)
|
||||||
{
|
{
|
||||||
|
@ -141,8 +141,6 @@ class HtmlEngine
|
|||||||
}
|
}
|
||||||
|
|
||||||
$data['$entity_number'] = &$data['$number'];
|
$data['$entity_number'] = &$data['$number'];
|
||||||
|
|
||||||
//$data['$paid_to_date'] = ;
|
|
||||||
$data['$invoice.discount'] = ['value' => Number::formatMoney($this->entity_calc->getTotalDiscount(), $this->client) ?: ' ', 'label' => ctrans('texts.discount')];
|
$data['$invoice.discount'] = ['value' => Number::formatMoney($this->entity_calc->getTotalDiscount(), $this->client) ?: ' ', 'label' => ctrans('texts.discount')];
|
||||||
$data['$discount'] = &$data['$invoice.discount'];
|
$data['$discount'] = &$data['$invoice.discount'];
|
||||||
$data['$subtotal'] = ['value' => Number::formatMoney($this->entity_calc->getSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.subtotal')];
|
$data['$subtotal'] = ['value' => Number::formatMoney($this->entity_calc->getSubTotal(), $this->client) ?: ' ', 'label' => ctrans('texts.subtotal')];
|
||||||
@ -236,9 +234,8 @@ class HtmlEngine
|
|||||||
$data['$client.country'] = &$data['$country'];
|
$data['$client.country'] = &$data['$country'];
|
||||||
$data['$client.email'] = &$data['$email'];
|
$data['$client.email'] = &$data['$email'];
|
||||||
|
|
||||||
|
$data['$client.balance'] = ['value' => Number::formatMoney($this->client->balance, $this->client), 'label' => ctrans('texts.account_balance')];
|
||||||
$data['$client.balance'] = ['value' => $this->client->balance, 'label' => ctrans('texts.balance')];
|
$data['$paid_to_date'] = ['value' => Number::formatMoney($this->client->paid_to_date, $this->client), 'label' => ctrans('texts.paid_to_date')];
|
||||||
$data['$paid_to_date'] = ['value' => $this->client->paid_to_date, 'label' => ctrans('texts.paid_to_date')];
|
|
||||||
|
|
||||||
$data['$contact.full_name'] = ['value' => $this->contact->present()->name(), 'label' => ctrans('texts.name')];
|
$data['$contact.full_name'] = ['value' => $this->contact->present()->name(), 'label' => ctrans('texts.name')];
|
||||||
$data['$contact.email'] = ['value' => $this->contact->email, 'label' => ctrans('texts.email')];
|
$data['$contact.email'] = ['value' => $this->contact->email, 'label' => ctrans('texts.email')];
|
||||||
|
@ -3268,4 +3268,5 @@ return [
|
|||||||
'no_items_selected' => 'No items selected.',
|
'no_items_selected' => 'No items selected.',
|
||||||
|
|
||||||
'payment_due' => 'Payment due',
|
'payment_due' => 'Payment due',
|
||||||
|
'account_balance' => 'Account balance',
|
||||||
];
|
];
|
||||||
|
@ -6,8 +6,10 @@
|
|||||||
{{ ctrans('texts.payment_error_code', ['code' => isset($code) ? $code : '']) }}
|
{{ ctrans('texts.payment_error_code', ['code' => isset($code) ? $code : '']) }}
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
<span class="mt-6 block">{{ ctrans('texts.common_codes') }}:</span>
|
@if($message)
|
||||||
<ul>
|
<span class="mt-6 block">{{ ctrans('texts.message') }}:</span>
|
||||||
<li>{{ ctrans('texts.payment_error_code_20087') }}.</li>
|
<ul>
|
||||||
</ul>
|
<li>{{ $message }}.</li>
|
||||||
|
</ul>
|
||||||
|
@endif
|
||||||
@endsection
|
@endsection
|
||||||
|
Loading…
x
Reference in New Issue
Block a user