Working on Authorize.net

This commit is contained in:
David Bomba 2020-06-10 18:05:30 +10:00
parent ef209741d6
commit 15081c2875
7 changed files with 44 additions and 37 deletions

View File

@ -15,6 +15,7 @@ use App\Events\Payment\Methods\MethodDeleted;
use App\Http\Controllers\Controller;
use App\Http\Requests\ClientPortal\CreatePaymentMethodRequest;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\PaymentDrivers\AuthorizePaymentDriver;
use App\Utils\Traits\MakesDates;
use Illuminate\Http\Request;
@ -43,9 +44,12 @@ class PaymentMethodController extends Controller
{
$gateway = auth()->user()->client->getCreditCardGateway();
$auth = new AuthorizePaymentDriver($gateway, auth()->user()->client);
// $auth = new AuthorizePaymentDriver($gateway, auth()->user()->client);
// return $auth->authorizeView(GatewayType::CREDIT_CARD);
return $gateway->driver(auth()->user()->client)->authorizeView(GatewayType::CREDIT_CARD);
return $auth->authorizeView();
// $data = [
// 'gateway' => $gateway,
@ -68,10 +72,12 @@ class PaymentMethodController extends Controller
public function store(Request $request)
{
$gateway = auth()->user()->client->getCreditCardGateway();
return $gateway->driver(auth()->user()->client)->authorizeResponseView($request->all());
$auth = new AuthorizePaymentDriver($gateway, auth()->user()->client);
// $auth = new AuthorizePaymentDriver($gateway, auth()->user()->client);
return $auth->authorizeResponseView($request->all());
// return $auth->authorizeResponseView($request->all());
// return $gateway
// ->driver(auth()->user()->client)

View File

@ -14,7 +14,7 @@ namespace App\PaymentDrivers;
abstract class AbstractPaymentDriver
{
abstract public function authorize();
abstract public function authorize($payment_method);
abstract public function purchase();

View File

@ -28,8 +28,8 @@ use net\authorize\api\controller\CreateCustomerPaymentProfileController;
use net\authorize\api\controller\CreateCustomerProfileController;
/**
* Class BaseDriver
* @package App\PaymentDrivers
* Class AuthorizePaymentMethod
* @package App\PaymentDrivers\AuthorizePaymentMethod
*
*/
class AuthorizePaymentMethod
@ -101,7 +101,7 @@ class AuthorizePaymentMethod
if($client_gateway_token = $this->authorize->findClientGatewayRecord())
$payment_profile = $this->addPaymentMethodToClient($client_gateway_token->gateway_customer_reference, $data);
else{
$gateway_customer_reference = (new AuthorizeCreateCustomer($this->authorize, $this->client))->create($data);
$gateway_customer_reference = (new AuthorizeCreateCustomer($this->authorize, $this->authorize->client))->create($data);
$payment_profile = $this->addPaymentMethodToClient($gateway_customer_reference, $data);
}
@ -119,8 +119,8 @@ class AuthorizePaymentMethod
private function createClientGatewayToken($payment_profile, $gateway_customer_reference)
{
$client_gateway_token = new ClientGatewayToken();
$client_gateway_token->company_id = $this->client->company_id;
$client_gateway_token->client_id = $this->client->id;
$client_gateway_token->company_id = $this->authorize->client->company_id;
$client_gateway_token->client_id = $this->authorize->client->id;
$client_gateway_token->token = $payment_profile->getCustomerPaymentProfileId();
$client_gateway_token->company_gateway_id = $this->authorize->company_gateway->id;
$client_gateway_token->gateway_type_id = $this->payment_method;
@ -158,23 +158,23 @@ class AuthorizePaymentMethod
$paymentOne = new PaymentType();
$paymentOne->setOpaqueData($op);
$contact = $this->client->primary_contact()->first();
$contact = $this->authorize->client->primary_contact()->first();
if($contact){
// Create the Bill To info for new payment type
$billto = new CustomerAddressType();
$billto->setFirstName($contact->present()->first_name());
$billto->setLastName($contact->present()->last_name());
$billto->setCompany($this->client->present()->name());
$billto->setAddress($this->client->address1);
$billto->setCity($this->client->city);
$billto->setState($this->client->state);
$billto->setZip($this->client->postal_code);
$billto->setCompany($this->authorize->client->present()->name());
$billto->setAddress($this->authorize->client->address1);
$billto->setCity($this->authorize->client->city);
$billto->setState($this->authorize->client->state);
$billto->setZip($this->authorize->client->postal_code);
if($this->client->country_id)
$billto->setCountry($this->client->country->name);
if($this->authorize->client->country_id)
$billto->setCountry($this->authorize->client->country->name);
$billto->setPhoneNumber($this->client->phone);
$billto->setPhoneNumber($this->authorize->client->phone);
}
// Create a new Customer Payment Profile object

View File

@ -13,7 +13,9 @@
namespace App\PaymentDrivers;
use App\Models\ClientGatewayToken;
use App\Models\GatewayType;
use App\PaymentDrivers\Authorize\AuthorizeCreditCard;
use App\PaymentDrivers\Authorize\AuthorizePaymentMethod;
use net\authorize\api\constants\ANetEnvironment;
use net\authorize\api\contract\v1\CreateTransactionRequest;
use net\authorize\api\contract\v1\GetMerchantDetailsRequest;
@ -31,6 +33,18 @@ class AuthorizePaymentDriver extends BaseDriver
public $merchant_authentication;
/**
* Returns the gateway types
*/
public function gatewayTypes() :array
{
$types = [
GatewayType::CREDIT_CARD,
];
return $types;
}
public function init()
{
error_reporting (E_ALL & ~E_DEPRECATED);
@ -70,23 +84,10 @@ class AuthorizePaymentDriver extends BaseDriver
return (new AuthorizePaymentMethod($this))->authorizeView($payment_method);
}
public function authorizeResponse($payment_method, array $data)
public function authorizeResponseView(array $data)
{
// <input type="hidden" name="is_default" id="is_default">
// <input type="hidden" name="dataValue" id="dataValue" />
// <input type="hidden" name="dataDescriptor" id="dataDescriptor" />
// $client_gateway_token = new ClientGatewayToken();
// $client_gateway_token->company_id = $this->stripe->client->company->id;
// $client_gateway_token->client_id = $this->stripe->client->id;
// $client_gateway_token->token = $payment_method;
// $client_gateway_token->company_gateway_id = $this->stripe->company_gateway->id;
// $client_gateway_token->gateway_type_id = $gateway_type_id;
// $client_gateway_token->gateway_customer_reference = $customer->id;
// $client_gateway_token->meta = $payment_meta;
// $client_gateway_token->save();
return (new AuthorizePaymentMethod($this))->authorizeResponseView($data['gateway_type_id'], $data);
}

View File

@ -55,7 +55,7 @@ class BaseDriver extends AbstractPaymentDriver
}
public function authorize() {}
public function authorize($payment_method) {}
public function purchase() {}

View File

@ -11,7 +11,7 @@ class PaymentLibrariesSeeder extends Seeder
Eloquent::unguard();
$gateways = [
['id' => 1, 'name' => 'Authorize.Net AIM', 'provider' => 'AuthorizeNet_AIM', 'sort_order' => 5, 'key' => '3b6621f970ab18887c4f6dca78d3f8bb', 'fields' => '{"apiLoginId":"","transactionKey":"","testMode":false,"developerMode":false,"liveEndpoint":"https:\/\/api2.authorize.net\/xml\/v1\/request.api","developerEndpoint":"https:\/\/apitest.authorize.net\/xml\/v1\/request.api"}
['id' => 1, 'name' => 'Authorize.Net', 'provider' => 'Authorize', 'sort_order' => 5, 'key' => '3b6621f970ab18887c4f6dca78d3f8bb', 'fields' => '{"apiLoginId":"","transactionKey":"","testMode":false,"developerMode":false,"liveEndpoint":"https:\/\/api2.authorize.net\/xml\/v1\/request.api","developerEndpoint":"https:\/\/apitest.authorize.net\/xml\/v1\/request.api"}
'],
['id' => 2, 'name' => 'CardSave', 'provider' => 'CardSave', 'key' => '46c5c1fed2c43acf4f379bae9c8b9f76', 'fields' => '{"merchantId":"","password":""}
'],

View File

@ -319,7 +319,7 @@ class RandomDataSeeder extends Seeder
$cg = new CompanyGateway;
$cg->company_id = $company->id;
$cg->user_id = $user->id;
$cg->gateway_key = '2f71dc17b0158ac30a7ae0839799e888';
$cg->gateway_key = '3b6621f970ab18887c4f6dca78d3f8bb';
$cg->require_cvv = true;
$cg->show_billing_address = true;
$cg->show_shipping_address = true;