![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/old/app/code/Cnc/StripePayment/Model/PaymentIntent/ |
<?php /** * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) * @author Radosław Łańcucki <[email protected]> * @copyright Copyright (c) 2022 KDC (https://digitalcommerce.kaliop.com) */ declare(strict_types=1); namespace Cnc\StripePayment\Model\PaymentIntent; class DescriptionFormatter { const DESCRIPTION_ORDER = 'Order #{INCREMENT_ID}'; const DESCRIPTION_ORDER_MULTI_SHIPPING = 'Multi-shipping Order #{INCREMENT_ID}'; const DESCRIPTION_INVOICE = '(Invoice #{INVOICE_INCREMENT_ID})'; const DESCRIPTION_SEPARATOR = ' by '; const DESCRIPTION_CUSTOMER = '{COMPANY NAME} - {PREFIX} {CUSTOMER FIRSTNAME + LASTNAME}'; /** * @param bool $isMultiShipping * @param string $incrementId * @param string $invoiceIncrementId * @param string $company * @param string $prefix * @param string $firstname * @param string $lastname * @return string|null */ public function getFormattedDescription( bool $isMultiShipping, string $incrementId, string $invoiceIncrementId, string $company, string $prefix, string $firstname, string $lastname ): ?string { if (empty($incrementId)) { return null; } $description = str_replace('{INCREMENT_ID}', $incrementId, $isMultiShipping ? self::DESCRIPTION_ORDER_MULTI_SHIPPING : self::DESCRIPTION_ORDER ); if (!empty($invoiceIncrementId)) { $description .= ' '; $description .= str_replace( '{INVOICE_INCREMENT_ID}', $invoiceIncrementId, self::DESCRIPTION_INVOICE ); } $customerPart = ''; $customer = [ '{COMPANY NAME}' => $company, '{PREFIX}' => $prefix, '{CUSTOMER FIRSTNAME + LASTNAME}' => trim($firstname . ' ' . $lastname) ]; if (!empty($company) || !empty($prefix) || !empty($firstname) || !empty($lastname)) { $customerPart = self::DESCRIPTION_CUSTOMER; if (empty($company)) { $customerPart = str_replace(' - ', '', $customerPart); } foreach ($customer as $search => $replace) { $customerPart = str_replace($search, $replace, $customerPart); } } if (!empty($customerPart)) { $description .= self::DESCRIPTION_SEPARATOR; $description .= $customerPart; } return $description; } }