Fix for adding a payment method twice

This commit is contained in:
Lars Kusch 2023-01-20 09:20:30 +01:00
parent 8cb650dd60
commit 0414b6e622
2 changed files with 22 additions and 19 deletions

View File

@ -15,6 +15,7 @@ namespace App\PaymentDrivers\Stripe;
use App\Exceptions\PaymentFailed;
use App\Http\Requests\ClientPortal\Payments\PaymentResponseRequest;
use App\Jobs\Util\SystemLogger;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\Models\Payment;
use App\Models\PaymentType;
@ -177,8 +178,12 @@ class BACS
'token' => $method->id,
'payment_method_id' => GatewayType::BACS,
];
$this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]);
$clientgateway = ClientGatewayToken::query()
->where('token', $method->id)
->first();
if (!$clientgateway){
$this->stripe->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]);
}
} catch (\Exception $e) {
return $this->stripe->processInternallyFailedPayment($this->stripe, $e);
}

View File

@ -738,21 +738,21 @@ class StripePaymentDriver extends BaseDriver
$customer = $this->findOrCreateCustomer();
$this->attach($setup_intent->payment_method, $customer);
$payment_method = $this->getStripePaymentMethod($setup_intent->payment_method);
$payment_meta = new \stdClass;
$payment_meta->brand = (string) $payment_method->bacs_debit->sort_code;
$payment_meta->last4 = (string) $payment_method->bacs_debit->last4;
$payment_meta->state = 'unauthorized';
$payment_meta->type = GatewayType::BACS;
$data = [
'payment_meta' => $payment_meta,
'token' => $payment_method->id,
'payment_method_id' => GatewayType::BACS,
];
$clientgateway = ClientGatewayToken::query()
->where('token', $payment_method)
->first();
if (!$clientgateway){
$payment_meta = new \stdClass;
$payment_meta->brand = (string) $payment_method->bacs_debit->sort_code;
$payment_meta->last4 = (string) $payment_method->bacs_debit->last4;
$payment_meta->state = 'unauthorized';
$payment_meta->type = GatewayType::BACS;
$data = [
'payment_meta' => $payment_meta,
'token' => $payment_method->id,
'payment_method_id' => GatewayType::BACS,
];
$this->storeGatewayToken($data, ['gateway_customer_reference' => $customer->id]);
}
return response()->json([], 200);
@ -772,12 +772,10 @@ class StripePaymentDriver extends BaseDriver
}
elseif ($request->data['object']['status'] === "inactive" && $request->data['object']['payment_method']){
// Delete payment method
// $clientgateway = ClientGatewayToken::query()
// ->where('token', $request->data['object']['payment_method'])
// ->first();
// $clientgateway->delete();
(new ClientGatewayTokenRepository)->archive($request->data['object']['payment_method']);
$clientgateway = ClientGatewayToken::query()
->where('token', $request->data['object']['payment_method'])
->first();
$clientgateway->delete();
return response()->json([], 200);
}
elseif ($request->data['object']['status'] === "pending"){