diff --git a/app/Http/Controllers/ClientPortal/PaymentMethodController.php b/app/Http/Controllers/ClientPortal/PaymentMethodController.php index b068605ee9e2..830351535339 100644 --- a/app/Http/Controllers/ClientPortal/PaymentMethodController.php +++ b/app/Http/Controllers/ClientPortal/PaymentMethodController.php @@ -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) diff --git a/app/PaymentDrivers/AbstractPaymentDriver.php b/app/PaymentDrivers/AbstractPaymentDriver.php index ea7633f742e1..432b50af9de6 100644 --- a/app/PaymentDrivers/AbstractPaymentDriver.php +++ b/app/PaymentDrivers/AbstractPaymentDriver.php @@ -14,7 +14,7 @@ namespace App\PaymentDrivers; abstract class AbstractPaymentDriver { - abstract public function authorize(); + abstract public function authorize($payment_method); abstract public function purchase(); diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php similarity index 88% rename from app/PaymentDrivers/Authorize/AuthorizeCreditCard.php rename to app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php index 6a04bc844c4f..16ec873c1343 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php @@ -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 diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index 4e44b3fb62e0..530c9bbdce4e 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -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) { - // - // - // - - - // $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); } diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 15eef40c7493..18a2d62f50ab 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -55,7 +55,7 @@ class BaseDriver extends AbstractPaymentDriver } - public function authorize() {} + public function authorize($payment_method) {} public function purchase() {} diff --git a/database/seeds/PaymentLibrariesSeeder.php b/database/seeds/PaymentLibrariesSeeder.php index caa4f32b92b7..c3960d1d2853 100644 --- a/database/seeds/PaymentLibrariesSeeder.php +++ b/database/seeds/PaymentLibrariesSeeder.php @@ -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":""} '], diff --git a/database/seeds/RandomDataSeeder.php b/database/seeds/RandomDataSeeder.php index 6a1f4464f8bb..c4eed11060dc 100644 --- a/database/seeds/RandomDataSeeder.php +++ b/database/seeds/RandomDataSeeder.php @@ -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;