diff --git a/app/PaymentDrivers/GoCardless/ACH.php b/app/PaymentDrivers/GoCardless/ACH.php index 41bd1fe892cf..c466754f58fa 100644 --- a/app/PaymentDrivers/GoCardless/ACH.php +++ b/app/PaymentDrivers/GoCardless/ACH.php @@ -14,10 +14,10 @@ namespace App\PaymentDrivers\GoCardless; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use Illuminate\Http\Request; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; +use App\Models\Invoice; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; @@ -27,6 +27,7 @@ use App\Utils\Traits\MakesHash; use Exception; use GoCardlessPro\Resources\Payment as ResourcesPayment; use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; use Illuminate\Routing\Redirector; use Illuminate\View\View; @@ -148,7 +149,6 @@ class ACH implements MethodInterface $data['gateway'] = $this->go_cardless; $data['amount'] = $this->go_cardless->convertToGoCardlessAmount($data['total']['amount_with_fee'], $this->go_cardless->client->currency()->precision); $data['currency'] = $this->go_cardless->client->getCurrencyCode(); - $data['description'] = ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number'); return render('gateways.gocardless.ach.pay', $data); } @@ -161,17 +161,24 @@ class ACH implements MethodInterface */ public function paymentResponse(PaymentResponseRequest $request) { - // $token = ClientGatewayToken::find( - // $this->decodePrimaryKey($request->source) - // )->firstOrFail(); $this->go_cardless->ensureMandateIsReady($request->source); - + + $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) + ->withTrashed() + ->first(); + + if($invoice) + $description = "Invoice {$invoice->number} for {$request->amount} for client {$this->go_cardless->client->present()->name()}"; + else + $description = "Amount {$request->amount} from client {$this->go_cardless->client->present()->name()}"; + try { $payment = $this->go_cardless->gateway->payments()->create([ 'params' => [ 'amount' => $request->amount, 'currency' => $request->currency, + 'description' => $description, 'metadata' => [ 'payment_hash' => $this->go_cardless->payment_hash->hash, ], diff --git a/app/PaymentDrivers/GoCardless/DirectDebit.php b/app/PaymentDrivers/GoCardless/DirectDebit.php index 7e915f5f8f9d..51ae2fb1de91 100644 --- a/app/PaymentDrivers/GoCardless/DirectDebit.php +++ b/app/PaymentDrivers/GoCardless/DirectDebit.php @@ -14,11 +14,11 @@ namespace App\PaymentDrivers\GoCardless; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use Illuminate\Http\Request; use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; +use App\Models\Invoice; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; @@ -26,6 +26,7 @@ use App\PaymentDrivers\Common\MethodInterface; use App\PaymentDrivers\GoCardlessPaymentDriver; use App\Utils\Traits\MakesHash; use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; use Illuminate\Routing\Redirector; use Illuminate\View\View; @@ -155,11 +156,21 @@ class DirectDebit implements MethodInterface $this->go_cardless->ensureMandateIsReady($request->source); + $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) + ->withTrashed() + ->first(); + + if($invoice) + $description = "Invoice {$invoice->number} for {$request->amount} for client {$this->go_cardless->client->present()->name()}"; + else + $description = "Amount {$request->amount} from client {$this->go_cardless->client->present()->name()}"; + try { $payment = $this->go_cardless->gateway->payments()->create([ 'params' => [ 'amount' => $request->amount, 'currency' => $request->currency, + 'description' => $description, 'metadata' => [ 'payment_hash' => $this->go_cardless->payment_hash->hash, ], diff --git a/app/PaymentDrivers/GoCardless/SEPA.php b/app/PaymentDrivers/GoCardless/SEPA.php index 6a9bfb342664..d14d84a69d34 100644 --- a/app/PaymentDrivers/GoCardless/SEPA.php +++ b/app/PaymentDrivers/GoCardless/SEPA.php @@ -14,10 +14,10 @@ namespace App\PaymentDrivers\GoCardless; use App\Exceptions\PaymentFailed; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; -use Illuminate\Http\Request; use App\Jobs\Util\SystemLogger; use App\Models\ClientGatewayToken; use App\Models\GatewayType; +use App\Models\Invoice; use App\Models\Payment; use App\Models\PaymentType; use App\Models\SystemLog; @@ -26,6 +26,7 @@ use App\PaymentDrivers\GoCardlessPaymentDriver; use App\Utils\Traits\MakesHash; use Exception; use Illuminate\Http\RedirectResponse; +use Illuminate\Http\Request; use Illuminate\Routing\Redirector; use Illuminate\View\View; @@ -162,11 +163,21 @@ class SEPA implements MethodInterface { $this->go_cardless->ensureMandateIsReady($request->source); + $invoice = Invoice::whereIn('id', $this->transformKeys(array_column($this->go_cardless->payment_hash->invoices(), 'invoice_id'))) + ->withTrashed() + ->first(); + + if($invoice) + $description = "Invoice {$invoice->number} for {$request->amount} for client {$this->go_cardless->client->present()->name()}"; + else + $description = "Amount {$request->amount} from client {$this->go_cardless->client->present()->name()}"; + try { $payment = $this->go_cardless->gateway->payments()->create([ 'params' => [ 'amount' => $request->amount, 'currency' => $request->currency, + 'description' => $description, 'metadata' => [ 'payment_hash' => $this->go_cardless->payment_hash->hash, ],