1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Refactor for Gocardless

This commit is contained in:
David Bomba 2023-03-22 17:45:33 +11:00
parent 6e9ebd5779
commit 5d66f5df2c
8 changed files with 68 additions and 24 deletions

View File

@ -65,8 +65,8 @@ class PaymentFailedMailer implements ShouldQueue
*/
public function handle()
{
if (!is_string($this->error)) {
$this->error = "Payment failed, no reason given.";
if (!is_string($this->error) || strlen($this->error) <=1) {
$this->error = "";
}
//Set DB

View File

@ -37,6 +37,8 @@ class CleanStaleInvoiceOrder implements ShouldQueue
*/
public function handle(InvoiceRepository $repo) : void
{
nlog("Cleaning Stale Invoices:");
if (! config('ninja.db.multi_db_enabled')) {
Invoice::query()
->withTrashed()

View File

@ -124,6 +124,10 @@ class ClientPaymentFailureObject
'company' => $this->company,
];
if (strlen($this->error > 1)) {
$data['content'] .= "\n\n".$this->error;
}
return $data;
}
}

View File

@ -120,6 +120,10 @@ class PaymentFailureObject
'additional_info' => $this->error,
];
if (strlen($this->error > 1)) {
$data['content'] .= "\n\n".$this->error;
}
return $data;
}

View File

@ -176,7 +176,7 @@ class DirectDebit implements MethodInterface
$payment_meta = new \stdClass;
$payment_meta->brand = $billing_request->resources->customer_bank_account->bank_name;
$payment_meta->type = GatewayType::DIRECT_DEBIT;
$payment_meta->type = $this->resolveScheme($billing_request->mandate_request->scheme);
$payment_meta->state = 'pending';
$payment_meta->last4 = $billing_request->resources->customer_bank_account->account_number_ending;
@ -230,6 +230,7 @@ class DirectDebit implements MethodInterface
{
match ($scheme) {
'sepa_core' => $type = GatewayType::SEPA,
'ach' => $type = GatewayType::BANK_TRANSFER,
default => $type = GatewayType::DIRECT_DEBIT,
};

View File

@ -177,7 +177,7 @@ class SEPA implements MethodInterface
try {
$payment = $this->go_cardless->gateway->payments()->create([
'params' => [
'amount' => $amount),
'amount' => $amount,
'currency' => $request->currency,
'description' => $description,
'metadata' => [

View File

@ -11,22 +11,23 @@
namespace App\PaymentDrivers;
use App\Factory\ClientContactFactory;
use App\Factory\ClientFactory;
use App\Http\Requests\Payments\PaymentWebhookRequest;
use App\Jobs\Util\SystemLogger;
use App\Models\Client;
use App\Models\ClientGatewayToken;
use App\Models\Country;
use App\Models\GatewayType;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\SystemLog;
use App\Models\GatewayType;
use App\Models\PaymentHash;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\Utils\Traits\GeneratesCounter;
use App\Factory\ClientFactory;
use App\Jobs\Util\SystemLogger;
use App\Utils\Traits\MakesHash;
use App\Models\ClientGatewayToken;
use App\Factory\ClientContactFactory;
use App\Jobs\Mail\PaymentFailedMailer;
use App\Utils\Traits\GeneratesCounter;
use Illuminate\Database\QueryException;
use App\Http\Requests\Payments\PaymentWebhookRequest;
class GoCardlessPaymentDriver extends BaseDriver
{
@ -46,7 +47,7 @@ class GoCardlessPaymentDriver extends BaseDriver
private bool $completed = true;
public static $methods = [
GatewayType::BANK_TRANSFER => \App\PaymentDrivers\GoCardless\ACH::class,
GatewayType::BANK_TRANSFER => \App\PaymentDrivers\GoCardless\DirectDebit::class,
GatewayType::DIRECT_DEBIT => \App\PaymentDrivers\GoCardless\DirectDebit::class,
GatewayType::SEPA => \App\PaymentDrivers\GoCardless\SEPA::class,
GatewayType::INSTANT_BANK_PAY => \App\PaymentDrivers\GoCardless\InstantBankPay::class,
@ -79,7 +80,7 @@ class GoCardlessPaymentDriver extends BaseDriver
$this->client
&& isset($this->client->country)
// && in_array($this->client->country->iso_3166_3, ['GBR'])
&& in_array($this->client->currency()->code, ['EUR', 'GBP','DKK','SEK','AUD','NZD','USD'])
&& in_array($this->client->currency()->code, ['EUR', 'GBP','DKK','SEK','AUD','NZD'])
) {
$types[] = GatewayType::DIRECT_DEBIT;
}
@ -131,7 +132,8 @@ class GoCardlessPaymentDriver extends BaseDriver
}
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
{nlog("here");
{
$amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total;
$converted_amount = $this->convertToGoCardlessAmount($amount, $this->client->currency()->precision);
@ -278,9 +280,28 @@ class GoCardlessPaymentDriver extends BaseDriver
->first();
if ($payment) {
if ($payment->status_id == Payment::STATUS_PENDING) {
$payment->service()->deletePayment();
}
$payment->status_id = Payment::STATUS_FAILED;
$payment->save();
nlog('GoCardless completed');
$payment_hash = PaymentHash::where('payment_id', $payment->id)->first();
$error = '';
if (isset($event['details']['description'])) {
$error = $event['details']['description'];
}
PaymentFailedMailer::dispatch(
$payment_hash,
$payment->client->company,
$payment->client,
$error
);
}
}

View File

@ -21,17 +21,29 @@
@endisset
@isset($url)
<!-- <a href="{{ $url }}" class="button" target="_blank">{{ ctrans($button) }}</a> -->
<table border="0" cellspacing="0" cellpadding="0" align="center">
<tr style="border: 0 !important; ">
<td class="new_button" style="padding: 12px 18px 12px 18px; border-radius:5px;" align="center">
<a href="{{ $url }}") }}" target="_blank" style="border: 0 !important;font-size: 18px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; display: inline-block;">
{{ ctrans($button) }}
<div>
<!--[if (gte mso 9)|(IE)]>
<table align="center" cellspacing="0" cellpadding="0" style="width: 600px;">
<tr>
<td align="center" valign="top">
<![endif]-->
<table align="center" border="0" cellpadding="0" cellspacing="0" role="presentation" >
<tbody><tr>
<td align="center" class="new_button" style="border-radius: 2px; background-color: '.$this->settings->primary_color.'">
<a href="{{ $url }}" target="_blank" class="new_button" style="text-decoration: none; border: 1px solid '.$this->settings->primary_color.'; display: inline-block; border-radius: 2px; padding-top: 15px; padding-bottom: 15px; padding-left: 25px; padding-right: 25px; font-size: 20px; color: #fff">
<singleline label="cta button">{{ ctrans($button) }}</singleline>
</a>
</td>
</td>
</tr>
</table>
</tbody>
</table>
<!--[if (gte mso 9)|(IE)]>
</td>
</tr>
</table>
<![endif]-->
</div>
@endisset