Add descriptions to GoCardless

This commit is contained in:
David Bomba 2021-12-08 20:46:15 +11:00
parent 64e0da2958
commit 5b7be30612
3 changed files with 37 additions and 8 deletions

View File

@ -14,10 +14,10 @@ namespace App\PaymentDrivers\GoCardless;
use App\Exceptions\PaymentFailed; use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use Illuminate\Http\Request;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
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\PaymentType; use App\Models\PaymentType;
use App\Models\SystemLog; use App\Models\SystemLog;
@ -27,6 +27,7 @@ use App\Utils\Traits\MakesHash;
use Exception; use Exception;
use GoCardlessPro\Resources\Payment as ResourcesPayment; use GoCardlessPro\Resources\Payment as ResourcesPayment;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector; use Illuminate\Routing\Redirector;
use Illuminate\View\View; use Illuminate\View\View;
@ -148,7 +149,6 @@ class ACH implements MethodInterface
$data['gateway'] = $this->go_cardless; $data['gateway'] = $this->go_cardless;
$data['amount'] = $this->go_cardless->convertToGoCardlessAmount($data['total']['amount_with_fee'], $this->go_cardless->client->currency()->precision); $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['currency'] = $this->go_cardless->client->getCurrencyCode();
$data['description'] = ctrans('texts.invoices') . ': ' . collect($data['invoices'])->pluck('invoice_number');
return render('gateways.gocardless.ach.pay', $data); return render('gateways.gocardless.ach.pay', $data);
} }
@ -161,17 +161,24 @@ class ACH implements MethodInterface
*/ */
public function paymentResponse(PaymentResponseRequest $request) public function paymentResponse(PaymentResponseRequest $request)
{ {
// $token = ClientGatewayToken::find(
// $this->decodePrimaryKey($request->source)
// )->firstOrFail();
$this->go_cardless->ensureMandateIsReady($request->source); $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 { try {
$payment = $this->go_cardless->gateway->payments()->create([ $payment = $this->go_cardless->gateway->payments()->create([
'params' => [ 'params' => [
'amount' => $request->amount, 'amount' => $request->amount,
'currency' => $request->currency, 'currency' => $request->currency,
'description' => $description,
'metadata' => [ 'metadata' => [
'payment_hash' => $this->go_cardless->payment_hash->hash, 'payment_hash' => $this->go_cardless->payment_hash->hash,
], ],

View File

@ -14,11 +14,11 @@ namespace App\PaymentDrivers\GoCardless;
use App\Exceptions\PaymentFailed; use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use Illuminate\Http\Request;
use App\Jobs\Mail\PaymentFailureMailer; use App\Jobs\Mail\PaymentFailureMailer;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
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\PaymentType; use App\Models\PaymentType;
use App\Models\SystemLog; use App\Models\SystemLog;
@ -26,6 +26,7 @@ use App\PaymentDrivers\Common\MethodInterface;
use App\PaymentDrivers\GoCardlessPaymentDriver; use App\PaymentDrivers\GoCardlessPaymentDriver;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector; use Illuminate\Routing\Redirector;
use Illuminate\View\View; use Illuminate\View\View;
@ -155,11 +156,21 @@ class DirectDebit implements MethodInterface
$this->go_cardless->ensureMandateIsReady($request->source); $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 { try {
$payment = $this->go_cardless->gateway->payments()->create([ $payment = $this->go_cardless->gateway->payments()->create([
'params' => [ 'params' => [
'amount' => $request->amount, 'amount' => $request->amount,
'currency' => $request->currency, 'currency' => $request->currency,
'description' => $description,
'metadata' => [ 'metadata' => [
'payment_hash' => $this->go_cardless->payment_hash->hash, 'payment_hash' => $this->go_cardless->payment_hash->hash,
], ],

View File

@ -14,10 +14,10 @@ namespace App\PaymentDrivers\GoCardless;
use App\Exceptions\PaymentFailed; use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest; use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use Illuminate\Http\Request;
use App\Jobs\Util\SystemLogger; use App\Jobs\Util\SystemLogger;
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\PaymentType; use App\Models\PaymentType;
use App\Models\SystemLog; use App\Models\SystemLog;
@ -26,6 +26,7 @@ use App\PaymentDrivers\GoCardlessPaymentDriver;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
use Exception; use Exception;
use Illuminate\Http\RedirectResponse; use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Redirector; use Illuminate\Routing\Redirector;
use Illuminate\View\View; use Illuminate\View\View;
@ -162,11 +163,21 @@ class SEPA implements MethodInterface
{ {
$this->go_cardless->ensureMandateIsReady($request->source); $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 { try {
$payment = $this->go_cardless->gateway->payments()->create([ $payment = $this->go_cardless->gateway->payments()->create([
'params' => [ 'params' => [
'amount' => $request->amount, 'amount' => $request->amount,
'currency' => $request->currency, 'currency' => $request->currency,
'description' => $description,
'metadata' => [ 'metadata' => [
'payment_hash' => $this->go_cardless->payment_hash->hash, 'payment_hash' => $this->go_cardless->payment_hash->hash,
], ],