GoCardless: New payment flow (#72)

* pass livewirePaymentView & processPaymentView thru base driver

* gocardless
This commit is contained in:
Benjamin Beganović 2024-08-09 01:09:29 +02:00
parent 8fbd8a9593
commit 83ced6d340
4 changed files with 91 additions and 15 deletions

View File

@ -20,6 +20,7 @@ use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\Common\MethodInterface;
use App\PaymentDrivers\GoCardlessPaymentDriver;
use App\Utils\Traits\MakesHash;
@ -31,7 +32,7 @@ use Illuminate\Routing\Redirector;
use Illuminate\View\View;
//@deprecated
class ACH implements MethodInterface
class ACH implements MethodInterface, LivewireMethodInterface
{
use MakesHash;
@ -146,9 +147,7 @@ class ACH implements MethodInterface
*/
public function paymentView(array $data): View
{
$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 = $this->paymentData($data);
return render('gateways.gocardless.ach.pay', $data);
}
@ -257,4 +256,23 @@ class ACH implements MethodInterface
throw new PaymentFailed('Failed to process the payment.', 500);
}
/**
* @inheritDoc
*/
public function livewirePaymentView(array $data): string
{
return 'gateways.gocardless.ach.pay_livewire';
}
/**
* @inheritDoc
*/
public function paymentData(array $data): array
{
$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();
return $data;
}
}

View File

@ -21,6 +21,7 @@ use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\Common\MethodInterface;
use App\PaymentDrivers\GoCardlessPaymentDriver;
use App\Utils\Traits\MakesHash;
@ -29,7 +30,7 @@ use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
class DirectDebit implements MethodInterface
class DirectDebit implements MethodInterface, LivewireMethodInterface
{
use MakesHash;
@ -218,9 +219,7 @@ class DirectDebit implements MethodInterface
*/
public function paymentView(array $data): View
{
$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 = $this->paymentData($data);
return render('gateways.gocardless.direct_debit.pay', $data);
}
@ -330,4 +329,24 @@ class DirectDebit implements MethodInterface
throw new PaymentFailed('Failed to process the payment.', 500);
}
/**
* @inheritDoc
*/
public function livewirePaymentView(array $data): string
{
return 'gateways.gocardless.direct_debit.pay_livewire';
}
/**
* @inheritDoc
*/
public function paymentData(array $data): array
{
$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();
return $data;
}
}

View File

@ -9,13 +9,14 @@ use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\Common\MethodInterface;
use App\PaymentDrivers\GoCardlessPaymentDriver;
use Illuminate\Contracts\Container\BindingResolutionException;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
class InstantBankPay implements MethodInterface
class InstantBankPay implements MethodInterface, LivewireMethodInterface
{
protected GoCardlessPaymentDriver $go_cardless;
@ -197,9 +198,8 @@ class InstantBankPay implements MethodInterface
* Process unsuccessful payments for Direct Debit.
*
* @param ResourcesPayment $payment
* @return never
*/
public function processUnsuccessfulPayment(\GoCardlessPro\Resources\Payment $payment)
public function processUnsuccessfulPayment(\GoCardlessPro\Resources\Payment $payment): void
{
PaymentFailureMailer::dispatch($this->go_cardless->client, $payment->status, $this->go_cardless->client->company, $this->go_cardless->payment_hash->data->amount_with_fee);
@ -224,4 +224,24 @@ class InstantBankPay implements MethodInterface
$this->go_cardless->client->company,
);
}
/**
* @inheritDoc
*/
public function livewirePaymentView(array $data): string
{
// not supported, this is offsite payment method.
return '';
}
/**
* @inheritDoc
*/
public function paymentData(array $data): array
{
$this->paymentView($data);
return $data;
}
}

View File

@ -20,6 +20,7 @@ use App\Models\Invoice;
use App\Models\Payment;
use App\Models\PaymentType;
use App\Models\SystemLog;
use App\PaymentDrivers\Common\LivewireMethodInterface;
use App\PaymentDrivers\Common\MethodInterface;
use App\PaymentDrivers\GoCardlessPaymentDriver;
use App\Utils\Traits\MakesHash;
@ -29,7 +30,7 @@ use Illuminate\Http\Request;
use Illuminate\Routing\Redirector;
use Illuminate\View\View;
class SEPA implements MethodInterface
class SEPA implements MethodInterface, LivewireMethodInterface
{
use MakesHash;
@ -145,9 +146,7 @@ class SEPA implements MethodInterface
*/
public function paymentView(array $data): View
{
$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 = $this->paymentData($data);
return render('gateways.gocardless.sepa.pay', $data);
}
@ -257,4 +256,24 @@ class SEPA implements MethodInterface
throw new PaymentFailed('Failed to process the payment.', 500);
}
/**
* @inheritDoc
*/
public function livewirePaymentView(array $data): string
{
return 'gateways.gocardless.sepa.pay_livewire';
}
/**
* @inheritDoc
*/
public function paymentData(array $data): array
{
$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();
return $data;
}
}