OTC-Zahlungssummen als Verkaufspreis verwenden
This commit is contained in:
1 parent
3957d57a3a
commit
2a31a88c1d
2 files changed
+7
-27
No files matched your search
@@ -30,7 +30,7 @@ if (!is_array($data)) {
|
||||
json_response(400, ['ok' => false, 'error' => 'JSON object expected']);
|
||||
}
|
||||
|
||||
$required = ['products', 'totalPrice', 'orderDate', 'payments', 'billing'];
|
||||
$required = ['products', 'orderDate', 'payments', 'billing'];
|
||||
foreach ($required as $field) {
|
||||
if (!array_key_exists($field, $data)) {
|
||||
json_response(422, ['ok' => false, 'error' => "Missing field: {$field}"]);
|
||||
@@ -38,7 +38,6 @@ foreach ($required as $field) {
|
||||
}
|
||||
|
||||
$products = $data['products'];
|
||||
$totalPrice = parse_number($data['totalPrice']);
|
||||
$orderDate = trim((string) $data['orderDate']);
|
||||
$payments = $data['payments'];
|
||||
$billing = is_array($data['billing']) ? $data['billing'] : [];
|
||||
@@ -51,10 +50,6 @@ if (!is_array($payments) || count($payments) === 0) {
|
||||
json_response(422, ['ok' => false, 'error' => 'No payment methods specified']);
|
||||
}
|
||||
|
||||
if ($totalPrice === null || $totalPrice <= 0) {
|
||||
json_response(422, ['ok' => false, 'error' => 'Invalid total price']);
|
||||
}
|
||||
|
||||
$orderDateTime = DateTimeImmutable::createFromFormat('!Y-m-d', $orderDate);
|
||||
$orderDateErrors = DateTimeImmutable::getLastErrors();
|
||||
if ($orderDateTime === false) {
|
||||
@@ -109,10 +104,12 @@ foreach ($payments as $payment) {
|
||||
$paymentTotal = round($paymentTotal + (float) $amount, 2);
|
||||
}
|
||||
|
||||
if (abs($paymentTotal - (float) $totalPrice) > 0.005) {
|
||||
json_response(422, ['ok' => false, 'error' => 'Payment amounts must equal total price']);
|
||||
if ($paymentTotal <= 0) {
|
||||
json_response(422, ['ok' => false, 'error' => 'Payment total must be greater than zero']);
|
||||
}
|
||||
|
||||
$totalPrice = $paymentTotal;
|
||||
|
||||
try {
|
||||
$env = expand_env_values(parse_env_file(__DIR__ . '/../../../../.env'));
|
||||
$pdo = connect_database($env);
|
||||
|
||||
Reference in new issue
Block a user