| 1 |
<?php |
| 2 |
|
| 3 |
namespace FluentCart\App\Services\ShortCodeParser\Parsers; |
| 4 |
|
| 5 |
use FluentCart\Api\CurrencySettings; |
| 6 |
use FluentCart\Api\StoreSettings; |
| 7 |
use FluentCart\App\Helpers\Helper; |
| 8 |
use FluentCart\App\Models\Order; |
| 9 |
use FluentCart\App\Services\DateTime\DateTime; |
| 10 |
use FluentCart\App\Services\Payments\PaymentReceipt; |
| 11 |
use FluentCart\Framework\Support\Arr; |
| 12 |
use FluentCart\Framework\Support\Str; |
| 13 |
use FluentCartPro\App\Modules\Licensing\Models\License; |
| 14 |
|
| 15 |
class TransactionParser extends BaseParser |
| 16 |
{ |
| 17 |
private $transaction; |
| 18 |
|
| 19 |
public function __construct($data) |
| 20 |
{ |
| 21 |
$this->transaction = Arr::get($data, 'transaction'); |
| 22 |
parent::__construct($data); |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
protected array $centColumns = [ |
| 27 |
'total' |
| 28 |
]; |
| 29 |
|
| 30 |
public function parse($accessor = '', $code = '', $transformer = null): ?string |
| 31 |
{ |
| 32 |
|
| 33 |
if (empty($this->transaction)) { |
| 34 |
return $code; |
| 35 |
} |
| 36 |
// Handle _formatted suffix for cent columns |
| 37 |
$formattedSuffix = '_formatted'; |
| 38 |
if (Str::endsWith($accessor, $formattedSuffix)) { |
| 39 |
$baseAccessor = substr($accessor, 0, -strlen($formattedSuffix)); |
| 40 |
if (in_array($baseAccessor, $this->centColumns)) { |
| 41 |
$amount = Arr::get($this->transaction, $baseAccessor); |
| 42 |
if (!is_numeric($amount)) { |
| 43 |
return (string) $amount; |
| 44 |
} |
| 45 |
return CurrencySettings::getPriceHtml($amount, Arr::get($this->transaction, 'currency')); |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
if (in_array($accessor, $this->centColumns)) { |
| 50 |
$amount = Arr::get($this->transaction, $accessor); |
| 51 |
if (!is_numeric($amount)) { |
| 52 |
return (string) $amount; |
| 53 |
} |
| 54 |
return (string) ($amount / 100); |
| 55 |
} |
| 56 |
return $this->get($accessor, $code); |
| 57 |
} |
| 58 |
|
| 59 |
public function getRefundAmount(): string |
| 60 |
{ |
| 61 |
$amount = (int) Arr::get($this->transaction, 'total', 0); |
| 62 |
return (string) ($amount / 100); |
| 63 |
} |
| 64 |
|
| 65 |
public function getRefundAmountFormatted(): string |
| 66 |
{ |
| 67 |
$amount = Arr::get($this->transaction, 'total', 0); |
| 68 |
return CurrencySettings::getPriceHtml($amount, Arr::get($this->transaction, 'currency')); |
| 69 |
} |
| 70 |
|
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|