mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 22:47:32 -05:00 
			
		
		
		
	Improve ACH flow
This commit is contained in:
		
							parent
							
								
									0fc0f4d6bb
								
							
						
					
					
						commit
						6cd6c218de
					
				@ -13,6 +13,7 @@ namespace App\PaymentDrivers\Stripe\Jobs;
 | 
			
		||||
 | 
			
		||||
use App\Jobs\Util\SystemLogger;
 | 
			
		||||
use App\Libraries\MultiDB;
 | 
			
		||||
use App\Models\ClientGatewayToken;
 | 
			
		||||
use App\Models\Company;
 | 
			
		||||
use App\Models\CompanyGateway;
 | 
			
		||||
use App\Models\GatewayType;
 | 
			
		||||
@ -21,6 +22,7 @@ use App\Models\Payment;
 | 
			
		||||
use App\Models\PaymentHash;
 | 
			
		||||
use App\Models\PaymentType;
 | 
			
		||||
use App\Models\SystemLog;
 | 
			
		||||
use App\PaymentDrivers\Stripe\UpdatePaymentMethods;
 | 
			
		||||
use App\PaymentDrivers\Stripe\Utilities;
 | 
			
		||||
use Illuminate\Bus\Queueable;
 | 
			
		||||
use Illuminate\Contracts\Queue\ShouldQueue;
 | 
			
		||||
@ -53,7 +55,6 @@ class PaymentIntentWebhook implements ShouldQueue
 | 
			
		||||
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        nlog($this->stripe_request);
 | 
			
		||||
 | 
			
		||||
        MultiDB::findAndSetDbByCompanyKey($this->company_key);
 | 
			
		||||
 | 
			
		||||
@ -202,6 +203,49 @@ class PaymentIntentWebhook implements ShouldQueue
 | 
			
		||||
            $client->company,
 | 
			
		||||
        );
 | 
			
		||||
 | 
			
		||||
        try {
 | 
			
		||||
 | 
			
		||||
            $customer = $driver->getCustomer($this->stripe_request['object']['charges']['data'][0]['customer']);
 | 
			
		||||
            $method = $driver->getStripePaymentMethod($this->stripe_request['object']['charges']['data'][0]['payment_method']);
 | 
			
		||||
            $payment_method = $this->stripe_request['object']['charges']['data'][0]['payment_method'];
 | 
			
		||||
 | 
			
		||||
            $token_exists = ClientGatewayToken::where([
 | 
			
		||||
                'gateway_customer_reference' => $customer->id,
 | 
			
		||||
                'token' => $payment_method,
 | 
			
		||||
                'client_id' => $client->id,
 | 
			
		||||
                'company_id' => $client->company_id,
 | 
			
		||||
            ])->exists();
 | 
			
		||||
 | 
			
		||||
            /* Already exists return */
 | 
			
		||||
            if ($token_exists) {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $payment_meta = new \stdClass;
 | 
			
		||||
            $payment_meta->brand = (string) \sprintf('%s (%s)', $method->us_bank_account['bank_name'], ctrans('texts.ach'));
 | 
			
		||||
            $payment_meta->last4 = (string) $method->us_bank_account['last4'];
 | 
			
		||||
            $payment_meta->type = GatewayType::BANK_TRANSFER;
 | 
			
		||||
            $payment_meta->state = 'verified';
 | 
			
		||||
 | 
			
		||||
            $data = [
 | 
			
		||||
                'payment_meta' => $payment_meta,
 | 
			
		||||
                'token' => $payment_method,
 | 
			
		||||
                'payment_method_id' => GatewayType::BANK_TRANSFER,
 | 
			
		||||
            ];
 | 
			
		||||
 | 
			
		||||
            $additional_data = ['gateway_customer_reference' => $customer->id];
 | 
			
		||||
 | 
			
		||||
            if ($customer->default_source === $method->id) {
 | 
			
		||||
                $additional_data = ['gateway_customer_reference' => $customer->id, 'is_default' => 1];
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $driver->storeGatewayToken($data, $additional_data);
 | 
			
		||||
            
 | 
			
		||||
        }
 | 
			
		||||
        catch(\Exception $e){
 | 
			
		||||
            nlog("failed to import payment methods");
 | 
			
		||||
            nlog($e->getMessage());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -70,7 +70,7 @@ class UpdatePaymentMethods
 | 
			
		||||
        $this->importBankAccounts($customer, $client);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    private function importBankAccounts($customer, $client)
 | 
			
		||||
    public function importBankAccounts($customer, $client)
 | 
			
		||||
    {
 | 
			
		||||
        $sources = $customer->sources;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user