Reputation: 81
In following the Stripe documentation for Billing and Subscriptions, I'm using PaymentIntents to create a subscription. It works fine if I enter a test card that doesn't require 3D Secure. But it I use one that does, instead of giving me a status of requires_action, it just gives a error on the card.
//Create customer
$customer = \Stripe\Customer::create(array(
"source" => $token,
"email" => $subscriber_email)
);
// Get customer variables from Stripe response
$payment_livemode = $customer->livemode;
$payer_id = $customer->id;
// Now put customer on subs plan
try {
$subscription = \Stripe\Subscription::create([
"customer" => $payer_id,
"items" => [
[
"plan" => $subscription_plan
],
],
"expand" => ["latest_invoice.payment_intent"],
]);
$subscription_id = $subscription->id;
$subscription_plan_id = $subscription->items->data[0]->plan->id;
$subscription_latest_invoice_status = $subscription->latest_invoice->status;
$subscription_latest_invoice_id = $subscription->latest_invoice->id;
$subscription_latest_invoice_payment_intent_status = $subscription->latest_invoice->payment_intent->status;
$subscription_latest_invoice_payment_intent_client_secret = $subscription->latest_invoice->payment_intent->client_secret;
$_SESSION['subscription_latest_invoice_payment_intent_client_secret'] = $subscription_latest_invoice_payment_intent_client_secret;
if ($subscription_latest_invoice_payment_intent_status=='succeeded') {
header("Location: ../payment-success");
}
if ($subscription_latest_invoice_payment_intent_status=='requires_payment_method') {
header("Location: ../payment?payment_status=failed&inv=$subscription_latest_invoice_id");
}
if ($subscription_latest_invoice_payment_intent_status=='requires_action') {
header("Location: ../payment?payment_status=requires_action");
}
} catch(\Stripe\Error\Card $e) {
$body = $e->getJsonBody();
$err = $body['error'];
if ($err['code']=="subscription_payment_intent_requires_action") {
header("Location: ../payment/requires_action");
}
} catch (\Stripe\Error\RateLimit $e) {
// Too many requests made to the API too quickly
} catch (\Stripe\Error\InvalidRequest $e) {
// Invalid parameters were supplied to Stripe's API
} catch (\Stripe\Error\Authentication $e) {
// Authentication with Stripe's API failed
// (maybe you changed API keys recently)
} catch (\Stripe\Error\ApiConnection $e) {
// Network communication with Stripe failed
} catch (\Stripe\Error\Base $e) {
// Display a very generic error to the user, and maybe send
// yourself an email
} catch (Exception $e) {
// Something else happened, completely unrelated to Stripe
}
I'm using test cards on this page: https://stripe.com/docs/testing#three-ds-cards
I have chosen the card with this number: 4000 0000 0000 3220
Here's my error details:
Status:402
Type:card_error
Code:subscription_payment_intent_requires_action
Message:Payment for this subscription requires additional user action before it can be completed successfully. Please refer to the use of the enable_incomplete_payments
parameter here: https://stripe.com/docs/billing/lifecycle#incomplete-opt-in
My API version is 2018-05-21.
Can anyone give me a clue to what I'm doing wrong?
Upvotes: 8
Views: 14443
Reputation: 26317
In case anyone else hits this, I was prototyping a checkout and updating the payment intent with some coupon info on an input blur.
Turns out I was updating the payment intent after 3d secure opened, but before it had been confirmed.
Upvotes: 0
Reputation: 5025
I had the same problem and actually, the API version is not the version of the library you download, you have to change it in your dashboard, https://dashboard.stripe.com/developers
Upvotes: 3
Reputation: 3331
Answered in the comments, just posting here for visibility:
Hi Andy, since you are on an older API version, to support 3DS on subscriptions, you should be using this guide instead: https://stripe.com/docs/billing/migration/strong-customer-authentication#upgrading-integration.
This means updating your API version or passing the enable_incomplete_payments flag when creating the subscription, as the error message points out.
Upvotes: 6