From 87d14dd052ec3bb238fe1ce0424f316e0b0af53f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 19 Aug 2023 16:32:24 +1000 Subject: [PATCH] Upgrades for Square --- app/PaymentDrivers/Square/CreditCard.php | 10 ++-------- app/PaymentDrivers/SquarePaymentDriver.php | 10 +++------- 2 files changed, 5 insertions(+), 15 deletions(-) diff --git a/app/PaymentDrivers/Square/CreditCard.php b/app/PaymentDrivers/Square/CreditCard.php index 16e22bc1dc45..616bbbbff046 100644 --- a/app/PaymentDrivers/Square/CreditCard.php +++ b/app/PaymentDrivers/Square/CreditCard.php @@ -34,11 +34,8 @@ class CreditCard implements MethodInterface { use MakesHash; - public $square_driver; - - public function __construct(SquarePaymentDriver $square_driver) + public function __construct(public SquarePaymentDriver $square_driver) { - $this->square_driver = $square_driver; $this->square_driver->init(); } @@ -103,8 +100,7 @@ class CreditCard implements MethodInterface ); if ($request->shouldUseToken()) { - /** @var \App\Models\ClientGatewayToken $cgt **/ - $cgt = ClientGatewayToken::where('token', $request->token)->first(); + $cgt = ClientGatewayToken::query()->where('token', $request->token)->first(); $token = $cgt->token; } @@ -122,7 +118,6 @@ class CreditCard implements MethodInterface $body = new \Square\Models\CreatePaymentRequest($token, $request->idempotencyKey, $amount_money); $body->setAmountMoney($amount_money); - $body->setAutocomplete(true); $body->setLocationId($this->square_driver->company_gateway->getConfigField('locationId')); $body->setReferenceId($this->square_driver->payment_hash->hash); @@ -134,7 +129,6 @@ class CreditCard implements MethodInterface $body->setVerificationToken($request->input('verificationToken')); } - /** @var ApiResponse */ $response = $this->square_driver->square->getPaymentsApi()->createPayment($body); if ($response->isSuccess()) { diff --git a/app/PaymentDrivers/SquarePaymentDriver.php b/app/PaymentDrivers/SquarePaymentDriver.php index 8538bfe70ce7..5c9b5515821a 100644 --- a/app/PaymentDrivers/SquarePaymentDriver.php +++ b/app/PaymentDrivers/SquarePaymentDriver.php @@ -17,7 +17,6 @@ use App\Models\SystemLog; use App\Models\GatewayType; use App\Models\PaymentHash; use App\Models\PaymentType; -use Square\Http\ApiResponse; use App\Jobs\Util\SystemLogger; use App\Utils\Traits\MakesHash; use Square\Utils\WebhooksHelper; @@ -25,7 +24,6 @@ use App\Models\ClientGatewayToken; use Square\Models\WebhookSubscription; use App\PaymentDrivers\Square\CreditCard; use App\PaymentDrivers\Square\SquareWebhook; -use Square\Models\ListWebhookSubscriptionsRequest; use Square\Models\CreateWebhookSubscriptionRequest; use App\Http\Requests\Payments\PaymentWebhookRequest; use Square\Models\Builders\RefundPaymentRequestBuilder; @@ -238,7 +236,6 @@ class SquarePaymentDriver extends BaseDriver $body->setReferenceId($payment_hash->hash); $body->setNote(substr($description,0,500)); - /** @var ApiResponse */ $response = $this->square->getPaymentsApi()->createPayment($body); $body = json_decode($response->getBody()); @@ -310,7 +307,6 @@ class SquarePaymentDriver extends BaseDriver return false; } - // { // "subscription": { // "id": "wbhk_b35f6b3145074cf9ad513610786c19d5", @@ -341,9 +337,9 @@ class SquarePaymentDriver extends BaseDriver $subscription->setName('Invoice_Ninja_Webhook_Subscription'); $subscription->setEventTypes($event_types); -$subscription->setNotificationUrl('https://invoicing.co'); + // $subscription->setNotificationUrl('https://invoicing.co'); -// $subscription->setNotificationUrl($this->company_gateway->webhookUrl()); + $subscription->setNotificationUrl($this->company_gateway->webhookUrl()); // $subscription->setApiVersion('2021-12-15'); $body = new CreateWebhookSubscriptionRequest($subscription); @@ -354,7 +350,7 @@ $subscription->setNotificationUrl('https://invoicing.co'); if ($api_response->isSuccess()) { $subscription = $api_response->getResult()->getSubscription(); $signatureKey = $subscription->getSignatureKey(); - + $this->company_gateway->setConfigField('signatureKey', $signatureKey); } else {