From 753c9c42395a63174141757cc894478eb40051ca Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 27 Jan 2024 16:08:54 +1100 Subject: [PATCH] Update Checkout.com customer on successful payment --- app/PaymentDrivers/CheckoutCom/CreditCard.php | 9 +++++---- app/PaymentDrivers/CheckoutComPaymentDriver.php | 14 +++++++------- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/app/PaymentDrivers/CheckoutCom/CreditCard.php b/app/PaymentDrivers/CheckoutCom/CreditCard.php index 38f592b201d1..ec5bfeec1731 100644 --- a/app/PaymentDrivers/CheckoutCom/CreditCard.php +++ b/app/PaymentDrivers/CheckoutCom/CreditCard.php @@ -173,10 +173,6 @@ class CreditCard implements MethodInterface if ($request->has('token') && ! is_null($request->token) && ! empty($request->token)) { return $this->attemptPaymentUsingToken($request); } - - if($this->checkout->company_gateway->update_details) { - $this->checkout->updateCustomer(); - } return $this->attemptPaymentUsingCreditCard($request); } @@ -235,8 +231,13 @@ class CreditCard implements MethodInterface try { $response = $this->checkout->gateway->getPaymentsClient()->requestPayment($paymentRequest); + + if($this->checkout->company_gateway->update_details && isset($response['customer'])) { + $this->checkout->updateCustomer($response['customer']['id'] ?? ''); + } if ($response['status'] == 'Authorized') { + return $this->processSuccessfulPayment($response); } diff --git a/app/PaymentDrivers/CheckoutComPaymentDriver.php b/app/PaymentDrivers/CheckoutComPaymentDriver.php index ce91f337a6bc..469986059b33 100644 --- a/app/PaymentDrivers/CheckoutComPaymentDriver.php +++ b/app/PaymentDrivers/CheckoutComPaymentDriver.php @@ -329,9 +329,11 @@ class CheckoutComPaymentDriver extends BaseDriver } } - public function updateCustomer() + public function updateCustomer($customer_id = null) { - nlog("merp"); + + if(!$customer_id) + return; try { @@ -343,7 +345,9 @@ class CheckoutComPaymentDriver extends BaseDriver $request->name = $this->client->present()->name(); $request->phone = $phone; - $response = $this->gateway->getCustomersClient()->update("customer_id", $request); + $response = $this->gateway->getCustomersClient()->update($customer_id, $request); + + } catch (CheckoutApiException $e) { nlog($e->getMessage()); } catch (CheckoutAuthorizationException $e) { @@ -384,10 +388,6 @@ class CheckoutComPaymentDriver extends BaseDriver $this->init(); - if($this->company_gateway->update_details) { - $this->updateCustomer(); - } - $paymentRequest = $this->bootTokenRequest($cgt->token); $paymentRequest->amount = $this->convertToCheckoutAmount($amount, $this->client->getCurrencyCode()); $paymentRequest->reference = '#'.$invoice->number.' - '.now();