mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 05:27:33 -05:00 
			
		
		
		
	Import GoCardless customers and mandates
This commit is contained in:
		
							parent
							
								
									595da2b519
								
							
						
					
					
						commit
						c0e34b369e
					
				@ -415,6 +415,42 @@ class GoCardlessPaymentDriver extends BaseDriver
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    private function updatePaymentMethods($customer, Client $client): void
 | 
					    private function updatePaymentMethods($customer, Client $client): void
 | 
				
			||||||
    {
 | 
					    {
 | 
				
			||||||
 | 
					        
 | 
				
			||||||
 | 
					        $this->client = $client;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        $mandates = $this->gateway->mandates()->list();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        foreach($mandates->records as $mandate)
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            if($customer->id != $mandate->links->customer || $mandate->status != 'active') {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $payment_meta = new \stdClass;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            if ($mandate->scheme == 'bacs') {
 | 
				
			||||||
 | 
					                $payment_meta->brand = ctrans('texts.payment_type_direct_debit');
 | 
				
			||||||
 | 
					                $payment_meta->type = GatewayType::DIRECT_DEBIT;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            elseif($mandate->scheme == 'sepa_core') {
 | 
				
			||||||
 | 
					                $payment_meta->brand = ctrans('texts.sepa');
 | 
				
			||||||
 | 
					                $payment_meta->type = GatewayType::SEPA;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            else {
 | 
				
			||||||
 | 
					                continue;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            
 | 
				
			||||||
 | 
					            $payment_meta->state = 'authorized';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $data = [
 | 
				
			||||||
 | 
					                'payment_meta' => $payment_meta,
 | 
				
			||||||
 | 
					                'token' => $mandate->id,
 | 
				
			||||||
 | 
					                'payment_method_id' => GatewayType::DIRECT_DEBIT,
 | 
				
			||||||
 | 
					            ];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            $payment_method = $this->storeGatewayToken($data, ['gateway_customer_reference' => $mandate->links->customer]);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
@ -444,11 +480,11 @@ class GoCardlessPaymentDriver extends BaseDriver
 | 
				
			|||||||
        $client->address2 = $customer->address_line2 ?: '';
 | 
					        $client->address2 = $customer->address_line2 ?: '';
 | 
				
			||||||
        $client->city = $customer->city ?: '';
 | 
					        $client->city = $customer->city ?: '';
 | 
				
			||||||
        $client->state = $customer->region ?: '';
 | 
					        $client->state = $customer->region ?: '';
 | 
				
			||||||
        $client->postal_code = $customer->postal_city ?: '';
 | 
					        $client->postal_code = $customer->postal_code ?: '';
 | 
				
			||||||
        $client->phone = $customer->address->phone ? $customer->phone : '';
 | 
					        $client->phone = $customer->phone_number ? $customer->phone_number : '';
 | 
				
			||||||
        $client->name = $customer->company_name;
 | 
					        $client->name = $customer->company_name;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if ($customer->address->country) {
 | 
					        if ($customer->country_code) {
 | 
				
			||||||
            $country = Country::where('iso_3166_2', $customer->country_code)->first();
 | 
					            $country = Country::where('iso_3166_2', $customer->country_code)->first();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ($country) {
 | 
					            if ($country) {
 | 
				
			||||||
@ -464,8 +500,8 @@ class GoCardlessPaymentDriver extends BaseDriver
 | 
				
			|||||||
        $client->save();
 | 
					        $client->save();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $contact = ClientContactFactory::create($this->company_gateway->company_id, $this->company_gateway->user_id);
 | 
					        $contact = ClientContactFactory::create($this->company_gateway->company_id, $this->company_gateway->user_id);
 | 
				
			||||||
        $contact->first_name = $customer->first_name ?: '';
 | 
					        $contact->first_name = $customer->given_name ?: '';
 | 
				
			||||||
        $contact->last_name = $customer->last_name ?: '';
 | 
					        $contact->last_name = $customer->family_name ?: '';
 | 
				
			||||||
        $contact->email = $customer->email ?: '';
 | 
					        $contact->email = $customer->email ?: '';
 | 
				
			||||||
        $contact->client_id = $client->id;
 | 
					        $contact->client_id = $client->id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user