(int) round($state['balance'] * 100)) { $refuse = 'amount is more than is owed on ' . $reference_text . ' - ' . billingMoney($state['balance'], $currency) . '.'; } elseif (!isset(paymentAccounts()[$account_id])) { $refuse = 'account_id is needed - the account it went into. There is no default payment account (Admin > Settings > Invoices and billing).'; } elseif ($payment_method === '' || !in_array($payment_method, paymentMethods('in'), true)) { $refuse = 'payment_method is needed - how it was paid, one of: ' . implode(', ', paymentMethods('in')) . '.'; } if ($refuse !== '') { http_response_code(400); $return_arr['success'] = "False"; $return_arr['message'] = $refuse; echo json_encode($return_arr); exit(); } $date_sql = escapeSql($date); $currency_sql = escapeSql($currency); $method_sql = escapeSql($payment_method); $reference_sql = escapeSql($reference); mysqli_query($mysqli, "INSERT INTO payments SET payment_date = '$date_sql', payment_amount = $amount, payment_currency_code = '$currency_sql', payment_account_id = $account_id, payment_method = '$method_sql', payment_reference = '$reference_sql', payment_invoice_id = $invoice_id"); $payment_id = intval(mysqli_insert_id($mysqli)); if ($payment_id) { $insert_id = $payment_id; $status = updateInvoiceStatusFromPayments($invoice_id); $money = billingMoney($amount, $currency); billingLog('invoice', $invoice_id, $status, "Payment of $money added via the API (" . html_entity_decode($api_key_name, ENT_QUOTES, 'UTF-8') . ")"); logAudit("Invoice", "Payment", "Payment amount of " . escapeSql($money) . " added to invoice " . escapeSql($reference_text) . " via API ($api_key_name)", $client_id, $invoice_id); logAudit("API", "Success", "Added a payment of " . escapeSql($money) . " to invoice " . escapeSql($reference_text) . " via API ($api_key_name)", $client_id); // The client's receipt (functions/billing_email.php) $receipt_to = []; // Left out, it goes when ITFlow sends mail - as the switch on Add Payment shows then if (array_key_exists('email_receipt', $_POST) ? !empty($_POST['email_receipt']) : !empty($config_smtp_provider)) { $receipt_to = billingPaymentSend($invoice_id, $amount, ['date' => $date, 'method' => $payment_method, 'reference' => $reference]); if ($receipt_to) { logAudit("Invoice", "Payment", "Payment receipt for invoice " . escapeSql($reference_text) . " queued to " . escapeSql(implode(', ', $receipt_to)), $client_id, $invoice_id); } } triggerCustomAction('invoice_pay', $invoice_id); $return_arr['invoice_status'] = (string) getFieldById('invoices', $invoice_id, 'invoice_status'); $return_arr['balance'] = round(floatval($invoice['invoice_amount']) - invoicePaid($invoice_id), 2); $return_arr['receipt_to'] = array_values($receipt_to); } } // Output require_once '../create_output.php';