diff --git a/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php b/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php index b2bc21c399..b344283c65 100644 --- a/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php +++ b/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php @@ -15,8 +15,9 @@ namespace App\PaymentDrivers\Authorize; use App\Exceptions\GenericPaymentDriverFailure; use App\Models\ClientGatewayToken; use App\Models\GatewayType; -use App\PaymentDrivers\Authorize\AuthorizeCreateCustomer; use App\PaymentDrivers\AuthorizePaymentDriver; +use App\PaymentDrivers\Authorize\AuthorizeCreateCustomer; +use App\PaymentDrivers\Authorize\AuthorizeCreditCard; use net\authorize\api\contract\v1\CreateCustomerPaymentProfileRequest; use net\authorize\api\contract\v1\CreateCustomerProfileRequest; use net\authorize\api\contract\v1\CustomerAddressType; @@ -39,27 +40,28 @@ class AuthorizePaymentMethod public $payment_method; + private $payment_method_id; + public function __construct(AuthorizePaymentDriver $authorize) { $this->authorize = $authorize; } - public function authorizeView($payment_method) + public function authorizeView() { - $this->payment_method = $payment_method; + if($this->authorize->payment_method instanceof AuthorizeCreditCard){ - switch ($payment_method) { - case GatewayType::CREDIT_CARD: - return $this->authorizeCreditCard(); - break; - case GatewayType::BANK_TRANSFER: - return $this->authorizeBankTransfer(); - break; + $this->payment_method_id = GatewayType::CREDIT_CARD; + + return $this->authorizeCreditCard(); - default: - // code... - break; } + + + // case GatewayType::BANK_TRANSFER: + // return $this->authorizeBankTransfer(); + // break; + } public function authorizeResponseView($data) @@ -115,19 +117,17 @@ class AuthorizePaymentMethod public function createClientGatewayToken($payment_profile, $gateway_customer_reference) { - // info(print_r($payment_profile,1)); - $client_gateway_token = new ClientGatewayToken(); - $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->getPaymentProfile()->getCustomerPaymentProfileId(); - $client_gateway_token->company_gateway_id = $this->authorize->company_gateway->id; - $client_gateway_token->gateway_type_id = $this->payment_method; - $client_gateway_token->gateway_customer_reference = $gateway_customer_reference; - $client_gateway_token->meta = $this->buildPaymentMethod($payment_profile); - $client_gateway_token->save(); + $data = []; + $additonal = []; - return $client_gateway_token; + $data['token'] = $payment_profile->getPaymentProfile()->getCustomerPaymentProfileId(); + $data['payment_method_id'] = $this->payment_method_id; + $data['payment_meta'] = $this->buildPaymentMethod($payment_profile); + + $additional['gateway_customer_reference'] = $gateway_customer_reference; + + $this->authorize->storeGatewayToken($data, $additional); } public function buildPaymentMethod($payment_profile) diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index 41c2348089..d8dc9b201a 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -69,7 +69,7 @@ class AuthorizePaymentDriver extends BaseDriver public function authorizeView($payment_method) { - return (new AuthorizePaymentMethod($this))->authorizeView($payment_method); + return (new AuthorizePaymentMethod($this))->authorizeView(); } public function authorizeResponseView(array $data) diff --git a/app/PaymentDrivers/DriverTemplate.php b/app/PaymentDrivers/DriverTemplate.php index e5575f6db3..4e98461d1d 100644 --- a/app/PaymentDrivers/DriverTemplate.php +++ b/app/PaymentDrivers/DriverTemplate.php @@ -13,7 +13,6 @@ namespace App\PaymentDrivers; use App\Utils\Traits\MakesHash; - class YourGatewayPaymentDriver extends BaseDriver { use MakesHash; @@ -61,41 +60,14 @@ class YourGatewayPaymentDriver extends BaseDriver return $this->payment_method->paymentResponse($request); //this is your custom implementation from here } - public function refund(Payment $payment, $amount, $return_client_response = false) { - return $this->payment_method->yourRefundImplementationHere(); + return $this->payment_method->yourRefundImplementationHere(); //this is your custom implementation from here } public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) { - return $this->payment_method->yourTokenBillingImplmentation(); + return $this->payment_method->yourTokenBillingImplmentation(); //this is your custom implementation from here } - - /** - * Creates a payment record for the given - * data array. - * - * @param array $data An array of payment attributes - * @param float $amount The amount of the payment - * @return Payment The payment object - */ - public function createPaymentRecord($data, $amount): ?Payment - { - $payment = PaymentFactory::create($this->client->company_id, $this->client->user_id); - $payment->client_id = $this->client->id; - $payment->company_gateway_id = $this->company_gateway->id; - $payment->status_id = Payment::STATUS_COMPLETED; - $payment->gateway_type_id = $data['gateway_type_id']; - $payment->type_id = $data['type_id']; - $payment->currency_id = $this->client->getSetting('currency_id'); - $payment->date = Carbon::now(); - $payment->transaction_reference = $data['transaction_reference']; - $payment->amount = $amount; - $payment->save(); - - return $payment->service()->applyNumber()->save(); - } - }