2021-10-12 16:46:42 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2024-04-12 06:15:41 +02:00
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
2021-10-12 16:46:42 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\PaymentDrivers\Stripe;
|
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\SystemLog;
|
2024-09-04 05:36:50 +02:00
|
|
|
use Stripe\PaymentIntent;
|
2023-12-18 05:25:16 +01:00
|
|
|
use App\Models\GatewayType;
|
|
|
|
use App\Models\PaymentHash;
|
|
|
|
use App\Models\PaymentType;
|
|
|
|
use Illuminate\Support\Str;
|
2021-10-13 15:53:32 +02:00
|
|
|
use App\Http\Requests\Request;
|
2023-12-18 05:25:16 +01:00
|
|
|
use App\Jobs\Util\SystemLogger;
|
|
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
use App\Exceptions\PaymentFailed;
|
|
|
|
use App\Models\ClientGatewayToken;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
2021-10-12 16:46:42 +02:00
|
|
|
use App\Jobs\Mail\PaymentFailureMailer;
|
|
|
|
use App\PaymentDrivers\StripePaymentDriver;
|
2024-09-04 05:36:50 +02:00
|
|
|
use App\PaymentDrivers\Common\LivewireMethodInterface;
|
2023-12-18 05:25:16 +01:00
|
|
|
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
|
2021-10-12 16:46:42 +02:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
class ACSS implements LivewireMethodInterface
|
2021-10-12 16:46:42 +02:00
|
|
|
{
|
2023-12-18 05:25:16 +01:00
|
|
|
use MakesHash;
|
|
|
|
|
2021-10-12 16:46:42 +02:00
|
|
|
/** @var StripePaymentDriver */
|
|
|
|
public StripePaymentDriver $stripe;
|
|
|
|
|
|
|
|
public function __construct(StripePaymentDriver $stripe)
|
|
|
|
{
|
|
|
|
$this->stripe = $stripe;
|
2021-10-13 15:53:32 +02:00
|
|
|
$this->stripe->init();
|
2021-10-12 16:46:42 +02:00
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
/**
|
|
|
|
* Generate mandate for future ACSS billing
|
|
|
|
*
|
|
|
|
* @param mixed $data
|
|
|
|
* @return void
|
|
|
|
*/
|
2021-10-12 16:46:42 +02:00
|
|
|
public function authorizeView($data)
|
|
|
|
{
|
2021-10-13 15:53:32 +02:00
|
|
|
$data['gateway'] = $this->stripe;
|
2023-12-18 05:25:16 +01:00
|
|
|
$data['company_gateway'] = $this->stripe->company_gateway;
|
|
|
|
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
|
|
|
|
$data['country'] = $this->stripe->client->country->iso_3166_2;
|
|
|
|
$data['post_auth_response'] = false;
|
|
|
|
|
|
|
|
$intent = \Stripe\SetupIntent::create([
|
|
|
|
'usage' => 'off_session',
|
|
|
|
'payment_method_types' => ['acss_debit'],
|
|
|
|
'customer' => $data['customer'],
|
|
|
|
'payment_method_options' => [
|
|
|
|
'acss_debit' => [
|
2024-09-05 03:55:47 +02:00
|
|
|
'currency' => strtolower($this->stripe->client->currency()->code),
|
2023-12-18 05:25:16 +01:00
|
|
|
'mandate_options' => [
|
|
|
|
'payment_schedule' => 'combined',
|
|
|
|
'interval_description' => 'On any invoice due date',
|
|
|
|
'transaction_type' => 'personal',
|
|
|
|
],
|
|
|
|
'verification_method' => 'instant',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
], $this->stripe->stripe_connect_auth);
|
|
|
|
|
|
|
|
$data['pi_client_secret'] = $intent->client_secret;
|
2021-10-13 15:53:32 +02:00
|
|
|
|
|
|
|
return render('gateways.stripe.acss.authorize', array_merge($data));
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
/**
|
|
|
|
* Authorizes the mandate for future billing
|
|
|
|
*
|
2023-12-18 05:32:01 +01:00
|
|
|
* @param Request $request
|
2023-12-18 05:25:16 +01:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-10-13 15:53:32 +02:00
|
|
|
public function authorizeResponse(Request $request)
|
|
|
|
{
|
2023-12-18 05:25:16 +01:00
|
|
|
$setup_intent = json_decode($request->input('gateway_response'));
|
|
|
|
|
|
|
|
if (isset($setup_intent->type)) {
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
$error = "There was a problem setting up this payment method for future use";
|
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
if (in_array($setup_intent->type, ["validation_error", "invalid_request_error"])) {
|
2023-12-18 05:25:16 +01:00
|
|
|
$error = "Please provide complete payment details.";
|
|
|
|
}
|
|
|
|
|
|
|
|
SystemLogger::dispatch(
|
|
|
|
['response' => (array)$setup_intent, 'data' => $request->all()],
|
|
|
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
|
|
|
SystemLog::EVENT_GATEWAY_FAILURE,
|
|
|
|
SystemLog::TYPE_STRIPE,
|
|
|
|
$this->stripe->client,
|
|
|
|
$this->stripe->client->company,
|
|
|
|
);
|
|
|
|
|
|
|
|
throw new PaymentFailed($error, 400);
|
|
|
|
}
|
2021-10-13 15:53:32 +02:00
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
$stripe_setup_intent = $this->stripe->getSetupIntentId($setup_intent->id); //needed to harvest the Mandate
|
2021-10-13 15:53:32 +02:00
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
$client_gateway_token = $this->storePaymentMethod($setup_intent->payment_method, $stripe_setup_intent->mandate, $setup_intent->status == 'succeeded' ? 'authorized' : 'unauthorized');
|
2021-10-13 15:53:32 +02:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
if ($request->has('post_auth_response') && boolval($request->post_auth_response)) {
|
2023-12-18 05:25:16 +01:00
|
|
|
/** @var array $data */
|
|
|
|
$data = Cache::pull($request->post_auth_response);
|
2021-10-13 15:53:32 +02:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
if (!$data) {
|
2023-12-18 05:25:16 +01:00
|
|
|
throw new PaymentFailed("There was a problem storing this payment method", 500);
|
2024-01-14 05:05:00 +01:00
|
|
|
}
|
2021-10-13 15:53:32 +02:00
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
$hash = PaymentHash::with('fee_invoice')->where('hash', $data['payment_hash'])->first();
|
|
|
|
$data['tokens'] = [$client_gateway_token];
|
2021-10-13 15:53:32 +02:00
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
$this->stripe->setPaymentHash($hash);
|
2023-12-18 05:25:16 +01:00
|
|
|
$this->stripe->setClient($hash->fee_invoice->client);
|
|
|
|
$this->stripe->setPaymentMethod(GatewayType::ACSS);
|
2021-10-13 15:53:32 +02:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
return $this->paymentView($data);
|
2023-12-18 05:25:16 +01:00
|
|
|
}
|
2021-10-13 15:53:32 +02:00
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
return redirect()->route('client.payment_methods.show', $client_gateway_token->hashed_id);
|
2021-10-13 15:53:32 +02:00
|
|
|
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-12-18 05:32:01 +01:00
|
|
|
/**
|
|
|
|
* Generates a token Payment Intent
|
|
|
|
*
|
|
|
|
* @param ClientGatewayToken $token
|
2023-12-18 05:37:03 +01:00
|
|
|
* @return PaymentIntent
|
2023-12-18 05:32:01 +01:00
|
|
|
*/
|
|
|
|
private function tokenIntent(ClientGatewayToken $token): PaymentIntent
|
2021-10-13 15:53:32 +02:00
|
|
|
{
|
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
$intent = \Stripe\PaymentIntent::create([
|
|
|
|
'amount' => $this->stripe->convertToStripeAmount($this->stripe->payment_hash->amount_with_fee(), $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
|
|
|
|
'currency' => $this->stripe->client->currency()->code,
|
|
|
|
'payment_method_types' => ['acss_debit'],
|
|
|
|
'customer' => $this->stripe->findOrCreateCustomer(),
|
|
|
|
'description' => $this->stripe->getDescription(false),
|
|
|
|
'metadata' => [
|
|
|
|
'payment_hash' => $this->stripe->payment_hash->hash,
|
|
|
|
'gateway_type_id' => GatewayType::ACSS,
|
|
|
|
],
|
2024-01-14 05:05:00 +01:00
|
|
|
'payment_method' => $token->token,
|
|
|
|
'mandate' => $token->meta?->mandate,
|
|
|
|
'confirm' => true,
|
2023-12-18 05:25:16 +01:00
|
|
|
], $this->stripe->stripe_connect_auth);
|
2021-10-13 15:53:32 +02:00
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
return $intent;
|
2021-10-13 15:53:32 +02:00
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2024-08-28 03:17:03 +02:00
|
|
|
public function paymentData(array $data): array
|
2021-10-13 15:53:32 +02:00
|
|
|
{
|
2023-12-18 05:25:16 +01:00
|
|
|
if(count($data['tokens']) == 0) {
|
|
|
|
$hash = Str::random(32);
|
2024-09-04 05:36:50 +02:00
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
Cache::put($hash, $data, 3600);
|
2021-10-13 15:53:32 +02:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
$data['post_auth_response'] = $hash;
|
|
|
|
$data['needs_mandate_generate'] = true;
|
|
|
|
|
|
|
|
$data['gateway'] = $this->stripe;
|
|
|
|
$data['company_gateway'] = $this->stripe->company_gateway;
|
|
|
|
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
|
|
|
|
$data['country'] = $this->stripe->client->country->iso_3166_2;
|
2024-07-16 10:43:55 +02:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
$intent = \Stripe\SetupIntent::create([
|
|
|
|
'usage' => 'off_session',
|
|
|
|
'payment_method_types' => ['acss_debit'],
|
|
|
|
'customer' => $data['customer'],
|
|
|
|
'payment_method_options' => [
|
|
|
|
'acss_debit' => [
|
2024-09-05 03:55:47 +02:00
|
|
|
'currency' => strtolower($this->stripe->client->currency()->code),
|
2024-09-04 05:36:50 +02:00
|
|
|
'mandate_options' => [
|
|
|
|
'payment_schedule' => 'combined',
|
|
|
|
'interval_description' => 'On any invoice due date',
|
|
|
|
'transaction_type' => 'personal',
|
|
|
|
],
|
|
|
|
'verification_method' => 'instant',
|
|
|
|
],
|
|
|
|
],
|
|
|
|
], $this->stripe->stripe_connect_auth);
|
2024-07-16 10:43:55 +02:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
$data['pi_client_secret'] = $intent->client_secret;
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
return $data;
|
|
|
|
}
|
2021-10-12 16:46:42 +02:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
$this->stripe->init();
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-10-12 16:46:42 +02:00
|
|
|
$data['gateway'] = $this->stripe;
|
2024-09-04 05:36:50 +02:00
|
|
|
$data['return_url'] = $this->buildReturnUrl();
|
|
|
|
$data['stripe_amount'] = $this->stripe->convertToStripeAmount($data['total']['amount_with_fee'], $this->stripe->client->currency()->precision, $this->stripe->client->currency());
|
|
|
|
$data['client'] = $this->stripe->client;
|
2021-10-12 16:46:42 +02:00
|
|
|
$data['customer'] = $this->stripe->findOrCreateCustomer()->id;
|
|
|
|
$data['country'] = $this->stripe->client->country->iso_3166_2;
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $data['stripe_amount']]);
|
|
|
|
$this->stripe->payment_hash->save();
|
2023-12-18 05:25:16 +01:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
return $data;
|
2023-12-18 05:25:16 +01:00
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-12-18 05:32:01 +01:00
|
|
|
/**
|
2024-09-04 05:36:50 +02:00
|
|
|
* Payment view for ACSS
|
|
|
|
*
|
|
|
|
* Determines if any payment tokens are available and if not, generates a mandate
|
2023-12-18 05:32:01 +01:00
|
|
|
*
|
|
|
|
* @param array $data
|
2024-09-04 05:36:50 +02:00
|
|
|
|
2023-12-18 05:32:01 +01:00
|
|
|
*/
|
2024-09-04 05:36:50 +02:00
|
|
|
public function paymentView(array $data)
|
2023-12-18 05:25:16 +01:00
|
|
|
{
|
2024-09-04 05:36:50 +02:00
|
|
|
$data = $this->paymentData($data);
|
2023-12-18 05:25:16 +01:00
|
|
|
|
2024-09-04 05:36:50 +02:00
|
|
|
if (array_key_exists('needs_mandate_generate', $data)) {
|
|
|
|
return render('gateways.stripe.acss.authorize', array_merge($data));
|
|
|
|
}
|
2021-10-12 16:46:42 +02:00
|
|
|
|
|
|
|
return render('gateways.stripe.acss.pay', $data);
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-12-18 05:32:01 +01:00
|
|
|
/**
|
|
|
|
* ?redundant
|
|
|
|
*
|
|
|
|
* @return string
|
|
|
|
*/
|
2021-10-12 16:46:42 +02:00
|
|
|
private function buildReturnUrl(): string
|
|
|
|
{
|
|
|
|
return route('client.payments.response', [
|
|
|
|
'company_gateway_id' => $this->stripe->company_gateway->id,
|
|
|
|
'payment_hash' => $this->stripe->payment_hash->hash,
|
|
|
|
'payment_method_id' => GatewayType::ACSS,
|
|
|
|
]);
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-12-18 05:32:01 +01:00
|
|
|
/**
|
|
|
|
* PaymentResponseRequest
|
|
|
|
*
|
2023-12-18 05:37:03 +01:00
|
|
|
* @param PaymentResponseRequest $request
|
2023-12-18 05:32:01 +01:00
|
|
|
*/
|
2021-10-12 16:46:42 +02:00
|
|
|
public function paymentResponse(PaymentResponseRequest $request)
|
|
|
|
{
|
2023-12-18 05:25:16 +01:00
|
|
|
|
2021-10-12 16:46:42 +02:00
|
|
|
$gateway_response = json_decode($request->gateway_response);
|
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
$cgt = ClientGatewayToken::find($this->decodePrimaryKey($request->token));
|
2023-12-18 05:32:01 +01:00
|
|
|
|
2023-12-18 05:37:03 +01:00
|
|
|
/** @var \Stripe\PaymentIntent $intent */
|
2023-12-18 05:25:16 +01:00
|
|
|
$intent = $this->tokenIntent($cgt);
|
|
|
|
|
2021-10-12 16:46:42 +02:00
|
|
|
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, $request->all());
|
|
|
|
$this->stripe->payment_hash->save();
|
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
if ($intent->status && $intent->status == 'processing') {
|
|
|
|
|
|
|
|
return $this->processSuccessfulPayment($intent->id);
|
2021-10-12 16:46:42 +02:00
|
|
|
}
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2021-10-12 16:46:42 +02:00
|
|
|
return $this->processUnsuccessfulPayment();
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-12-18 05:32:01 +01:00
|
|
|
/**
|
|
|
|
* Performs token billing using a ACSS payment method
|
|
|
|
*
|
|
|
|
* @param ClientGatewayToken $cgt
|
|
|
|
* @param PaymentHash $payment_hash
|
|
|
|
*/
|
2023-12-18 05:25:16 +01:00
|
|
|
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
|
|
|
|
{
|
|
|
|
$this->stripe->init();
|
|
|
|
$this->stripe->setPaymentHash($payment_hash);
|
|
|
|
$this->stripe->setClient($cgt->client);
|
|
|
|
$stripe_amount = $this->stripe->convertToStripeAmount($payment_hash->amount_with_fee(), $this->stripe->client->currency()->precision, $this->stripe->client->currency());
|
|
|
|
$this->stripe->payment_hash->data = array_merge((array) $this->stripe->payment_hash->data, ['stripe_amount' => $stripe_amount]);
|
|
|
|
$this->stripe->payment_hash->save();
|
|
|
|
|
2023-12-18 05:37:03 +01:00
|
|
|
/** @var \Stripe\PaymentIntent $intent */
|
2023-12-18 05:25:16 +01:00
|
|
|
$intent = $this->tokenIntent($cgt);
|
|
|
|
|
|
|
|
if ($intent->status && $intent->status == 'processing') {
|
|
|
|
$this->processSuccessfulPayment($intent->id);
|
2024-01-14 05:05:00 +01:00
|
|
|
} else {
|
2023-12-18 05:25:16 +01:00
|
|
|
$e = new \Exception("There was a problem processing this payment method", 500);
|
|
|
|
$this->stripe->processInternallyFailedPayment($this->stripe, $e);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-12-18 05:32:01 +01:00
|
|
|
/**
|
|
|
|
* Creates a payment for the transaction
|
|
|
|
*
|
|
|
|
* @param string $payment_intent
|
|
|
|
*/
|
2023-12-18 05:37:03 +01:00
|
|
|
public function processSuccessfulPayment(string $payment_intent)
|
2021-10-12 16:46:42 +02:00
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'payment_method' => $payment_intent,
|
|
|
|
'payment_type' => PaymentType::ACSS,
|
|
|
|
'amount' => $this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency()),
|
|
|
|
'transaction_reference' => $payment_intent,
|
|
|
|
'gateway_type_id' => GatewayType::ACSS,
|
|
|
|
];
|
|
|
|
|
2021-10-15 15:38:01 +02:00
|
|
|
$payment = $this->stripe->createPayment($data, Payment::STATUS_PENDING);
|
2021-10-12 16:46:42 +02:00
|
|
|
|
|
|
|
SystemLogger::dispatch(
|
|
|
|
['response' => $this->stripe->payment_hash->data, 'data' => $data],
|
|
|
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
|
|
|
SystemLog::EVENT_GATEWAY_SUCCESS,
|
|
|
|
SystemLog::TYPE_STRIPE,
|
|
|
|
$this->stripe->client,
|
|
|
|
$this->stripe->client->company,
|
|
|
|
);
|
|
|
|
|
2021-10-15 15:38:01 +02:00
|
|
|
return redirect()->route('client.payments.show', $payment->hashed_id);
|
2021-10-12 16:46:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function processUnsuccessfulPayment()
|
|
|
|
{
|
|
|
|
$server_response = $this->stripe->payment_hash->data;
|
|
|
|
|
|
|
|
PaymentFailureMailer::dispatch(
|
|
|
|
$this->stripe->client,
|
|
|
|
$server_response,
|
|
|
|
$this->stripe->client->company,
|
|
|
|
$this->stripe->convertFromStripeAmount($this->stripe->payment_hash->data->stripe_amount, $this->stripe->client->currency()->precision, $this->stripe->client->currency())
|
|
|
|
);
|
|
|
|
|
|
|
|
$message = [
|
|
|
|
'server_response' => $server_response,
|
|
|
|
'data' => $this->stripe->payment_hash->data,
|
|
|
|
];
|
|
|
|
|
|
|
|
SystemLogger::dispatch(
|
|
|
|
$message,
|
|
|
|
SystemLog::CATEGORY_GATEWAY_RESPONSE,
|
|
|
|
SystemLog::EVENT_GATEWAY_FAILURE,
|
|
|
|
SystemLog::TYPE_STRIPE,
|
|
|
|
$this->stripe->client,
|
|
|
|
$this->stripe->client->company,
|
|
|
|
);
|
|
|
|
|
|
|
|
throw new PaymentFailed('Failed to process the payment.', 500);
|
|
|
|
}
|
2024-01-14 05:05:00 +01:00
|
|
|
|
2023-12-18 05:32:01 +01:00
|
|
|
/**
|
|
|
|
* Stores the payment token
|
|
|
|
*
|
|
|
|
* @param string $payment_method
|
|
|
|
* @param string $mandate
|
|
|
|
* @param string $status
|
|
|
|
* @return ClientGatewayToken
|
|
|
|
*/
|
2023-12-18 05:25:16 +01:00
|
|
|
private function storePaymentMethod(string $payment_method, string $mandate, string $status = 'authorized'): ?ClientGatewayToken
|
2021-10-12 16:46:42 +02:00
|
|
|
{
|
|
|
|
try {
|
2023-12-18 05:25:16 +01:00
|
|
|
$method = $this->stripe->getStripePaymentMethod($payment_method);
|
2021-10-12 16:46:42 +02:00
|
|
|
|
2024-01-14 05:05:00 +01:00
|
|
|
$payment_meta = new \stdClass();
|
2022-03-09 01:31:59 +01:00
|
|
|
$payment_meta->brand = (string) $method->acss_debit->bank_name;
|
|
|
|
$payment_meta->last4 = (string) $method->acss_debit->last4;
|
2023-12-18 05:25:16 +01:00
|
|
|
$payment_meta->state = $status;
|
2021-10-12 16:46:42 +02:00
|
|
|
$payment_meta->type = GatewayType::ACSS;
|
2023-12-18 05:25:16 +01:00
|
|
|
$payment_meta->mandate = $mandate;
|
2021-10-12 16:46:42 +02:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'payment_meta' => $payment_meta,
|
2023-12-18 05:25:16 +01:00
|
|
|
'token' => $payment_method,
|
2021-10-12 16:46:42 +02:00
|
|
|
'payment_method_id' => GatewayType::ACSS,
|
|
|
|
];
|
|
|
|
|
2023-12-18 05:25:16 +01:00
|
|
|
return $this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $method->customer]);
|
2021-10-12 16:46:42 +02:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
return $this->stripe->processInternallyFailedPayment($this->stripe, $e);
|
|
|
|
}
|
|
|
|
}
|
2024-07-16 10:43:55 +02:00
|
|
|
|
|
|
|
public function livewirePaymentView(array $data): string
|
2024-09-04 05:36:50 +02:00
|
|
|
{
|
|
|
|
if (array_key_exists('needs_mandate_generate', $data)) {
|
|
|
|
return 'gateways.stripe.acss.authorize_livewire';
|
|
|
|
}
|
|
|
|
|
|
|
|
return 'gateways.stripe.acss.pay_livewire';
|
|
|
|
}
|
2021-10-12 16:46:42 +02:00
|
|
|
}
|