mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Update bank accounts when they are verified offline
This commit is contained in:
parent
ae00f3cad3
commit
a0395558f7
@ -103,7 +103,7 @@ class Gateway extends StaticModel
|
||||
case 20:
|
||||
return [
|
||||
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::APPLE_PAY => ['refund' => false, 'token_billing' => false],
|
||||
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
|
||||
return [
|
||||
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::APPLE_PAY => ['refund' => false, 'token_billing' => false],
|
||||
GatewayType::SOFORT => ['refund' => true, 'token_billing' => true, 'webhooks' => ['source.chargeable', 'charge.succeeded', 'payment_intent.succeeded']],
|
||||
|
@ -94,6 +94,26 @@ class ACH
|
||||
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)
|
||||
{
|
||||
if (isset($token->meta->state) && $token->meta->state === 'authorized') {
|
||||
@ -102,6 +122,25 @@ class ACH
|
||||
->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 = [
|
||||
'token' => $token,
|
||||
'gateway' => $this->stripe,
|
||||
@ -126,19 +165,19 @@ class ACH
|
||||
|
||||
$bank_account = Customer::retrieveSource($request->customer, $request->source, [], $this->stripe->stripe_connect_auth);
|
||||
|
||||
/* Catch externally validated bank accounts and mark them as verified */
|
||||
if(property_exists($bank_account, 'status') && $bank_account->status == 'verified'){
|
||||
// /* 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();
|
||||
// $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'));
|
||||
// return redirect()
|
||||
// ->route('client.payment_methods.show', $token->hashed_id)
|
||||
// ->with('message', __('texts.payment_method_verified'));
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
try {
|
||||
$bank_account->verify(['amounts' => request()->transactions]);
|
||||
|
@ -631,6 +631,11 @@ class StripePaymentDriver extends BaseDriver
|
||||
// nlog($request->all());
|
||||
|
||||
//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') {
|
||||
PaymentIntentWebhook::dispatch($request->data, $request->company_key, $this->company_gateway->id)->delay(now()->addSeconds(rand(5, 10)));
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user