loevgaard /
altapay-php-sdk
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | namespace Loevgaard\AltaPay\Payload; |
||
| 3 | |||
| 4 | use Assert\Assert; |
||
| 5 | use Loevgaard\AltaPay; |
||
| 6 | use Money\Money; |
||
| 7 | |||
| 8 | class CaptureReservation extends Payload implements CaptureReservationInterface |
||
| 9 | { |
||
| 10 | use OrderLineArrayTrait; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var string |
||
| 14 | */ |
||
| 15 | private $transactionId; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var int |
||
| 19 | */ |
||
| 20 | private $amountValue; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | private $amountCurrency; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | private $reconciliationIdentifier; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | private $invoiceNumber; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var int |
||
| 39 | */ |
||
| 40 | private $salesTax; |
||
| 41 | |||
| 42 | 6 | public function __construct(string $transactionId) |
|
| 43 | { |
||
| 44 | 6 | $this->transactionId = $transactionId; |
|
| 45 | 6 | $this->orderLines = []; |
|
| 46 | 6 | } |
|
| 47 | |||
| 48 | /** |
||
| 49 | * @return array |
||
| 50 | */ |
||
| 51 | 3 | public function getPayload() : array |
|
| 52 | { |
||
| 53 | 3 | $this->validate(); |
|
| 54 | |||
| 55 | $payload = [ |
||
| 56 | 3 | 'transaction_id' => $this->transactionId, |
|
| 57 | 3 | 'amount' => AltaPay\floatFromMoney($this->getAmount()), |
|
| 58 | 3 | 'reconciliation_identifier' => $this->reconciliationIdentifier, |
|
| 59 | 3 | 'invoice_number' => $this->invoiceNumber, |
|
| 60 | 3 | 'sales_tax' => AltaPay\floatFromMoney($this->getSalesTax()), |
|
| 61 | 3 | 'orderLines' => $this->orderLines |
|
| 62 | ]; |
||
| 63 | |||
| 64 | 3 | return static::simplePayload($payload); |
|
| 65 | } |
||
| 66 | |||
| 67 | 3 | public function validate() |
|
| 68 | { |
||
| 69 | 3 | Assert::that($this->transactionId)->string(); |
|
| 70 | 3 | Assert::thatNullOr($this->getAmount())->isInstanceOf(Money::class); |
|
| 71 | 3 | Assert::thatNullOr($this->reconciliationIdentifier)->string(); |
|
| 72 | 3 | Assert::thatNullOr($this->invoiceNumber)->string(); |
|
| 73 | 3 | Assert::thatNullOr($this->getSalesTax())->isInstanceOf(Money::class); |
|
| 74 | 3 | Assert::that($this->orderLines)->isArray(); |
|
| 75 | 3 | } |
|
| 76 | |||
| 77 | /** |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | 3 | public function getTransactionId() : string |
|
| 81 | { |
||
| 82 | 3 | return $this->transactionId; |
|
| 83 | } |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @param string $transactionId |
||
| 87 | * @return CaptureReservation |
||
| 88 | */ |
||
| 89 | 3 | public function setTransactionId(string $transactionId) : self |
|
| 90 | { |
||
| 91 | 3 | $this->transactionId = $transactionId; |
|
| 92 | 3 | return $this; |
|
| 93 | } |
||
| 94 | |||
| 95 | /** |
||
| 96 | * @return Money |
||
| 97 | */ |
||
| 98 | 6 | public function getAmount() : ?Money |
|
| 99 | { |
||
| 100 | 6 | return AltaPay\createMoney((string)$this->amountCurrency, (int)$this->amountValue); |
|
| 101 | } |
||
| 102 | |||
| 103 | /** |
||
| 104 | * @param Money $amount |
||
| 105 | * @return CaptureReservation |
||
| 106 | */ |
||
| 107 | 3 | public function setAmount(Money $amount) : self |
|
| 108 | { |
||
| 109 | 3 | $this->amountValue = $amount->getAmount(); |
|
|
0 ignored issues
–
show
|
|||
| 110 | 3 | $this->amountCurrency = $amount->getCurrency()->getCode(); |
|
| 111 | |||
| 112 | 3 | return $this; |
|
| 113 | } |
||
| 114 | |||
| 115 | /** |
||
| 116 | * @return string |
||
| 117 | */ |
||
| 118 | 3 | public function getReconciliationIdentifier() : ?string |
|
| 119 | { |
||
| 120 | 3 | return $this->reconciliationIdentifier; |
|
| 121 | } |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @param string $reconciliationIdentifier |
||
| 125 | * @return CaptureReservation |
||
| 126 | */ |
||
| 127 | 3 | public function setReconciliationIdentifier(string $reconciliationIdentifier) : self |
|
| 128 | { |
||
| 129 | 3 | $this->reconciliationIdentifier = $reconciliationIdentifier; |
|
| 130 | 3 | return $this; |
|
| 131 | } |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @return string |
||
| 135 | */ |
||
| 136 | 3 | public function getInvoiceNumber() : ?string |
|
| 137 | { |
||
| 138 | 3 | return $this->invoiceNumber; |
|
| 139 | } |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @param string $invoiceNumber |
||
| 143 | * @return CaptureReservation |
||
| 144 | */ |
||
| 145 | 3 | public function setInvoiceNumber(string $invoiceNumber) : self |
|
| 146 | { |
||
| 147 | 3 | $this->invoiceNumber = $invoiceNumber; |
|
| 148 | 3 | return $this; |
|
| 149 | } |
||
| 150 | |||
| 151 | /** |
||
| 152 | * @return Money |
||
| 153 | */ |
||
| 154 | 6 | public function getSalesTax() : ?Money |
|
| 155 | { |
||
| 156 | 6 | return AltaPay\createMoney((string)$this->amountCurrency, (int)$this->salesTax); |
|
| 157 | } |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @param Money $salesTax |
||
| 161 | * @return CaptureReservation |
||
| 162 | */ |
||
| 163 | 3 | public function setSalesTax(Money $salesTax) : self |
|
| 164 | { |
||
| 165 | 3 | $this->salesTax = $salesTax->getAmount(); |
|
|
0 ignored issues
–
show
The property
$salesTax was declared of type integer, but $salesTax->getAmount() is of type string. Maybe add a type cast?
This check looks for assignments to scalar types that may be of the wrong type. To ensure the code behaves as expected, it may be a good idea to add an explicit type cast. $answer = 42;
$correct = false;
$correct = (bool) $answer;
Loading history...
|
|||
| 166 | 3 | return $this; |
|
| 167 | } |
||
| 168 | } |
||
| 169 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.