From fc9c05b6043519b5197e2c33141d0d571bc341db Mon Sep 17 00:00:00 2001 From: MDW Date: Mon, 17 Feb 2025 22:10:41 +0100 Subject: [PATCH] Qual: Fix phan notices (stripe) --- htdocs/stripe/admin/stripe.php | 4 +- htdocs/stripe/charge.php | 10 +- htdocs/stripe/class/actions_stripe.class.php | 8 +- htdocs/stripe/class/stripe.class.php | 128 +++++++++---------- htdocs/stripe/lib/stripe.lib.php | 4 +- 5 files changed, 77 insertions(+), 77 deletions(-) diff --git a/htdocs/stripe/admin/stripe.php b/htdocs/stripe/admin/stripe.php index 77999453856..5a63260084d 100644 --- a/htdocs/stripe/admin/stripe.php +++ b/htdocs/stripe/admin/stripe.php @@ -4,7 +4,7 @@ * Copyright (C) 2017 Saasprov * Copyright (C) 2018-2022 Thibault FOUCART * Copyright (C) 2018-2025 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -455,7 +455,7 @@ if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { // TODO Not used by current c // If $site_account not defined, then key not set and no way to call API Location $stripeacc = $stripe->getStripeAccount($service); if ($stripeacc) { - $locations = \Stripe\Terminal\Location::all('', array("stripe_account" => $stripeacc)); + $locations = \Stripe\Terminal\Location::all(null, array("stripe_account" => $stripeacc)); } else { $locations = \Stripe\Terminal\Location::all(); } diff --git a/htdocs/stripe/charge.php b/htdocs/stripe/charge.php index 98ebb3690c6..a209a77b419 100644 --- a/htdocs/stripe/charge.php +++ b/htdocs/stripe/charge.php @@ -1,7 +1,7 @@ * Copyright (C) 2019-2024 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -202,15 +202,15 @@ if (!$rowid) { // Save into $tmparray all metadata $tmparray = dolExplodeIntoArray($FULLTAG, '.', '='); // Load origin object according to metadata - if (!empty($tmparray['CUS']) && $tmparray['CUS'] > 0) { - $societestatic->fetch($tmparray['CUS']); + if (!empty($tmparray['CUS']) && (int) $tmparray['CUS'] > 0) { + $societestatic->fetch((int) $tmparray['CUS']); } elseif (!empty($charge->metadata->dol_thirdparty_id) && $charge->metadata->dol_thirdparty_id > 0) { $societestatic->fetch($charge->metadata->dol_thirdparty_id); } else { $societestatic->id = 0; } - if (!empty($tmparray['MEM']) && $tmparray['MEM'] > 0) { - $memberstatic->fetch($tmparray['MEM']); + if (!empty($tmparray['MEM']) && (int) $tmparray['MEM'] > 0) { + $memberstatic->fetch((int) $tmparray['MEM']); } else { $memberstatic->id = 0; } diff --git a/htdocs/stripe/class/actions_stripe.class.php b/htdocs/stripe/class/actions_stripe.class.php index 7dbf68d7fb9..d52587c21fa 100644 --- a/htdocs/stripe/class/actions_stripe.class.php +++ b/htdocs/stripe/class/actions_stripe.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2009-2016 Regis Houssin * Copyright (C) 2011 Herve Prot * Copyright (C) 2014 Philippe Grand - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * Copyright (C) 2024 Frédéric France * * This program is free software; you can redistribute it and/or modify @@ -126,7 +126,7 @@ class ActionsStripeconnect extends CommonHookActions $this->resprints .= ''; $this->resprints .= ''; $stripe = new Stripe($this->db); - if (7 == 4) { + if (7 == 4) { // @phan-suppress-current-line PhanPluginBothLiteralsBinaryOp $object->fetch_thirdparty(); $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service)); $this->resprints .= $customer->id; @@ -145,7 +145,7 @@ class ActionsStripeconnect extends CommonHookActions $this->resprints .= ''; $this->resprints .= ''; $stripe = new Stripe($this->db); - if (7 == 4) { + if (7 == 4) { // @phan-suppress-current-line PhanPluginBothLiteralsBinaryOp $object->fetch_thirdparty(); $customer = $stripe->customerStripe($object, $stripe->getStripeAccount($service)); $this->resprints .= $customer->id; @@ -196,7 +196,7 @@ class ActionsStripeconnect extends CommonHookActions if ($object->statut > Facture::STATUS_DRAFT && $object->statut < Facture::STATUS_ABANDONED && $object->paye == 0) { $stripe = new Stripe($this->db); if ($resteapayer > 0) { - if ($stripe->getStripeAccount($conf->entity)) { // a modifier avec droit stripe + if ($stripe->getStripeAccount($service, 0, $conf->entity)) { // To modify with stripe authorizations $langs->load("withdrawals"); print ''.$langs->trans("StripeConnectPay").''; } else { diff --git a/htdocs/stripe/class/stripe.class.php b/htdocs/stripe/class/stripe.class.php index d9df53069b4..bec79999831 100644 --- a/htdocs/stripe/class/stripe.class.php +++ b/htdocs/stripe/class/stripe.class.php @@ -47,7 +47,7 @@ class Stripe extends CommonObject public $fk_key; /** - * @var int ID + * @var string Stripe ID */ public $id; @@ -101,10 +101,10 @@ class Stripe extends CommonObject /** * Return main company OAuth Connect stripe account * - * @param string $mode 'StripeTest' or 'StripeLive' - * @param int $fk_soc Id of thirdparty - * @param int $entity Id of entity (-1 = current environment) - * @return string Stripe account 'acc_....' or '' if no OAuth token found + * @param 'StripeTest'|'StripeLive' $mode 'StripeTest' or 'StripeLive' + * @param int $fk_soc Id of third party + * @param int $entity Id of entity (-1 = current environment) + * @return string Stripe account 'acc_....' or '' if no OAuth token found */ public function getStripeAccount($mode = 'StripeTest', $fk_soc = 0, $entity = -1) { @@ -153,10 +153,10 @@ class Stripe extends CommonObject /** * getStripeCustomerAccount * - * @param int $id Id of third party - * @param int $status Status - * @param string $site_account Value to use to identify with account to use on site when site can offer several accounts. For example: 'pk_live_123456' when using Stripe service. - * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or '' + * @param int $id Id of third party + * @param int<0,1> $status Status + * @param string $site_account Value to use to identify with account to use on site when site can offer several accounts. For example: 'pk_live_123456' when using Stripe service. + * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or '' */ public function getStripeCustomerAccount($id, $status = 0, $site_account = '') { @@ -262,15 +262,15 @@ class Stripe extends CommonObject if (!empty($vatcleaned)) { $isineec = isInEEC($object); if ($object->country_code && $isineec) { - //$taxids = $customer->allTaxIds($customer->id); - $customer->createTaxId($customer->id, array('type' => 'eu_vat', 'value' => $vatcleaned)); + //$taxids = $customer->allTaxIds($customer); + $customer->createTaxId($customer, array('type' => 'eu_vat', 'value' => $vatcleaned)); } } } // Create customer in Dolibarr $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_account (fk_soc, login, key_account, site, site_account, status, entity, date_creation, fk_user_creat)"; - $sql .= " VALUES (".((int) $object->id).", '', '".$this->db->escape($customer->id)."', 'stripe', '".$this->db->escape($stripearrayofkeysbyenv[$status]['publishable_key'])."', ".((int) $status).", ".((int) $conf->entity).", '".$this->db->idate(dol_now())."', ".((int) $user->id).")"; + $sql .= " VALUES (".((int) $object->id).", '', '".$this->db->escape($customer)."', 'stripe', '".$this->db->escape($stripearrayofkeysbyenv[$status]['publishable_key'])."', ".((int) $status).", ".((int) $conf->entity).", '".$this->db->idate(dol_now())."', ".((int) $user->id).")"; $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -289,9 +289,9 @@ class Stripe extends CommonObject /** * Get the Stripe payment method Object from its ID * - * @param string $paymentmethod Payment Method ID - * @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect - * @param int $status Status (0=test, 1=live) + * @param Stripe $paymentmethod Payment Method ID + * @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect + * @param int<0,1> $status Status (0=test, 1=live) * @return \Stripe\PaymentMethod|null Stripe PaymentMethod or null if not found */ public function getPaymentMethodStripe($paymentmethod, $key = '', $status = 0) @@ -317,10 +317,10 @@ class Stripe extends CommonObject /** * Get the Stripe reader Object from its ID * - * @param string $reader Reader ID - * @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect - * @param int $status Status (0=test, 1=live) - * @return \Stripe\Terminal\Reader|null Stripe Reader or null if not found + * @param string $reader Reader ID + * @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect + * @param int<0,1> $status Status (0=test, 1=live) + * @return \Stripe\Terminal\Reader|null Stripe Reader or null if not found */ public function getSelectedReader($reader, $key = '', $status = 0) { @@ -351,21 +351,21 @@ class Stripe extends CommonObject * Note: This is used when option STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION is on when making a payment from the public/payment/newpayment.php page * but not when using the STRIPE_USE_NEW_CHECKOUT. * - * @param double $amount Amount - * @param string $currency_code Currency code - * @param string $tag Tag - * @param string $description Description - * @param ?CommonObject $object Object to pay with Stripe - * @param ?string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() - * @param ?string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect - * @param int $status Status (0=test, 1=live) - * @param int $usethirdpartyemailforreceiptemail 1=use thirdparty email for receipt - * @param string $mode automatic=automatic confirmation/payment when conditions are ok, manual=need to call confirm() on intent - * @param boolean $confirmnow false=default, true=try to confirm immediately after create (if conditions are ok) - * @param ?string $payment_method 'pm_....' (if known) - * @param int $off_session If we use an already known payment method to pay when customer is not available during the checkout flow. - * @param int $noidempotency_key Do not use the idempotency_key when creating the PaymentIntent - * @param int $did ID of an existing line into llx_prelevement_demande (Dolibarr intent). If provided, no new line will be created. + * @param float $amount Amount + * @param string $currency_code Currency code + * @param string $tag Tag + * @param string $description Description + * @param ?CommonObject $object Object to pay with Stripe + * @param ?string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() + * @param ?string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect + * @param int<0,1> $status Status (0=test, 1=live) + * @param int<0,1> $usethirdpartyemailforreceiptemail 1=use thirdparty email for receipt + * @param 'automatic'|'manual' $mode automatic=automatic confirmation/payment when conditions are ok, manual=need to call confirm() on intent + * @param bool $confirmnow false=default, true=try to confirm immediately after create (if conditions are ok) + * @param ?string $payment_method 'pm_....' (if known) + * @param int<0,1> $off_session If we use an already known payment method to pay when customer is not available during the checkout flow. + * @param int<0,1> $noidempotency_key Do not use the idempotency_key when creating the PaymentIntent + * @param int $did ID of an existing line into llx_prelevement_demande (Dolibarr intent). If provided, no new line will be created. * @return ?\Stripe\PaymentIntent Stripe PaymentIntent or null if not found and failed to create */ public function getPaymentIntent($amount, $currency_code, $tag, $description = '', $object = null, $customer = null, $key = null, $status = 0, $usethirdpartyemailforreceiptemail = 0, $mode = 'automatic', $confirmnow = false, $payment_method = null, $off_session = 0, $noidempotency_key = 1, $did = 0) @@ -664,14 +664,14 @@ class Stripe extends CommonObject * Note: This is used when option STRIPE_USE_INTENT_WITH_AUTOMATIC_CONFIRMATION is on when making a payment from the public/payment/newpayment.php page * but not when using the STRIPE_USE_NEW_CHECKOUT. * - * @param string $description Description - * @param Societe $object Object of company to link the Stripe payment mode with - * @param string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() - * @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect - * @param int $status Status (0=test, 1=live) - * @param int $usethirdpartyemailforreceiptemail 1=use thirdparty email for receipt - * @param boolean $confirmnow false=default, true=try to confirm immediately after create (if conditions are ok) - * @return \Stripe\SetupIntent|null Stripe SetupIntent or null if not found and failed to create + * @param string $description Description + * @param Societe $object Object of company to link the Stripe payment mode with + * @param string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() + * @param string $key ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect + * @param int<0,1> $status Status (0=test, 1=live) + * @param int<0,1> $usethirdpartyemailforreceiptemail 1=use thirdparty email for receipt + * @param bool $confirmnow false=default, true=try to confirm immediately after create (if conditions are ok) + * @return \Stripe\SetupIntent|null Stripe SetupIntent or null if not found and failed to create */ public function getSetupIntent($description, $object, $customer, $key, $status, $usethirdpartyemailforreceiptemail = 0, $confirmnow = false) { @@ -836,8 +836,8 @@ class Stripe extends CommonObject * @param \Stripe\Customer $cu Object stripe customer. * @param CompanyPaymentMode $object Object companypaymentmode to check, or create on stripe (create on stripe also update the societe_rib table for current entity) * @param string $stripeacc ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect - * @param int $status Status (0=test, 1=live) - * @param int $createifnotlinkedtostripe 1=Create the stripe card and the link if the card is not yet linked to a stripe card. Deprecated with new Stripe API and SCA. + * @param int<0,1> $status Status (0=test, 1=live) + * @param int<0,1> $createifnotlinkedtostripe 1=Create the stripe card and the link if the card is not yet linked to a stripe card. Deprecated with new Stripe API and SCA. * @return \Stripe\Card|\Stripe\PaymentMethod|null Stripe Card or null if not found */ public function cardStripe($cu, CompanyPaymentMode $object, $stripeacc = '', $status = 0, $createifnotlinkedtostripe = 0) @@ -988,8 +988,8 @@ class Stripe extends CommonObject * @param \Stripe\Customer $cu Object stripe customer. * @param CompanyPaymentMode $object Object companypaymentmode to check, or create on stripe (create on stripe also update the societe_rib table for current entity) * @param string $stripeacc ''=Use common API. If not '', it is the Stripe connect account 'acc_....' to use Stripe connect - * @param int $status Status (0=test, 1=live) - * @param int $createifnotlinkedtostripe 1=Create the stripe sepa and the link if the sepa is not yet linked to a stripe sepa. Used by the "Create bank to Stripe" feature. + * @param int<0,1> $status Status (0=test, 1=live) + * @param int<0,1> $createifnotlinkedtostripe 1=Create the stripe sepa and the link if the sepa is not yet linked to a stripe sepa. Used by the "Create bank to Stripe" feature. * @return \Stripe\PaymentMethod|null Stripe SEPA or null if not found */ public function sepaStripe($cu, CompanyPaymentMode $object, $stripeacc = '', $status = 0, $createifnotlinkedtostripe = 0) @@ -1161,16 +1161,16 @@ class Stripe extends CommonObject * Create charge. * This was called by page htdocs/stripe/payment.php and may be deprecated. * - * @param int $amount Amount to pay - * @param string $currency EUR, GPB... - * @param string $origin Object type to pay (order, invoice, contract...) - * @param int $item Object id to pay - * @param string $source src_xxxxx or card_xxxxx or pm_xxxxx - * @param string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() - * @param string $account Stripe account ref 'acc_xxxxxxxxxxxxx' via getStripeAccount() - * @param int $status Status (0=test, 1=live) - * @param int $usethirdpartyemailforreceiptemail Use thirdparty email as receipt email - * @param boolean $capture Set capture flag to true (take payment) or false (wait) + * @param float $amount Amount to pay + * @param string $currency EUR, GPB... + * @param string $origin Object type to pay (order, invoice, contract...) + * @param int $item Object id to pay + * @param string $source src_xxxxx or card_xxxxx or pm_xxxxx + * @param string $customer Stripe customer ref 'cus_xxxxxxxxxxxxx' via customerStripe() + * @param string $account Stripe account ref 'acc_xxxxxxxxxxxxx' via getStripeAccount() + * @param int<0,1> $status Status (0=test, 1=live) + * @param int<0,1> $usethirdpartyemailforreceiptemail Use thirdparty email as receipt email + * @param bool $capture Set capture flag to true (take payment) or false (wait) * @return Stripe * @deprecated */ @@ -1262,10 +1262,10 @@ class Stripe extends CommonObject dol_syslog("* createPaymentStripe get stripeacc", LOG_DEBUG); $stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account if it exists (no network access here) - dol_syslog("* createPaymentStripe Create payment for customer ".$customer->id." on source card ".$stripecard->id.", amounttopay=".$amounttopay.", amountstripe=".$amountstripe.", FULLTAG=".$FULLTAG, LOG_DEBUG); + dol_syslog("* createPaymentStripe Create payment for customer ".$customer." on source card ".$stripecard.", amounttopay=".$amounttopay.", amountstripe=".$amountstripe.", FULLTAG=".$FULLTAG, LOG_DEBUG); // Create payment intent and charge payment (confirmnow = true) - $paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $invoice, $customer->id, $stripeacc, $servicestatus, 0, 'automatic', true, $stripecard->id, 1); + $paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $invoice, $customer, $stripeacc, $servicestatus, 0, 'automatic', true, $stripecard, 1); $charge = new stdClass(); if ($paymentintent->status == 'succeeded') { @@ -1297,8 +1297,8 @@ class Stripe extends CommonObject "description" => "Stripe payment: ".$description, "capture" => $capture, "metadata" => $metadata, - "source" => "$source", - "customer" => "$customer" + "source" => (string) $source, + "customer" => (string) $customer ); if ($societe->email && $usethirdpartyemailforreceiptemail) { @@ -1329,8 +1329,8 @@ class Stripe extends CommonObject "description" => "Stripe payment: ".$description, "capture" => $capture, "metadata" => $metadata, - "source" => "$source", - "customer" => "$customer" + "source" => (string) $source, + "customer" => (string) $customer ); if ($conf->entity != $conf->global->STRIPECONNECT_PRINCIPAL && $stripefee > 0) { $paymentarray["application_fee_amount"] = $stripefee; @@ -1350,10 +1350,10 @@ class Stripe extends CommonObject dol_syslog("* createPaymentStripe get stripeacc", LOG_DEBUG); $stripeacc = $stripe->getStripeAccount($service); // Get Stripe OAuth connect account if it exists (no network access here) - dol_syslog("* createPaymentStripe Create payment on card ".$stripecard->id.", amounttopay=".$amounttopay.", amountstripe=".$amountstripe.", FULLTAG=".$FULLTAG, LOG_DEBUG); + dol_syslog("* createPaymentStripe Create payment on card ".$stripecard.", amounttopay=".$amounttopay.", amountstripe=".$amountstripe.", FULLTAG=".$FULLTAG, LOG_DEBUG); // Create payment intent and charge payment (confirmnow = true) - $paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $invoice, $customer->id, $stripeacc, $servicestatus, 0, 'automatic', true, $stripecard->id, 1); + $paymentintent = $stripe->getPaymentIntent($amounttopay, $currency, $FULLTAG, $description, $invoice, $customer, $stripeacc, $servicestatus, 0, 'automatic', true, $stripecard, 1); $charge = new stdClass(); if ($paymentintent->status == 'succeeded') { diff --git a/htdocs/stripe/lib/stripe.lib.php b/htdocs/stripe/lib/stripe.lib.php index 9f94fadd5eb..0db5a3ce787 100644 --- a/htdocs/stripe/lib/stripe.lib.php +++ b/htdocs/stripe/lib/stripe.lib.php @@ -1,7 +1,7 @@ * Copyright (C) 2024 Frédéric France - * Copyright (C) 2024 MDW + * Copyright (C) 2024-2025 MDW * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -74,7 +74,7 @@ function html_print_stripe_footer($fromcompany, $langs) } // Capital if ($fromcompany->capital) { - $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency); + $line1 .= ($line1 ? " - " : "").$langs->transnoentities("CapitalOf", (string) $fromcompany->capital)." ".$langs->transnoentities("Currency".$conf->currency); } $reg = array();