PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.4
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.4
1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk 1.2.0 All 47 releases
fluent-cart / app / Services / ShortCodeParser / Parsers / TransactionParser.php

TransactionParser.php in FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler 1.6.4, at app/Services/ShortCodeParser/Parsers/TransactionParser.php

74 lines 2.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
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