From be952866908398ad3d515ca8b877a4a6a279ed13 Mon Sep 17 00:00:00 2001 From: cnohall Date: Thu, 13 Mar 2025 09:02:40 +0900 Subject: [PATCH] Init --- app/Http/Controllers/CompanyGatewayController.php | 5 +++-- app/PaymentDrivers/AuthorizePaymentDriver.php | 4 ++-- app/PaymentDrivers/BaseDriver.php | 14 +++++++------- app/PaymentDrivers/BlockonomicsPaymentDriver.php | 9 ++++----- app/PaymentDrivers/BraintreePaymentDriver.php | 6 +++--- app/PaymentDrivers/CBAPowerBoardPaymentDriver.php | 4 ++-- app/PaymentDrivers/CheckoutComPaymentDriver.php | 6 +++--- app/PaymentDrivers/EwayPaymentDriver.php | 5 +++-- app/PaymentDrivers/FortePaymentDriver.php | 6 +++--- app/PaymentDrivers/GoCardlessPaymentDriver.php | 9 +++++---- app/PaymentDrivers/MolliePaymentDriver.php | 6 +++--- .../PayPal/PayPalBasePaymentDriver.php | 6 +++--- app/PaymentDrivers/PaytracePaymentDriver.php | 8 +++++--- app/PaymentDrivers/SquarePaymentDriver.php | 4 ++-- app/PaymentDrivers/StripePaymentDriver.php | 8 ++++---- 15 files changed, 52 insertions(+), 48 deletions(-) diff --git a/app/Http/Controllers/CompanyGatewayController.php b/app/Http/Controllers/CompanyGatewayController.php index c0a4efcfff..63628073a6 100644 --- a/app/Http/Controllers/CompanyGatewayController.php +++ b/app/Http/Controllers/CompanyGatewayController.php @@ -583,8 +583,9 @@ class CompanyGatewayController extends BaseController public function test(TestCompanyGatewayRequest $request, CompanyGateway $company_gateway) { - - return response()->json(['message' => $company_gateway->driver()->auth() ? 'true' : 'false'], 200); + $message = $company_gateway->driver()->auth(); + $is_ok = $message === 'ok'; + return response()->json(['message' => $message], $is_ok ? 200 : 400); } diff --git a/app/PaymentDrivers/AuthorizePaymentDriver.php b/app/PaymentDrivers/AuthorizePaymentDriver.php index 43af19cbdc..b3c38d4652 100644 --- a/app/PaymentDrivers/AuthorizePaymentDriver.php +++ b/app/PaymentDrivers/AuthorizePaymentDriver.php @@ -205,8 +205,8 @@ class AuthorizePaymentDriver extends BaseDriver return $this->import(); } - public function auth(): bool + public function auth(): string { - return $this->init()->getPublicClientKey() ?? false; + return $this->init()->getPublicClientKey() ? 'ok' : 'error'; } } diff --git a/app/PaymentDrivers/BaseDriver.php b/app/PaymentDrivers/BaseDriver.php index 1c161cc0ce..6074a9c350 100644 --- a/app/PaymentDrivers/BaseDriver.php +++ b/app/PaymentDrivers/BaseDriver.php @@ -58,7 +58,7 @@ class BaseDriver extends AbstractPaymentDriver /** * Indicates if returning responses should be headless or classic redirect. - * + * * @var bool */ public bool $headless = false; @@ -181,7 +181,7 @@ class BaseDriver extends AbstractPaymentDriver } - public function setHeadless(bool $headless): self + public function setHeadless(bool $headless): self { $this->headless = $headless; @@ -418,7 +418,7 @@ class BaseDriver extends AbstractPaymentDriver } $invoice = $this->payment_hash->fee_invoice; - + if(!$invoice) return; @@ -434,7 +434,7 @@ class BaseDriver extends AbstractPaymentDriver $unconfirmed_fee_count = collect($invoice->line_items) ->where('type_id', '3') ->count(); - + if ($unconfirmed_fee_count == 0) { nlog("apparently no fee, so injecting here!"); @@ -912,11 +912,11 @@ class BaseDriver extends AbstractPaymentDriver /** * Stub for checking authentication. * - * @return bool + * @return string */ - public function auth(): bool + public function auth(): string { - return true; + return 'ok'; } public function importCustomers() diff --git a/app/PaymentDrivers/BlockonomicsPaymentDriver.php b/app/PaymentDrivers/BlockonomicsPaymentDriver.php index f6675fe016..d7586e4c76 100644 --- a/app/PaymentDrivers/BlockonomicsPaymentDriver.php +++ b/app/PaymentDrivers/BlockonomicsPaymentDriver.php @@ -145,20 +145,19 @@ class BlockonomicsPaymentDriver extends BaseDriver return $this->payment_method->refund($payment, $amount); //this is your custom implementation from here } - public function auth(): bool + public function auth(): string { try { - $api_key = $this->company_gateway->getConfigField('apiKey'); $url = $this->NEW_ADDRESS_URL . '?reset=1'; $response = Http::withToken($api_key) ->post($url, []); if($response->successful()) { - return true; + return 'ok'; } - return false; + return 'error'; } catch (\Exception $e) { - return false; + return $e->getMessage(); } } diff --git a/app/PaymentDrivers/BraintreePaymentDriver.php b/app/PaymentDrivers/BraintreePaymentDriver.php index 302061f469..87b89c9cd1 100644 --- a/app/PaymentDrivers/BraintreePaymentDriver.php +++ b/app/PaymentDrivers/BraintreePaymentDriver.php @@ -333,18 +333,18 @@ class BraintreePaymentDriver extends BaseDriver return response()->json([], 200); } - public function auth(): bool + public function auth(): string { try { $ct = $this->init()->gateway->clientToken()->generate(); - return true; + return 'ok'; } catch (\Exception $e) { } - return false; + return 'error'; } private function find(string $customer_id = '') diff --git a/app/PaymentDrivers/CBAPowerBoardPaymentDriver.php b/app/PaymentDrivers/CBAPowerBoardPaymentDriver.php index 00cfb6cb52..7a3f440533 100644 --- a/app/PaymentDrivers/CBAPowerBoardPaymentDriver.php +++ b/app/PaymentDrivers/CBAPowerBoardPaymentDriver.php @@ -190,13 +190,13 @@ class CBAPowerBoardPaymentDriver extends BaseDriver { } - public function auth(): bool + public function auth(): string { $this->init(); $this->settings()->updateSettings(); - return true; + return 'ok'; } diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index 0319f57511..494b52da22 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -538,15 +538,15 @@ class CheckoutComPaymentDriver extends BaseDriver // Gateway doesn't support this feature. } - public function auth(): bool + public function auth(): string { try { $this->init()->gateway->getCustomersClient('x'); - return true; + return 'ok'; } catch (\Exception $e) { } - return false; + return 'error'; } private function getToken(string $token, $gateway_customer_reference) diff --git a/app/PaymentDrivers/EwayPaymentDriver.php b/app/PaymentDrivers/EwayPaymentDriver.php index 3298cae72f..21f761d36a 100644 --- a/app/PaymentDrivers/EwayPaymentDriver.php +++ b/app/PaymentDrivers/EwayPaymentDriver.php @@ -212,12 +212,13 @@ class EwayPaymentDriver extends BaseDriver return $fields; } - public function auth(): bool + public function auth(): string { $response = $this->init()->eway->queryTransaction('xx'); - return (bool) count($response->getErrors()) == 0; + $message = (bool) count($response->getErrors()) == 0 ? 'ok' : 'error'; + return $message; } diff --git a/app/PaymentDrivers/FortePaymentDriver.php b/app/PaymentDrivers/FortePaymentDriver.php index a456bd708c..3021f1603b 100644 --- a/app/PaymentDrivers/FortePaymentDriver.php +++ b/app/PaymentDrivers/FortePaymentDriver.php @@ -112,7 +112,7 @@ class FortePaymentDriver extends BaseDriver CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => 'POST', CURLOPT_POSTFIELDS => '{ - "action":"reverse", + "action":"reverse", "authorization_amount":'.$amount.', "original_transaction_id":"'.$payment->transaction_reference.'", "authorization_code": "9ZQ754" @@ -193,7 +193,7 @@ class FortePaymentDriver extends BaseDriver //////////////////////////////////////////// // DB /////////////////////////////////////////// - public function auth(): bool + public function auth(): string { $forte_base_uri = "https://sandbox.forte.net/api/v3/"; @@ -210,7 +210,7 @@ class FortePaymentDriver extends BaseDriver ->withHeaders(['X-Forte-Auth-Organization-Id' => $forte_organization_id]) ->get("{$forte_base_uri}/organizations/{$forte_organization_id}/locations/{$forte_location_id}/customers/"); - return $response->successful(); + return $response->successful() ? 'ok' : 'error'; } diff --git a/app/PaymentDrivers/GoCardlessPaymentDriver.php b/app/PaymentDrivers/GoCardlessPaymentDriver.php index 6e0209dc58..6ab9f01b1c 100644 --- a/app/PaymentDrivers/GoCardlessPaymentDriver.php +++ b/app/PaymentDrivers/GoCardlessPaymentDriver.php @@ -98,7 +98,7 @@ class GoCardlessPaymentDriver extends BaseDriver public function init(): self { $environment = $this->company_gateway->getConfigField('testMode') ? \GoCardlessPro\Environment::SANDBOX : \GoCardlessPro\Environment::LIVE; - + if ($this->company_gateway->getConfigField('oauth2')) { $environment = \GoCardlessPro\Environment::LIVE; } @@ -568,15 +568,16 @@ class GoCardlessPaymentDriver extends BaseDriver return render('gateways.gocardless.verification'); } - public function auth(): bool + + public function auth(): string { try { $customers = $this->init()->gateway->customers()->list(); - return true; + return 'ok'; } catch (\Exception $e) { } - return false; + return 'error'; } } diff --git a/app/PaymentDrivers/MolliePaymentDriver.php b/app/PaymentDrivers/MolliePaymentDriver.php index a4276e63a9..7ef0db39f1 100644 --- a/app/PaymentDrivers/MolliePaymentDriver.php +++ b/app/PaymentDrivers/MolliePaymentDriver.php @@ -427,18 +427,18 @@ class MolliePaymentDriver extends BaseDriver return \number_format((float) $amount, 2, '.', ''); } - public function auth(): bool + public function auth(): string { $this->init(); try { $p = $this->gateway->payments->page(); - return true; + return 'ok'; } catch (\Exception $e) { } - return false; + return 'error'; } } diff --git a/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php b/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php index dd88fc9dbd..501563ad5f 100644 --- a/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php +++ b/app/PaymentDrivers/PayPal/PayPalBasePaymentDriver.php @@ -499,17 +499,17 @@ class PayPalBasePaymentDriver extends BaseDriver } - public function auth(): bool + public function auth(): string { try { $this->init()->getClientToken(); - return true; + return 'ok'; } catch (\Exception $e) { } - return false; + return 'error'; } public function importCustomers() diff --git a/app/PaymentDrivers/PaytracePaymentDriver.php b/app/PaymentDrivers/PaytracePaymentDriver.php index dc2b6c3628..c03ec1ec1b 100644 --- a/app/PaymentDrivers/PaytracePaymentDriver.php +++ b/app/PaymentDrivers/PaytracePaymentDriver.php @@ -307,16 +307,18 @@ class PaytracePaymentDriver extends BaseDriver return $fields; } - public function auth(): bool + + + public function auth(): string { try { $this->init()->generateAuthHeaders() && strlen($this->company_gateway->getConfigField('integratorId')) > 2; - return true; + return 'ok'; } catch (\Exception $e) { } - return false; + return 'error'; } diff --git a/app/PaymentDrivers/SquarePaymentDriver.php b/app/PaymentDrivers/SquarePaymentDriver.php index d130cc6ca8..c948637907 100644 --- a/app/PaymentDrivers/SquarePaymentDriver.php +++ b/app/PaymentDrivers/SquarePaymentDriver.php @@ -435,7 +435,7 @@ class SquarePaymentDriver extends BaseDriver return $amount; } - public function auth(): bool + public function auth(): string { $api_response = $this->init() @@ -444,7 +444,7 @@ class SquarePaymentDriver extends BaseDriver ->listCustomers(); - return (bool) count($api_response->getErrors()) == 0; + return (bool) count($api_response->getErrors()) == 0 ? 'ok' : 'error'; } diff --git a/app/PaymentDrivers/StripePaymentDriver.php b/app/PaymentDrivers/StripePaymentDriver.php index eb48abc1f9..938e0e9a50 100644 --- a/app/PaymentDrivers/StripePaymentDriver.php +++ b/app/PaymentDrivers/StripePaymentDriver.php @@ -1035,25 +1035,25 @@ class StripePaymentDriver extends BaseDriver implements SupportsHeadlessInterfac }, $string); } - public function auth(): bool + public function auth(): string { $this->init(); try { $this->verifyConnect(); - return true; + return 'ok'; } catch (\Exception $e) { } - return false; + return 'error'; } /** * @inheritDoc */ - public function setHeadless(bool $headless): self + public function setHeadless(bool $headless): self { $this->headless = $headless;