2024-09-06 06:26:13 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\PaymentDrivers;
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Payment;
|
|
|
|
use App\Models\SystemLog;
|
|
|
|
use App\Utils\HtmlEngine;
|
2024-09-06 07:15:33 +02:00
|
|
|
use App\Models\GatewayType;
|
|
|
|
use App\Models\PaymentHash;
|
|
|
|
use App\Models\PaymentType;
|
|
|
|
use App\Jobs\Util\SystemLogger;
|
2024-09-06 06:26:13 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2024-09-06 07:15:33 +02:00
|
|
|
use App\Models\ClientGatewayToken;
|
2024-09-06 14:55:56 +02:00
|
|
|
use Illuminate\Support\Facades\Http;
|
2024-09-06 07:15:33 +02:00
|
|
|
use App\PaymentDrivers\CBAPowerBoard\CreditCard;
|
2024-09-07 01:34:53 +02:00
|
|
|
use App\PaymentDrivers\CBAPowerBoard\Customer;
|
2024-09-10 00:40:40 +02:00
|
|
|
use App\PaymentDrivers\CBAPowerBoard\Settings;
|
2024-09-06 06:26:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class CBAPowerBoardPaymentDriver.
|
|
|
|
*/
|
|
|
|
class CBAPowerBoardPaymentDriver extends BaseDriver
|
|
|
|
{
|
|
|
|
use MakesHash;
|
|
|
|
|
|
|
|
public $token_billing = true;
|
|
|
|
|
|
|
|
public $can_authorise_credit_card = false;
|
|
|
|
|
|
|
|
public $refundable = true;
|
|
|
|
|
2024-09-06 11:15:08 +02:00
|
|
|
public string $api_endpoint = 'https://api.powerboard.commbank.com.au';
|
2024-09-06 07:15:33 +02:00
|
|
|
|
2024-09-06 10:31:00 +02:00
|
|
|
public string $widget_endpoint = 'https://widget.powerboard.commbank.com.au/sdk/latest/widget.umd.min.js';
|
|
|
|
|
|
|
|
public string $environment = 'production_cba';
|
2024-09-06 06:34:54 +02:00
|
|
|
|
2024-09-07 01:34:53 +02:00
|
|
|
public const SYSTEM_LOG_TYPE = SystemLog::TYPE_POWERBOARD;
|
|
|
|
|
2024-09-06 07:15:33 +02:00
|
|
|
public static $methods = [
|
|
|
|
GatewayType::CREDIT_CARD => CreditCard::class,
|
|
|
|
];
|
2024-09-06 06:26:13 +02:00
|
|
|
/**
|
|
|
|
* Returns the gateway types.
|
|
|
|
*/
|
|
|
|
public function gatewayTypes(): array
|
|
|
|
{
|
2024-09-10 01:49:17 +02:00
|
|
|
|
|
|
|
$types = [];
|
|
|
|
|
|
|
|
if ($this->client
|
|
|
|
&& isset($this->client->country)
|
|
|
|
&& in_array($this->client->country->iso_3166_3, ['AUS'])
|
|
|
|
&& in_array($this->client->currency()->code, ['AUD'])
|
|
|
|
) {
|
|
|
|
$types[] = GatewayType::CREDIT_CARD;
|
|
|
|
}
|
2024-09-06 06:26:13 +02:00
|
|
|
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
2024-09-06 07:15:33 +02:00
|
|
|
public function init(): self
|
2024-09-06 06:26:13 +02:00
|
|
|
{
|
2024-09-06 07:15:33 +02:00
|
|
|
if($this->company_gateway->getConfigField('testMode')) {
|
|
|
|
$this->widget_endpoint = 'https://widget.preproduction.powerboard.commbank.com.au/sdk/latest/widget.umd.min.js';
|
2024-09-06 11:15:08 +02:00
|
|
|
$this->api_endpoint = 'https://api.preproduction.powerboard.commbank.com.au';
|
2024-09-06 10:31:00 +02:00
|
|
|
$this->environment = 'preproduction_cba';
|
|
|
|
}
|
2024-09-06 06:26:13 +02:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setPaymentMethod($payment_method_id)
|
|
|
|
{
|
2024-09-06 10:31:00 +02:00
|
|
|
|
|
|
|
$class = self::$methods[$payment_method_id];
|
|
|
|
|
|
|
|
$this->payment_method = new $class($this);
|
2024-09-06 06:26:13 +02:00
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2024-09-09 11:56:47 +02:00
|
|
|
/**
|
|
|
|
* Proxy method to pass the data into payment method authorizeView().
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|mixed
|
|
|
|
*/
|
|
|
|
public function authorizeView(array $data)
|
|
|
|
{
|
|
|
|
$this->init();
|
|
|
|
|
|
|
|
return $this->payment_method->authorizeView($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processes the gateway response for credit card authorization.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\RedirectResponse|mixed
|
|
|
|
*/
|
|
|
|
public function authorizeResponse($request)
|
|
|
|
{
|
|
|
|
return $this->payment_method->authorizeResponse($request);
|
|
|
|
}
|
|
|
|
|
2024-09-06 06:26:13 +02:00
|
|
|
/**
|
|
|
|
* View for displaying custom content of the driver.
|
|
|
|
*
|
|
|
|
* @param array $data
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function processPaymentView($data)
|
|
|
|
{
|
2024-09-06 10:31:00 +02:00
|
|
|
$this->init();
|
|
|
|
|
2024-09-06 06:26:13 +02:00
|
|
|
return $this->payment_method->paymentView($data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Processing method for payment. Should never be reached with this driver.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function processPaymentResponse($request)
|
|
|
|
{
|
|
|
|
return $this->payment_method->paymentResponse($request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Detach payment method from custom payment driver.
|
|
|
|
*
|
|
|
|
* @param ClientGatewayToken $token
|
2024-09-06 15:14:21 +02:00
|
|
|
* @return bool
|
2024-09-06 06:26:13 +02:00
|
|
|
*/
|
2024-09-06 14:55:56 +02:00
|
|
|
public function detach(ClientGatewayToken $token): bool
|
2024-09-06 06:26:13 +02:00
|
|
|
{
|
|
|
|
// Driver doesn't support this feature.
|
2024-09-06 15:14:21 +02:00
|
|
|
return true;
|
2024-09-06 06:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function refund(Payment $payment, $amount, $return_client_response = false)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processWebhookRequest($request)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getClientRequiredFields(): array
|
|
|
|
{
|
2024-09-17 02:05:19 +02:00
|
|
|
$fields = [];
|
|
|
|
|
|
|
|
if ($this->company_gateway->require_client_name) {
|
|
|
|
$fields[] = ['name' => 'client_name', 'label' => ctrans('texts.client_name'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
}
|
|
|
|
|
2024-09-17 02:16:10 +02:00
|
|
|
$fields[] = ['name' => 'contact_first_name', 'label' => ctrans('texts.first_name'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
$fields[] = ['name' => 'contact_last_name', 'label' => ctrans('texts.last_name'), 'type' => 'text', 'validation' => 'required'];
|
|
|
|
|
2024-09-17 02:05:19 +02:00
|
|
|
return $fields;
|
2024-09-06 06:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function tokenBilling(ClientGatewayToken $cgt, PaymentHash $payment_hash)
|
|
|
|
{
|
2024-10-10 03:41:55 +02:00
|
|
|
|
|
|
|
$this->init();
|
|
|
|
|
|
|
|
$this->setPaymentMethod($cgt->gateway_type_id);
|
|
|
|
$this->setPaymentHash($payment_hash);
|
|
|
|
$this->setClient($cgt->client);
|
|
|
|
|
|
|
|
return $this->payment_method->tokenBilling($cgt, false);
|
|
|
|
|
2024-09-06 06:26:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function importCustomers()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public function auth(): bool
|
|
|
|
{
|
|
|
|
$this->init();
|
|
|
|
|
2024-09-24 23:22:10 +02:00
|
|
|
$this->settings()->updateSettings();
|
|
|
|
|
2024-09-06 07:15:33 +02:00
|
|
|
return true;
|
2024-09-06 06:26:13 +02:00
|
|
|
|
|
|
|
|
|
|
|
}
|
2024-09-06 11:15:08 +02:00
|
|
|
|
|
|
|
public function gatewayRequest(string $uri, string $verb, array $payload, array $headers = [])
|
|
|
|
{
|
2024-09-07 01:34:53 +02:00
|
|
|
$this->init();
|
|
|
|
|
2024-09-06 11:15:08 +02:00
|
|
|
$r = Http::withHeaders($this->getHeaders($headers))
|
|
|
|
->{$verb}($this->api_endpoint.$uri, $payload);
|
2024-09-07 01:34:53 +02:00
|
|
|
|
|
|
|
nlog($r->body());
|
|
|
|
|
|
|
|
return $r;
|
2024-09-06 11:15:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getHeaders(array $headers = []): array
|
|
|
|
{
|
|
|
|
return array_merge([
|
|
|
|
'x-user-secret-key' => $this->company_gateway->getConfigField('secretKey'),
|
|
|
|
'Content-Type' => 'application/json',
|
|
|
|
],
|
|
|
|
$headers);
|
|
|
|
}
|
|
|
|
|
2024-09-07 01:34:53 +02:00
|
|
|
public function customer(): Customer
|
|
|
|
{
|
|
|
|
return new Customer($this);
|
|
|
|
}
|
2024-09-10 00:40:40 +02:00
|
|
|
|
|
|
|
public function settings(): Settings
|
|
|
|
{
|
|
|
|
return new Settings($this);
|
|
|
|
}
|
|
|
|
}
|