Fixes for squar

This commit is contained in:
David Bomba 2023-08-20 19:17:21 +10:00
parent 85b5398718
commit 787400ff39
3 changed files with 7 additions and 5 deletions

View File

@ -116,7 +116,7 @@ class CreditCard implements MethodInterface
$amount_money->setAmount($amount); $amount_money->setAmount($amount);
$amount_money->setCurrency($this->square_driver->client->currency()->code); $amount_money->setCurrency($this->square_driver->client->currency()->code);
$body = new \Square\Models\CreatePaymentRequest($token, $request->idempotencyKey, $amount_money); $body = new \Square\Models\CreatePaymentRequest($token, $request->idempotencyKey);
$body->setAmountMoney($amount_money); $body->setAmountMoney($amount_money);
$body->setAutocomplete(true); $body->setAutocomplete(true);
$body->setLocationId($this->square_driver->company_gateway->getConfigField('locationId')); $body->setLocationId($this->square_driver->company_gateway->getConfigField('locationId'));

View File

@ -104,13 +104,15 @@ class SquareWebhook implements ShouldQueue
MultiDB::findAndSetDbByCompanyKey($this->company_key); MultiDB::findAndSetDbByCompanyKey($this->company_key);
$this->company_gateway = CompanyGateway::queyr()->withTrashed()->find($this->company_gateway_id); $this->company_gateway = CompanyGateway::query()->withTrashed()->find($this->company_gateway_id);
$this->driver = $this->company_gateway->driver()->init(); $this->driver = $this->company_gateway->driver()->init();
$this->square = $this->driver->square; $this->square = $this->driver->square;
$status = $this->webhook_array['data']['object']['payment']['status'] ?? false; $status = $this->webhook_array['data']['object']['payment']['status'] ?? false;
$payment_id = $this->webhook_array['data']['object']['payment']['id'] ?? null; $payment_id = $this->webhook_array['data']['object']['payment']['id'] ?? null;
$payment_status = false;
match($status){ match($status){
'APPROVED' => $payment_status = false, 'APPROVED' => $payment_status = false,
'COMPLETED' => $payment_status = Payment::STATUS_COMPLETED, 'COMPLETED' => $payment_status = Payment::STATUS_COMPLETED,
@ -131,7 +133,6 @@ class SquareWebhook implements ShouldQueue
if($payment->status_id == Payment::STATUS_PENDING && in_array($payment_status, [Payment::STATUS_CANCELLED, Payment::STATUS_FAILED])){ if($payment->status_id == Payment::STATUS_PENDING && in_array($payment_status, [Payment::STATUS_CANCELLED, Payment::STATUS_FAILED])){
$payment->service()->deletePayment(); $payment->service()->deletePayment();
if ($this->driver->payment_hash) { if ($this->driver->payment_hash) {
$error = ctrans('texts.client_payment_failure_body', [ $error = ctrans('texts.client_payment_failure_body', [
'invoice' => implode(',', $payment->invoices->pluck('number')->toArray()), 'invoice' => implode(',', $payment->invoices->pluck('number')->toArray()),
@ -157,7 +158,7 @@ class SquareWebhook implements ShouldQueue
//toggle pending to completed. //toggle pending to completed.
} }
private function retrieveOrCreatePayment(?string $payment_reference, int $payment_status): \App\Models\Payment private function retrieveOrCreatePayment(?string $payment_reference, int $payment_status): ?\App\Models\Payment
{ {
$payment = Payment::withTrashed()->where('transaction_reference', $payment_reference)->first(); $payment = Payment::withTrashed()->where('transaction_reference', $payment_reference)->first();
@ -273,6 +274,7 @@ class SquareWebhook implements ShouldQueue
else{ else{
nlog("Square Webhook - Payment not found: $payment_reference"); nlog("Square Webhook - Payment not found: $payment_reference");
nlog($apiResponse->getErrors()); nlog($apiResponse->getErrors());
return null;
} }
} }
} }

View File

@ -230,7 +230,7 @@ class SquarePaymentDriver extends BaseDriver
$amount_money->setAmount($amount); $amount_money->setAmount($amount);
$amount_money->setCurrency($this->client->currency()->code); $amount_money->setCurrency($this->client->currency()->code);
$body = new \Square\Models\CreatePaymentRequest($cgt->token, \Illuminate\Support\Str::random(32), $amount_money); $body = new \Square\Models\CreatePaymentRequest($cgt->token, \Illuminate\Support\Str::random(32));
$body->setCustomerId($cgt->gateway_customer_reference); $body->setCustomerId($cgt->gateway_customer_reference);
$body->setAmountMoney($amount_money); $body->setAmountMoney($amount_money);
$body->setReferenceId($payment_hash->hash); $body->setReferenceId($payment_hash->hash);