diff --git a/app/Helpers/Invoice/InvoiceSum.php b/app/Helpers/Invoice/InvoiceSum.php index 7ad69538f..99de0fdb9 100644 --- a/app/Helpers/Invoice/InvoiceSum.php +++ b/app/Helpers/Invoice/InvoiceSum.php @@ -155,19 +155,19 @@ class InvoiceSum { $this->total += $this->total_taxes; - if (is_numeric($this->invoice->custom_value1) && $this->invoice->custom_value1 > 0) { + if (is_numeric($this->invoice->custom_value1)) { $this->total += $this->invoice->custom_value1; } - if (is_numeric($this->invoice->custom_value2) && $this->invoice->custom_value2 > 0) { + if (is_numeric($this->invoice->custom_value2)) { $this->total += $this->invoice->custom_value2; } - if (is_numeric($this->invoice->custom_value3) && $this->invoice->custom_value3 > 0) { + if (is_numeric($this->invoice->custom_value3)) { $this->total += $this->invoice->custom_value3; } - if (is_numeric($this->invoice->custom_value4) && $this->invoice->custom_value4 > 0) { + if (is_numeric($this->invoice->custom_value4)) { $this->total += $this->invoice->custom_value4; } diff --git a/app/Helpers/Invoice/InvoiceSumInclusive.php b/app/Helpers/Invoice/InvoiceSumInclusive.php index b13652471..8f6323033 100644 --- a/app/Helpers/Invoice/InvoiceSumInclusive.php +++ b/app/Helpers/Invoice/InvoiceSumInclusive.php @@ -166,19 +166,19 @@ class InvoiceSumInclusive { //$this->total += $this->total_taxes; - if (is_numeric($this->invoice->custom_value1) && $this->invoice->custom_value1 > 0) { + if (is_numeric($this->invoice->custom_value1)) { $this->total += $this->invoice->custom_value1; } - if (is_numeric($this->invoice->custom_value2) && $this->invoice->custom_value2 > 0) { + if (is_numeric($this->invoice->custom_value2)) { $this->total += $this->invoice->custom_value2; } - if (is_numeric($this->invoice->custom_value3) && $this->invoice->custom_value3 > 0) { + if (is_numeric($this->invoice->custom_value3)) { $this->total += $this->invoice->custom_value3; } - if (is_numeric($this->invoice->custom_value4) && $this->invoice->custom_value4 > 0) { + if (is_numeric($this->invoice->custom_value4)) { $this->total += $this->invoice->custom_value4; } diff --git a/app/PaymentDrivers/AbstractPaymentDriver.php b/app/PaymentDrivers/AbstractPaymentDriver.php index e59df6a41..b13da6aa4 100644 --- a/app/PaymentDrivers/AbstractPaymentDriver.php +++ b/app/PaymentDrivers/AbstractPaymentDriver.php @@ -11,15 +11,24 @@ namespace App\PaymentDrivers; +use App\Models\ClientGatewayToken; use App\Models\Payment; +use App\Models\PaymentHash; +use Illuminate\Http\Request; abstract class AbstractPaymentDriver { - abstract public function authorize($payment_method); + abstract public function authorizeView(array $data); - abstract public function purchase($amount, $return_client_response = false); + abstract public function authorizeResponse(Request $request); + + abstract public function processPaymentView(array $data); + + abstract public function processPaymentResponse(Request $request); abstract public function refund(Payment $payment, $refund_amount, $return_client_response = false); + abstract public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash); + abstract public function setPaymentMethod($payment_method_id); } diff --git a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php index 1aa011af3..1dda822d2 100644 --- a/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php +++ b/app/PaymentDrivers/Authorize/AuthorizeCreditCard.php @@ -95,18 +95,31 @@ class AuthorizeCreditCard $data = (new ChargePaymentProfile($this->authorize))->chargeCustomerProfile($cgt->gateway_customer_reference, $cgt->token, $amount); + /*Refactor and push to BaseDriver*/ if ($data['response'] != null && $data['response']->getMessages()->getResultCode() == 'Ok') { - $payment = $this->createPaymentRecord($data, $amount); - $payment->meta = $cgt->meta; - $payment->save(); + + // $response = $data['response']; + + // $payment_record = []; + // $payment_record['amount'] = $amount; + // $payment_record['payment_type'] = PaymentType::CREDIT_CARD_OTHER;; + // $payment_record['transaction_reference'] = $response->getTransactionResponse()->getTransId(); + + // $this->authorize->createPayment($payment_record); - $payment_hash->payment_id = $payment->id; - $payment_hash->save(); + $this->storePayment($payment_hash, $data); + + // $payment = $this->createPaymentRecord($data, $amount); + // $payment->meta = $cgt->meta; + // $payment->save(); + + // $payment_hash->payment_id = $payment->id; + // $payment_hash->save(); - $this->authorize->attachInvoices($payment, $payment_hash); - $payment->service()->updateInvoicePayment($payment_hash); + // $this->authorize->attachInvoices($payment, $payment_hash); + // $payment->service()->updateInvoicePayment($payment_hash); - event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); + // event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); $vars = [ 'hashed_ids' => $invoice->hashed_id, @@ -126,6 +139,12 @@ class AuthorizeCreditCard } } + + + + + + private function handleResponse($data, $request) { $response = $data['response']; @@ -143,16 +162,14 @@ class AuthorizeCreditCard { $amount = array_sum(array_column($payment_hash->invoices(), 'amount')) + $payment_hash->fee_total; - $payment = $this->createPaymentRecord($data, $amount); - - $payment_hash->payment_id = $payment->id; - $payment_hash->save(); + $response = $data['response']; - $this->authorize->attachInvoices($payment, $payment_hash); + $payment_record = []; + $payment_record['amount'] = $amount; + $payment_record['payment_type'] = PaymentType::CREDIT_CARD_OTHER;; + $payment_record['transaction_reference'] = $response->getTransactionResponse()->getTransId(); - $payment->service()->updateInvoicePayment($payment_hash); - - event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); + $payment = $this->authorize->createPayment($payment_record); return $payment; } diff --git a/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php b/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php index ecb88b842..8b1ab194a 100644 --- a/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php +++ b/app/PaymentDrivers/Authorize/AuthorizePaymentMethod.php @@ -16,6 +16,8 @@ use App\Exceptions\GenericPaymentDriverFailure; use App\Models\ClientGatewayToken; use App\Models\GatewayType; 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\CustomerAddressType; use net\authorize\api\contract\v1\CustomerPaymentProfileType; @@ -35,34 +37,37 @@ 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) + public function authorizeResponseView($request) { - $this->payment_method = $data['payment_method_id']; + $data = $request->all(); + + $this->payment_method_id = $data['method']; - switch ($this->payment_method) { + switch ($this->payment_method_id) { case GatewayType::CREDIT_CARD: return $this->authorizeCreditCardResponse($data); break; @@ -111,19 +116,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 5ee521787..a5b3de7ac 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -63,6 +63,38 @@ class AuthorizePaymentDriver extends BaseDriver return $types; } + public function authorizeView($payment_method) + { + return (new AuthorizePaymentMethod($this))->authorizeView(); + } + + public function authorizeResponse($request) + { + return (new AuthorizePaymentMethod($this))->authorizeResponseView($request); + } + + public function processPaymentView($data) + { + return $this->payment_method->processPaymentView($data); + } + + public function processPaymentResponse($request) + { + return $this->payment_method->processPaymentResponse($request); + } + + public function refund(Payment $payment, $refund_amount, $return_client_response = false) + { + return (new RefundTransaction($this))->refundTransaction($payment, $refund_amount); + } + + public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) + { + $this->setPaymentMethod($cgt->gateway_type_id); + + return $this->payment_method->tokenBilling($cgt, $payment_hash); + } + public function init() { error_reporting(E_ALL & ~E_DEPRECATED); @@ -94,59 +126,6 @@ class AuthorizePaymentDriver extends BaseDriver return $env = ANetEnvironment::PRODUCTION; } - public function authorizeView($payment_method) - { - if (count($this->required_fields) > 0) { - return redirect() - ->route('client.profile.edit', ['client_contact' => auth()->user()->hashed_id]) - ->with('missing_required_fields', $this->required_fields); - } - - return (new AuthorizePaymentMethod($this))->authorizeView($payment_method); - } - - public function authorizeResponseView(array $data) - { - return (new AuthorizePaymentMethod($this))->authorizeResponseView($data); - } - - public function authorize($payment_method) - { - return $this->authorizeView($payment_method); - } - - public function processPaymentView($data) - { - if (count($this->required_fields) > 0) { - return redirect() - ->route('client.profile.edit', ['client_contact' => auth()->user()->hashed_id]) - ->with('missing_required_fields', $this->required_fields); - } - - return $this->payment_method->processPaymentView($data); - } - - public function processPaymentResponse($request) - { - if (count($this->required_fields) > 0) { - return redirect() - ->route('client.profile.edit', ['client_contact' => auth()->user()->hashed_id]) - ->with('missing_required_fields', $this->required_fields); - } - - return $this->payment_method->processPaymentResponse($request); - } - - public function purchase($amount, $return_client_response = false) - { - return false; - } - - public function refund(Payment $payment, $refund_amount, $return_client_response = false) - { - return (new RefundTransaction($this))->refundTransaction($payment, $refund_amount); - } - public function findClientGatewayRecord() :?ClientGatewayToken { return ClientGatewayToken::where('client_id', $this->client->id) @@ -154,12 +133,6 @@ class AuthorizePaymentDriver extends BaseDriver ->first(); } - public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) - { - $this->setPaymentMethod($cgt->gateway_type_id); - - return $this->payment_method->tokenBilling($cgt, $payment_hash); - } /** * Detach payment method from Authorize.net. diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index d1f5c3dc7..12c32023e 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -32,7 +32,7 @@ use App\Utils\Traits\SystemLogTrait; use Checkout\Library\Exceptions\CheckoutHttpException; use Exception; use Illuminate\Support\Carbon; -use Illuminate\Support\Str; +use Illuminate\Http\Request; /** * Class BaseDriver. @@ -60,14 +60,13 @@ class BaseDriver extends AbstractPaymentDriver /* The client */ public $client; - /* The initiated gateway driver class*/ + /* The initialized gateway driver class*/ public $payment_method; - /** - * @var PaymentHash - */ + /* PaymentHash */ public $payment_hash; + /* Array of payment methods */ public static $methods = []; /** @var array */ @@ -76,9 +75,7 @@ class BaseDriver extends AbstractPaymentDriver public function __construct(CompanyGateway $company_gateway, Client $client = null, $invitation = false) { $this->company_gateway = $company_gateway; - $this->invitation = $invitation; - $this->client = $client; } @@ -86,23 +83,35 @@ class BaseDriver extends AbstractPaymentDriver * Authorize a payment method. * * Returns a reusable token for storage for future payments - * @param const $payment_method The GatewayType::constant - * @return void Return a view for collecting payment method information + * + * @param array $data + * @return mixed Return a view for collecting payment method information */ - public function authorize($payment_method) - { - } + public function authorizeView(array $data) {} /** - * Executes purchase attempt for a given amount. - * - * @param float $amount The amount to be collected - * @param bool $return_client_response Whether the method needs to return a response (otherwise we assume an unattended payment) - * @return mixed + * The payment authorization response + * + * @param Request $request + * @return mixed Return a response for collecting payment method information */ - public function purchase($amount, $return_client_response = false) - { - } + public function authorizeResponse(Request $request) {} + + /** + * Process a payment + * + * @param array $data + * @return mixed Return a view for the payment + */ + public function processPaymentView(array $data) {} + + /** + * Process payment response + * + * @param Request $request + * @return mixed Return a response for the payment + */ + public function processPaymentResponse(Request $request) {} /** * Executes a refund attempt for a given amount with a transaction_reference. @@ -112,23 +121,30 @@ class BaseDriver extends AbstractPaymentDriver * @param bool $return_client_response Whether the method needs to return a response (otherwise we assume an unattended payment) * @return mixed */ - public function refund(Payment $payment, $amount, $return_client_response = false) - { - } + public function refund(Payment $payment, $amount, $return_client_response = false) {} + + /** + * Process an unattended payment. + * + * @param ClientGatewayToken $cgt The client gateway token object + * @param PaymentHash $payment_hash The Payment hash containing the payment meta data + * @return void The payment response + */ + public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash){} /** * Set the inbound request payment method type for access. * * @param int $payment_method_id The Payment Method ID */ - public function setPaymentMethod($payment_method_id) - { - } + public function setPaymentMethod($payment_method_id){} + + + /************************** Helper methods *************************************/ public function setPaymentHash(PaymentHash $payment_hash) { $this->payment_hash = $payment_hash; - return $this; } @@ -189,17 +205,6 @@ class BaseDriver extends AbstractPaymentDriver return $payment->service()->applyNumber()->save(); } - /** - * Process an unattended payment. - * - * @param ClientGatewayToken $cgt The client gateway token object - * @param PaymentHash $payment_hash The Payment hash containing the payment meta data - * @return void The payment response - */ - public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) - { - } - /** * When a successful payment is made, we need to append the gateway fee * to an invoice. @@ -215,7 +220,7 @@ class BaseDriver extends AbstractPaymentDriver /*Payment invoices*/ $payment_invoices = $payment_hash->invoices(); - // /*Fee charged at gateway*/ + /*Fee charged at gateway*/ $fee_total = $payment_hash->fee_total; // Sum of invoice amounts @@ -265,7 +270,6 @@ class BaseDriver extends AbstractPaymentDriver } } - /** * Store payment method as company gateway token. * diff --git a/app/PaymentDrivers/DriverTemplate.php b/app/PaymentDrivers/DriverTemplate.php new file mode 100644 index 000000000..4e98461d1 --- /dev/null +++ b/app/PaymentDrivers/DriverTemplate.php @@ -0,0 +1,73 @@ + CreditCard::class, //maps GatewayType => Implementation class + ]; + + const SYSTEM_LOG_TYPE = SystemLog::TYPE_STRIPE; + + public function setPaymentMethod($payment_method_id) + { + $class = self::$methods[$payment_method_id]; + $this->payment_method = new $class($this); + return $this; + } + + public function authorizeView(array $data) + { + return $this->payment_method->authorizeView($data); //this is your custom implementation from here + } + + public function authorizeResponse($request) + { + return $this->payment_method->authorizeResponse($request); //this is your custom implementation from here + } + + public function processPaymentView(array $data) + { + return $this->payment_method->paymentView($data); //this is your custom implementation from here + } + + public function processPaymentResponse($request) + { + 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(); //this is your custom implementation from here + } + + public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash) + { + return $this->payment_method->yourTokenBillingImplmentation(); //this is your custom implementation from here + } + +} diff --git a/app/Utils/PhantomJS/Phantom.php b/app/Utils/PhantomJS/Phantom.php index 7748345eb..fee98d2d5 100644 --- a/app/Utils/PhantomJS/Phantom.php +++ b/app/Utils/PhantomJS/Phantom.php @@ -75,6 +75,8 @@ class Phantom $phantom_url = "https://phantomjscloud.com/api/browser/v2/{$key}/?request=%7Burl:%22{$url}%22,renderType:%22pdf%22%7D"; $pdf = CurlUtils::get($phantom_url); + //info($pdf); + Storage::makeDirectory($path, 0775); $instance = Storage::disk(config('filesystems.default'))->put($file_path, $pdf); diff --git a/config/filesystems.php b/config/filesystems.php index 816d65b2b..76d21e4ba 100644 --- a/config/filesystems.php +++ b/config/filesystems.php @@ -60,7 +60,8 @@ return [ 'public' => [ 'driver' => 'local', - 'root' => storage_path('app/public'), + 'root' => 'storage/', + // 'root' => storage_path('app/public'), 'url' => env('APP_URL').'/storage', 'visibility' => 'public', 'permissions' => [ diff --git a/resources/views/portal/ninja2020/gateways/authorize/add_credit_card.blade.php b/resources/views/portal/ninja2020/gateways/authorize/add_credit_card.blade.php index cd725c0f0..fa1f016a9 100644 --- a/resources/views/portal/ninja2020/gateways/authorize/add_credit_card.blade.php +++ b/resources/views/portal/ninja2020/gateways/authorize/add_credit_card.blade.php @@ -17,7 +17,8 @@ @endpush @section('body') -