Working on important Auth.net customers

This commit is contained in:
David Bomba 2022-02-15 15:24:00 +11:00
parent eb2123bf4e
commit 2a3c23e25d
3 changed files with 85 additions and 5 deletions

View File

@ -80,7 +80,7 @@ class AuthorizeCreditCard
$client_gateway_token = $authorise_payment_method->createClientGatewayToken($payment_profile, $gateway_customer_reference); $client_gateway_token = $authorise_payment_method->createClientGatewayToken($payment_profile, $gateway_customer_reference);
} }
else{ else{
//remove the payment profile //remove the payment profile if we are not storing tokens in our system
$this->removePaymentProfile($gateway_customer_reference, $payment_profile_id); $this->removePaymentProfile($gateway_customer_reference, $payment_profile_id);
} }

View File

@ -13,8 +13,13 @@
namespace App\PaymentDrivers\Authorize; namespace App\PaymentDrivers\Authorize;
use App\Exceptions\GenericPaymentDriverFailure; use App\Exceptions\GenericPaymentDriverFailure;
use App\Factory\ClientContactFactory;
use App\Factory\ClientFactory;
use App\Models\Client; use App\Models\Client;
use App\Models\ClientContact;
use App\Models\ClientGatewayToken;
use App\PaymentDrivers\AuthorizePaymentDriver; use App\PaymentDrivers\AuthorizePaymentDriver;
use Illuminate\Support\Facades\Cache;
use net\authorize\api\contract\v1\CreateCustomerProfileRequest; use net\authorize\api\contract\v1\CreateCustomerProfileRequest;
use net\authorize\api\contract\v1\CustomerProfileType; use net\authorize\api\contract\v1\CustomerProfileType;
use net\authorize\api\contract\v1\GetCustomerProfileIdsRequest; use net\authorize\api\contract\v1\GetCustomerProfileIdsRequest;
@ -48,9 +53,6 @@ class AuthorizeCustomer
return $response->getIds(); return $response->getIds();
// echo "GetCustomerProfileId's SUCCESS: " . "\n";
// $profileIds[] = $response->getIds();
// echo "There are " . count($profileIds[0]) . " Customer Profile ID's for this Merchant Name and Transaction Key" . "\n";
} }
else else
{ {
@ -77,7 +79,7 @@ class AuthorizeCustomer
$paymentProfilesSelected = $profileSelected->getPaymentProfiles(); $paymentProfilesSelected = $profileSelected->getPaymentProfiles();
return [ return [
'profile' => $profileSelected, 'email' => $profileSelected->getEmail(),
'payment_profiles' => $paymentProfilesSelected, 'payment_profiles' => $paymentProfilesSelected,
'error' => '' 'error' => ''
]; ];
@ -99,6 +101,78 @@ class AuthorizeCustomer
} }
} }
public function importCustomers()
{
$auth_customers = $this->getCustomerProfileIds();
$company = $this->authorize->company_gateway->company;
$user = $company->owner();
foreach($auth_customers as $customer)
{
$profile = $this->getCustomerProfile($customer);
//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()){
}
elseif($client_contact = ClientContact::where('company_id', $company->id)->where('email', $profile['email'])->first()){
$client = $client_contact->client;
}
else {
$first_payment_profile = $profile['payment_profiles'][0];
$client = ClientFactory::create($company->id, $user->id);
$billTo = $first_payment_profile->getBillTo();
$client->address1 = $billTo->getAddress();
$client->city = $billTo->getCity();
$client->state = $billTo->getState();
$client->postal_code = $billTo->getZip();
$client->country_id = $billTo->getCountry() ? $this->getCountryCode($billTo->getCountry()) : $company->settings->country_id;
$client->save();
$client_contact = ClientContactFactory::create($company->id, $user->id);
$client_contact->client_id = $client->id;
$client_contact->first_name = $billTo->getFirstName();
$client_contact->last_name = $billTo->getLastName();
$client_contact->email = $profile['email'];
$client_contact->phone = $billTo->getPhoneNumber();
$client_contact->save();
}
if($client){
foreach($profile['payment_profiles'] as $payment_profile)
{
$data['payment_profile_id'] = $payment_profile->getCustomerPaymentProfileId();
$data['card_number'] = $payment_profile->getPayment()->getCreditCard()->getCardNumber();
$data['card_expiry'] = $payment_profile->getPayment()->getCreditCard()->getExpirationDate();
$data['card_type'] = $payment_profile->getPayment()->getCreditCard()->getCardType();
return $data;
}
}
}
//iterate through auth.net list
//exclude any existing customers (ie. only import their missing payment profiles)
}
private function getCountryCode($country_code)
{
$countries = Cache::get('countries');
$country = $countries->filter(function ($item) use ($country_code) {
return $item->iso_3166_2 == $country_code || $item->iso_3166_3 == $country_code;
})->first();
return (string) $country->id;
}
} }

View File

@ -18,6 +18,7 @@ use App\Models\Payment;
use App\Models\PaymentHash; use App\Models\PaymentHash;
use App\Models\SystemLog; use App\Models\SystemLog;
use App\PaymentDrivers\Authorize\AuthorizeCreditCard; use App\PaymentDrivers\Authorize\AuthorizeCreditCard;
use App\PaymentDrivers\Authorize\AuthorizeCustomer;
use App\PaymentDrivers\Authorize\AuthorizePaymentMethod; use App\PaymentDrivers\Authorize\AuthorizePaymentMethod;
use App\PaymentDrivers\Authorize\RefundTransaction; use App\PaymentDrivers\Authorize\RefundTransaction;
use net\authorize\api\constants\ANetEnvironment; use net\authorize\api\constants\ANetEnvironment;
@ -159,4 +160,9 @@ class AuthorizePaymentDriver extends BaseDriver
{ {
return (new AuthorizePaymentMethod($this))->deletePaymentProfile($token->gateway_customer_reference, $token->token); return (new AuthorizePaymentMethod($this))->deletePaymentProfile($token->gateway_customer_reference, $token->token);
} }
public function import()
{
return (new AuthorizeCustomer($this))->importCustomers();
}
} }