'That invoice no longer exists.'])); } $client_id = intval($invoice['client_id']); enforceClientAccess(); $state = invoiceState($invoice, invoicePaid($invoice_id)); $cards = []; $sql = mysqli_query($mysqli, "SELECT saved_payment_id, saved_payment_description, payment_provider_name FROM client_saved_payment_methods JOIN payment_providers ON payment_provider_id = saved_payment_provider_id WHERE saved_payment_client_id = $client_id AND payment_provider_active = 1 ORDER BY saved_payment_description ASC"); while ($row = mysqli_fetch_assoc($sql)) { $cards[] = $row; } if (!$cards) { exit(json_encode(['error' => $invoice['client_name'] . ' has no card on file with a payment provider that is turned on.'])); } // What is charged - agent/post/payment.php works it out the same way $currency = (string) $invoice['invoice_currency_code']; $fee_rates = billingCardFeeFor($client_id); $invoice_cents = (int) round(floatval($invoice['invoice_amount']) * 100); $fee = billingCardFeeCents($invoice_cents, $fee_rates) / 100; $charge = $invoice_cents / 100 + $fee; ob_start(); ?>