+
+
+paymentIntents->create([
+ 'amount' => intval($balance_to_pay * 100), // Times by 100 as Stripe expects values in cents
+ 'currency' => $invoice_currency_code,
+ 'customer' => $payment_provider_client,
+ 'payment_method' => $saved_payment_method,
+ 'off_session' => true,
+ 'confirm' => true,
+ 'description' => $pi_description,
+ 'metadata' => [
+ 'itflow_client_id' => $client_id,
+ 'itflow_client_name' => $client_name,
+ 'itflow_invoice_number' => $invoice_prefix . $invoice_number,
+ 'itflow_invoice_id' => $invoice_id,
+ ]
+ ]);
+
+ // Get details from PI
+ $pi_id = sanitizeInput($payment_intent->id);
+ $pi_date = date('Y-m-d', $payment_intent->created);
+ $pi_amount_paid = floatval(($payment_intent->amount_received / 100));
+ $pi_currency = strtoupper(sanitizeInput($payment_intent->currency));
+ $pi_livemode = $payment_intent->livemode;
+
+ } catch (Exception $e) {
+ $error = $e->getMessage();
+ error_log("Stripe payment error - encountered exception during payment intent for invoice ID $invoice_id / $invoice_prefix$invoice_number: $error");
+ logApp("Stripe", "error", "Exception during PI for invoice ID $invoice_id: $error");
+ }
+
+ if ($payment_intent->status == "succeeded" && intval($balance_to_pay) == intval($pi_amount_paid)) {
+
+ // Update Invoice Status
+ mysqli_query($mysqli, "UPDATE invoices SET invoice_status = 'Paid' WHERE invoice_id = $invoice_id");
+
+ // Add Payment to History
+ mysqli_query($mysqli, "INSERT INTO payments SET payment_date = '$pi_date', payment_amount = $pi_amount_paid, payment_currency_code = '$pi_currency', payment_account_id = $account_id, payment_method = 'Stripe', payment_reference = 'Stripe - $pi_id', payment_invoice_id = $invoice_id");
+ mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Paid', history_description = 'Online Payment added (agent)', history_invoice_id = $invoice_id");
+
+ // Email receipt
+ if (!empty($config_smtp_host)) {
+ $subject = "Payment Received - Invoice $invoice_prefix$invoice_number";
+ $body = "Hello $contact_name,
We have received online payment for the amount of " . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . " for invoice $invoice_prefix$invoice_number. Please keep this email as a receipt for your records.
This is a notification that an invoice has been paid in ITFlow. Below is a copy of the receipt sent to the client:-
--------
Hello $contact_name,
We have received online payment for the amount of " . numfmt_format_currency($currency_format, $invoice_amount, $invoice_currency_code) . " for invoice $invoice_prefix$invoice_number. Please keep this email as a receipt for your records.