mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Import clients and payment methods via auth.net
This commit is contained in:
parent
2a3c23e25d
commit
3d11713457
@ -18,6 +18,7 @@ use App\Factory\ClientFactory;
|
|||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\ClientContact;
|
use App\Models\ClientContact;
|
||||||
use App\Models\ClientGatewayToken;
|
use App\Models\ClientGatewayToken;
|
||||||
|
use App\Models\GatewayType;
|
||||||
use App\PaymentDrivers\AuthorizePaymentDriver;
|
use App\PaymentDrivers\AuthorizePaymentDriver;
|
||||||
use Illuminate\Support\Facades\Cache;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use net\authorize\api\contract\v1\CreateCustomerProfileRequest;
|
use net\authorize\api\contract\v1\CreateCustomerProfileRequest;
|
||||||
@ -107,21 +108,22 @@ class AuthorizeCustomer
|
|||||||
$company = $this->authorize->company_gateway->company;
|
$company = $this->authorize->company_gateway->company;
|
||||||
$user = $company->owner();
|
$user = $company->owner();
|
||||||
|
|
||||||
foreach($auth_customers as $customer)
|
foreach($auth_customers as $gateway_customer_reference)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
$profile = $this->getCustomerProfile($gateway_customer_reference);
|
||||||
$profile = $this->getCustomerProfile($customer);
|
|
||||||
|
|
||||||
//if the profile ID already exists in ClientGatewayToken we continue else - add.
|
//if the profile ID already exists in ClientGatewayToken we continue else - add.
|
||||||
if($client = ClientGatewayToken::where('company_id', $company->id)->where('gateway_customer_reference', $customer)->first()){
|
if($client_gateway_token = ClientGatewayToken::where('company_id', $company->id)->where('gateway_customer_reference', $gateway_customer_reference)->first()){
|
||||||
|
nlog("found client");
|
||||||
|
$client = $client_gateway_token->client;
|
||||||
}
|
}
|
||||||
elseif($client_contact = ClientContact::where('company_id', $company->id)->where('email', $profile['email'])->first()){
|
elseif($client_contact = ClientContact::where('company_id', $company->id)->where('email', $profile['email'])->first()){
|
||||||
$client = $client_contact->client;
|
$client = $client_contact->client;
|
||||||
|
nlog("found client through contact");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
nlog("creating client");
|
||||||
$first_payment_profile = $profile['payment_profiles'][0];
|
$first_payment_profile = $profile['payment_profiles'][0];
|
||||||
|
|
||||||
$client = ClientFactory::create($company->id, $user->id);
|
$client = ClientFactory::create($company->id, $user->id);
|
||||||
@ -144,15 +146,23 @@ class AuthorizeCustomer
|
|||||||
|
|
||||||
if($client){
|
if($client){
|
||||||
|
|
||||||
|
$this->authorize->setClient($client);
|
||||||
|
|
||||||
foreach($profile['payment_profiles'] as $payment_profile)
|
foreach($profile['payment_profiles'] as $payment_profile)
|
||||||
{
|
{
|
||||||
|
|
||||||
$data['payment_profile_id'] = $payment_profile->getCustomerPaymentProfileId();
|
$payment_meta = new \stdClass;
|
||||||
$data['card_number'] = $payment_profile->getPayment()->getCreditCard()->getCardNumber();
|
$payment_meta->brand = (string) $payment_profile->getPayment()->getCreditCard()->getCardType();
|
||||||
$data['card_expiry'] = $payment_profile->getPayment()->getCreditCard()->getExpirationDate();
|
$payment_meta->last4 = (string) $payment_profile->getPayment()->getCreditCard()->getCardNumber();
|
||||||
$data['card_type'] = $payment_profile->getPayment()->getCreditCard()->getCardType();
|
$payment_meta->type = GatewayType::CREDIT_CARD;
|
||||||
|
|
||||||
|
$data['payment_method_id'] = GatewayType::CREDIT_CARD;
|
||||||
|
$data['payment_meta'] = $payment_meta;
|
||||||
|
$data['token'] = $payment_profile->getCustomerPaymentProfileId();
|
||||||
|
$additional['gateway_customer_reference'] = $gateway_customer_reference;
|
||||||
|
|
||||||
|
$this->authorize->storeGatewayToken($data, $additional);
|
||||||
|
|
||||||
return $data;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -182,7 +182,10 @@ class BaseDriver extends AbstractPaymentDriver
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setClient(Client $client)
|
||||||
|
{
|
||||||
|
$this->client = $client;
|
||||||
|
}
|
||||||
/************************** Helper methods *************************************/
|
/************************** Helper methods *************************************/
|
||||||
|
|
||||||
public function setPaymentHash(PaymentHash $payment_hash)
|
public function setPaymentHash(PaymentHash $payment_hash)
|
||||||
|
Loading…
Reference in New Issue
Block a user