From c4a19916fd381ae0ebc008ca667589be82b59748 Mon Sep 17 00:00:00 2001 From: Belle Aerni Date: Sat, 6 Sep 2025 13:03:58 -0700 Subject: [PATCH] Fix payment / PayPal problems (#2889) * Fix payment / PayPal problems * Update Guest.php Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Adam Daley Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --- src/library/Payment/Adapter/PayPalEmail.php | 2 +- src/modules/Invoice/Api/Guest.php | 4 +++- src/modules/Invoice/Service.php | 7 ++++--- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/library/Payment/Adapter/PayPalEmail.php b/src/library/Payment/Adapter/PayPalEmail.php index 5b2568647..968163b21 100644 --- a/src/library/Payment/Adapter/PayPalEmail.php +++ b/src/library/Payment/Adapter/PayPalEmail.php @@ -184,7 +184,7 @@ class Payment_Adapter_PayPalEmail extends Payment_AdapterAbstract implements FOS $d = [ 'id' => $id, 'error' => '', - 'error_code' => '', + 'error_code' => null, 'status' => 'processed', 'updated_at' => date('Y-m-d H:i:s'), ]; diff --git a/src/modules/Invoice/Api/Guest.php b/src/modules/Invoice/Api/Guest.php index 5df7ecd14..0197a005e 100644 --- a/src/modules/Invoice/Api/Guest.php +++ b/src/modules/Invoice/Api/Guest.php @@ -35,8 +35,10 @@ class Guest extends \Api_Abstract if (!$model) { throw new \FOSSBilling\Exception('Invoice was not found'); } + $service = $this->getService(); + $service->checkInvoiceAuth($model->client_id); - return $this->getService()->toApiArray($model, true, $this->getIdentity()); + return $service->toApiArray($model, true, $this->getIdentity()); } /** diff --git a/src/modules/Invoice/Service.php b/src/modules/Invoice/Service.php index 9f6a960fc..fa75e64ae 100644 --- a/src/modules/Invoice/Service.php +++ b/src/modules/Invoice/Service.php @@ -139,8 +139,6 @@ class Service implements InjectionAwareInterface public function toApiArray(\Model_Invoice $invoice, $deep = true, $identity = null): array { - $this->checkInvoiceAuth($invoice->client_id); - $row = $this->di['db']->toArray($invoice); $items = $this->di['db']->find('InvoiceItem', 'invoice_id = :iid', ['iid' => $row['id']]); @@ -1238,10 +1236,13 @@ class Service implements InjectionAwareInterface $document_format = $systemService->getParamValue('invoice_document_format', 'Letter'); $invoice = $this->di['db']->findOne('Invoice', 'hash = :hash', [':hash' => $hash]); + if (!$invoice instanceof \Model_Invoice) { throw new \FOSSBilling\Exception('Invoice not found'); } + $this->checkInvoiceAuth($invoice->client_id); + if (isset($invoice->currency)) { $currencyCode = $invoice->currency; } else { @@ -1498,7 +1499,7 @@ class Service implements InjectionAwareInterface return $this->di['table_export_csv']('invoice', 'invoices.csv', $headers); } - private function checkInvoiceAuth(?int $invoiceClientId) + public function checkInvoiceAuth(?int $invoiceClientId) { if ($invoiceClientId === null) { return;