Update Checkout.com customer on successful payment

This commit is contained in:
David Bomba 2024-01-27 16:08:54 +11:00
parent 849a9dc113
commit 753c9c4239
2 changed files with 12 additions and 11 deletions

View File

@ -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);
}

View File

@ -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();