Working on authorize refactor

This commit is contained in:
David Bomba 2020-11-26 13:30:36 +11:00
parent 56ac6c7b1f
commit 4888a7dc4f
3 changed files with 27 additions and 55 deletions

View File

@ -15,8 +15,9 @@ namespace App\PaymentDrivers\Authorize;
use App\Exceptions\GenericPaymentDriverFailure; use App\Exceptions\GenericPaymentDriverFailure;
use App\Models\ClientGatewayToken; use App\Models\ClientGatewayToken;
use App\Models\GatewayType; use App\Models\GatewayType;
use App\PaymentDrivers\Authorize\AuthorizeCreateCustomer;
use App\PaymentDrivers\AuthorizePaymentDriver; 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\CreateCustomerPaymentProfileRequest;
use net\authorize\api\contract\v1\CreateCustomerProfileRequest; use net\authorize\api\contract\v1\CreateCustomerProfileRequest;
use net\authorize\api\contract\v1\CustomerAddressType; use net\authorize\api\contract\v1\CustomerAddressType;
@ -39,27 +40,28 @@ class AuthorizePaymentMethod
public $payment_method; public $payment_method;
private $payment_method_id;
public function __construct(AuthorizePaymentDriver $authorize) public function __construct(AuthorizePaymentDriver $authorize)
{ {
$this->authorize = $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) { $this->payment_method_id = GatewayType::CREDIT_CARD;
case GatewayType::CREDIT_CARD:
return $this->authorizeCreditCard(); return $this->authorizeCreditCard();
break;
case GatewayType::BANK_TRANSFER:
return $this->authorizeBankTransfer();
break;
default:
// code...
break;
} }
// case GatewayType::BANK_TRANSFER:
// return $this->authorizeBankTransfer();
// break;
} }
public function authorizeResponseView($data) public function authorizeResponseView($data)
@ -115,19 +117,17 @@ class AuthorizePaymentMethod
public function createClientGatewayToken($payment_profile, $gateway_customer_reference) public function createClientGatewayToken($payment_profile, $gateway_customer_reference)
{ {
// info(print_r($payment_profile,1));
$client_gateway_token = new ClientGatewayToken(); $data = [];
$client_gateway_token->company_id = $this->authorize->client->company_id; $additonal = [];
$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();
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) public function buildPaymentMethod($payment_profile)

View File

@ -69,7 +69,7 @@ class AuthorizePaymentDriver extends BaseDriver
public function authorizeView($payment_method) public function authorizeView($payment_method)
{ {
return (new AuthorizePaymentMethod($this))->authorizeView($payment_method); return (new AuthorizePaymentMethod($this))->authorizeView();
} }
public function authorizeResponseView(array $data) public function authorizeResponseView(array $data)

View File

@ -13,7 +13,6 @@ namespace App\PaymentDrivers;
use App\Utils\Traits\MakesHash; use App\Utils\Traits\MakesHash;
class YourGatewayPaymentDriver extends BaseDriver class YourGatewayPaymentDriver extends BaseDriver
{ {
use MakesHash; use MakesHash;
@ -61,41 +60,14 @@ class YourGatewayPaymentDriver extends BaseDriver
return $this->payment_method->paymentResponse($request); //this is your custom implementation from here return $this->payment_method->paymentResponse($request); //this is your custom implementation from here
} }
public function refund(Payment $payment, $amount, $return_client_response = false) 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) 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();
}
} }