Stripe: when Stripe no longer has a client's customer, deleted there or made under other keys, forget it and the cards saved on it so the client sets up again, let new-card payments go ahead, tell agents, and remove the unused autopay_setup_stripe.js

This commit is contained in:
johnnyq
2026-11-19 01:34:48 -05:00
parent 3b1f1e8e8d
commit 875998bbb2
8 changed files with 116 additions and 27 deletions

View File

@@ -105,14 +105,25 @@ if (isset($_GET['stripe_create_pi'])) {
try {
\Stripe\Stripe::setApiKey($stripe_secret_key);
$paymentIntent = \Stripe\PaymentIntent::create([
$pi_params = [
'amount' => $balance_cents + $fee_cents, // Stripe expects cents
'currency' => $invoice_currency_code,
'description' => $pi_description,
'metadata' => $pi_metadata,
'payment_method_types' => ['card'],
'customer' => $stripe_customer_id,
]);
];
try {
$paymentIntent = \Stripe\PaymentIntent::create($pi_params);
} catch (\Stripe\Exception\InvalidRequestException $e) {
// A customer Stripe no longer has - forgotten (next time they are set up again), and this payment goes ahead without one
if (!$stripe_customer_id || !billingStripeCustomerGone($e)) {
throw $e;
}
billingStripeCustomerForget($client_id, $stripe_customer_id);
unset($pi_params['customer']);
$paymentIntent = \Stripe\PaymentIntent::create($pi_params);
}
$output = [
'clientSecret' => $paymentIntent->client_secret,