• Resolved mycommunication

    (@mycommunication)


    Greetings,
    We have a WooCommerce subscription based system and we have written a script for Late Fee on decline.
    Basically when a subscriber misses the payment we want to add a late fee on that subscription. 
    We have a product which called “Subscription” which is the main product and “Late Fee” product which we want to add onto the subscription.
    We also have Stripe tokens for our customers in the database but when we initalize the purchase via a custom PHP script from the website for a subscriber to resubscribe and add the late fee the purchase gets declined from Stripe even with the token.

    It is a basic purchase with two products but it isnt going through even with tokens it gets rejected.
    The script is stored in the website domain that uses Stripe daily, automatic resubscribing works fine but creating a custom purchase with the same user token does not.

    Are there any particular steps that the script should take or does it need some kind of approval from Stripe?
    What can be the issue?


    Best regards.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @mycommunication,

    I understand you’ve built a custom PHP script to add a “Late Fee” product to a WooCommerce subscription and charge the customer using an existing Stripe token. However, despite successful auto-renewals via WooCommerce, this manual charge attempt fails when using the same token. That definitely sounds frustrating, and I’ll do my best to point you in the right direction.

    From what you’ve shared, here are a few key considerations that might explain why the custom purchase attempt is being declined:

    1. Stripe Customer Tokens vs. Payment Intents WooCommerce Subscriptions (with Stripe) uses payment method tokens tied to a Stripe customer object. When Stripe processes automatic renewals, it uses saved payment methods attached to that customer—typically through the setup_intent flow. If your custom script doesn’t correctly associate the saved payment method with the customer and fails to create a PaymentIntent with proper authentication context, Stripe may reject it due to missing authorization or SCA requirements.
    2. SCA (Strong Customer Authentication) If the card requires SCA (common with European cards), Stripe will require 3D Secure or another challenge even for saved cards. The built-in WooCommerce Stripe Gateway handles this automatically using setup_intent and off_session flags. For your script to work similarly, you must:
      • Create a PaymentIntent with off_session set to true
      • Attach the correct payment_method and customer ID
      • Set confirm to true
      • Handle the requires_action or authentication_required response gracefully
    3. Script Setup Steps At a minimum, your custom script should:
      • Retrieve the WooCommerce Stripe customer ID (usually saved in wc_stripe_customer_id user meta)
      • Retrieve the correct payment_method ID (Stripe token saved)
      • Create a PaymentIntent via the Stripe API:
    \Stripe\Stripe::setApiKey('sk_test_...');
    
    $intent = \Stripe\PaymentIntent::create([
        'amount' => 5000, // e.g., 50.00 EUR
        'currency' => 'eur',
        'customer' => $stripe_customer_id,
        'payment_method' => $payment_method_id,
        'off_session' => true,
        'confirm' => true,
        'description' => 'Late Fee for Subscription Order #1234',
        'metadata' => [
            'order_id' => 1234,
        ],
    ]);

    – Catch and handle Stripe\Exception\CardException to capture SCA issues or declines

    4. Check the Logs Enable logging in WooCommerce > Settings > Payments > Stripe, and check the logs under WooCommerce > Status > Logs > stripe-YYYY-MM-DD to see if the failure reveals a decline reason like insufficient_funds, authentication_required, or do_not_honor.

    5. Test Mode vs. Live Mode Make sure your script uses the correct API key (test vs live) and tokens corresponding to the correct Stripe environment.

      Let us know how that goes.

      Plugin Support Feten L. a11n

      (@fetenlakhal)

      Hi there,

      We haven’t heard back in a bit, so I’ll go ahead and mark this as resolved for now. If you’d like to pick things back up later, we’re just a message away!

      Apart from this, if you have a moment, we’d really appreciate a review: https://ww.wp.xz.cn/support/plugin/woocommerce-gateway-stripe/reviews/#new-post

    Viewing 2 replies - 1 through 2 (of 2 total)

    The topic ‘Custom PHP Woocommerce / WordPress script that includes Stripe payment’ is closed to new replies.