Update bank accounts when they are verified offline

This commit is contained in:
David Bomba 2023-01-11 11:12:40 +11:00
parent ae00f3cad3
commit a0395558f7
3 changed files with 56 additions and 12 deletions

View File

@ -103,7 +103,7 @@ class Gateway extends StaticModel
case 20: case 20:
return [ return [
GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => ['payment_intent.succeeded']], GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => ['payment_intent.succeeded']],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'customer.source.updated']],
GatewayType::ALIPAY => ['refund' => false, 'token_billing' => false], GatewayType::ALIPAY => ['refund' => false, 'token_billing' => false],
GatewayType::APPLE_PAY => ['refund' => false, 'token_billing' => false], GatewayType::APPLE_PAY => ['refund' => false, 'token_billing' => false],
GatewayType::SOFORT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], GatewayType::SOFORT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']],
@ -140,7 +140,7 @@ class Gateway extends StaticModel
case 56: //Stripe case 56: //Stripe
return [ return [
GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => ['payment_intent.succeeded']], GatewayType::CREDIT_CARD => ['refund' => true, 'token_billing' => true, 'webhooks' => ['payment_intent.succeeded']],
GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded']], GatewayType::BANK_TRANSFER => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'customer.source.updated']],
GatewayType::ALIPAY => ['refund' => false, 'token_billing' => false], GatewayType::ALIPAY => ['refund' => false, 'token_billing' => false],
GatewayType::APPLE_PAY => ['refund' => false, 'token_billing' => false], GatewayType::APPLE_PAY => ['refund' => false, 'token_billing' => false],
GatewayType::SOFORT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']], GatewayType::SOFORT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']],

View File

@ -94,6 +94,26 @@ class ACH
return redirect()->route('client.payment_methods.verification', ['payment_method' => $client_gateway_token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]); return redirect()->route('client.payment_methods.verification', ['payment_method' => $client_gateway_token->hashed_id, 'method' => GatewayType::BANK_TRANSFER]);
} }
public function updateBankAccount(array $event)
{
$stripe_event = $event['data']['object'];
$token = ClientGatewayToken::where('token', $stripe_event['id'])
->where('gateway_customer_reference', $stripe_event['customer'])
->first();
if($token && isset($stripe_event['object']) && $stripe_event['object'] == 'bank_account' && isset($stripe_event['status']) && $stripe_event['status'] == 'verified') {
$meta = $token->meta;
$meta->state = 'authorized';
$token->meta = $meta;
$token->save();
}
}
public function verificationView(ClientGatewayToken $token) public function verificationView(ClientGatewayToken $token)
{ {
if (isset($token->meta->state) && $token->meta->state === 'authorized') { if (isset($token->meta->state) && $token->meta->state === 'authorized') {
@ -102,6 +122,25 @@ class ACH
->with('message', __('texts.payment_method_verified')); ->with('message', __('texts.payment_method_verified'));
} }
//double check here if we need to show the verification view.
$this->stripe->init();
$bank_account = Customer::retrieveSource($token->gateway_customer_reference, $token->token, [], $this->stripe->stripe_connect_auth);
/* Catch externally validated bank accounts and mark them as verified */
if(isset($bank_account->status) && $bank_account->status == 'verified'){
$meta = $token->meta;
$meta->state = 'authorized';
$token->meta = $meta;
$token->save();
return redirect()
->route('client.payment_methods.show', $token->hashed_id)
->with('message', __('texts.payment_method_verified'));
}
$data = [ $data = [
'token' => $token, 'token' => $token,
'gateway' => $this->stripe, 'gateway' => $this->stripe,
@ -126,19 +165,19 @@ class ACH
$bank_account = Customer::retrieveSource($request->customer, $request->source, [], $this->stripe->stripe_connect_auth); $bank_account = Customer::retrieveSource($request->customer, $request->source, [], $this->stripe->stripe_connect_auth);
/* Catch externally validated bank accounts and mark them as verified */ // /* Catch externally validated bank accounts and mark them as verified */
if(property_exists($bank_account, 'status') && $bank_account->status == 'verified'){ // if(isset($bank_account->status) && $bank_account->status == 'verified'){
$meta = $token->meta; // $meta = $token->meta;
$meta->state = 'authorized'; // $meta->state = 'authorized';
$token->meta = $meta; // $token->meta = $meta;
$token->save(); // $token->save();
return redirect() // return redirect()
->route('client.payment_methods.show', $token->hashed_id) // ->route('client.payment_methods.show', $token->hashed_id)
->with('message', __('texts.payment_method_verified')); // ->with('message', __('texts.payment_method_verified'));
} // }
try { try {
$bank_account->verify(['amounts' => request()->transactions]); $bank_account->verify(['amounts' => request()->transactions]);

View File

@ -631,6 +631,11 @@ class StripePaymentDriver extends BaseDriver
// nlog($request->all()); // nlog($request->all());
//payment_intent.succeeded - this will confirm or cancel the payment //payment_intent.succeeded - this will confirm or cancel the payment
if($request->type === 'customer.source.updated') {
$ach = new ACH($this);
$ach->updateBankAccount($request->all());
}
if ($request->type === 'payment_intent.succeeded') { if ($request->type === 'payment_intent.succeeded') {
PaymentIntentWebhook::dispatch($request->data, $request->company_key, $this->company_gateway->id)->delay(now()->addSeconds(rand(5, 10))); PaymentIntentWebhook::dispatch($request->data, $request->company_key, $this->company_gateway->id)->delay(now()->addSeconds(rand(5, 10)));