Update client details in checkout.com if configured to do so

This commit is contained in:
David Bomba 2024-01-14 15:25:21 +11:00
parent 0ba333898e
commit 7f5ffe9f73
2 changed files with 20 additions and 13 deletions

View File

@ -174,6 +174,10 @@ class CreditCard implements MethodInterface
return $this->attemptPaymentUsingToken($request);
}
if($this->checkout->company_gateway->update_details) {
$this->checkout->updateCustomer();
}
return $this->attemptPaymentUsingCreditCard($request);
}
@ -321,7 +325,6 @@ class CreditCard implements MethodInterface
return new PaymentFailed("There was a problem communicating with the API credentials for Checkout", $e->getCode());
// return $this->checkout->processInternallyFailedPayment($this->checkout, $human_exception);
}
}
}

View File

@ -217,6 +217,9 @@ class CheckoutComPaymentDriver extends BaseDriver
{
$this->init();
if($this->company_gateway->update_details)
$this->updateCustomer();
$request = new RefundRequest();
$request->reference = "{$payment->transaction_reference} ".now();
$request->amount = $this->convertToCheckoutAmount($amount, $this->client->getCurrencyCode());
@ -303,9 +306,6 @@ class CheckoutComPaymentDriver extends BaseDriver
$request->name = $this->client->present()->name();
$request->phone = $phone;
// if($this->company_gateway->update_details)
// $this->updateCustomer();
try {
$response = $this->gateway->getCustomersClient()->create($request);
} catch (CheckoutApiException $e) {
@ -334,16 +334,16 @@ class CheckoutComPaymentDriver extends BaseDriver
public function updateCustomer()
{
$phone = new Phone();
$phone->number = substr(str_pad($this->client->present()->phone(), 6, "0", STR_PAD_RIGHT), 0, 24);
try {
$request = new CustomerRequest();
$phone = new Phone();
$phone->number = substr(str_pad($this->client->present()->phone(), 6, "0", STR_PAD_RIGHT), 0, 24);
$request->email = $this->client->present()->email();
$request->name = $this->client->present()->name();
$request->phone = $phone;
try {
$response = $this->gateway->getCustomersClient()->update("customer_id", $request);
} catch (CheckoutApiException $e) {
@ -385,6 +385,10 @@ 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();