#codename-mid9it_subscription-manual-redirect

1 messages ยท Page 1 of 1 (latest)

tacit bridgeBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.

๐Ÿ”— This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1222160877265092672

๐Ÿ“ Have more to share? Add more details, code, screenshots, videos, etc. below.

lime garnetBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

inland glen
#

the rest of the code below

#
    // Create the subscription with the found product ID
             $subscription = $stripe->subscriptions->create([
                'customer' => $customer,
                'items' => [['price' => $product_id]],
                "currency" => $_currency,
                "description" => $paydesc,
                //'amount' => $finalamount,
                'expand' => ['latest_invoice.payment_intent'],
                
            ]);

            // Add var_dump() here to check payment_intent status and next_action type
var_dump($subscription->latest_invoice->payment_intent->status);
var_dump($subscription->latest_invoice->payment_intent->next_action->type);

$log_content = ob_get_clean(); // Get the buffered content
file_put_contents('payment_intent_log.txt', $log_content, FILE_APPEND); // Append content to log file



                    
            // Check if 3DS authentication is required
            if ($subscription->latest_invoice->payment_intent->status === 'requires_action' &&
                $subscription->latest_invoice->payment_intent->next_action->type === 'redirect_to_url'
            ) {
                // Redirect the customer to the 3DS authentication page
                $redirectUrl = $subscription->latest_invoice->payment_intent->next_action->redirect_to_url->url; 
                //var_dump($redirectUrl);
                header("HTTP/1.1 303 See Other");
                header("Location: " . $redirectUrl->url);
                exit(); 
            } else {
                {
lime garnetBOT
mighty fox
#

ah, were you on stackoverflow earlier too?

#

but yeah anyway you need to "re-confirm" the PaymentIntent if you really want to do it this way instead of using the SDK.

inland glen
#

yes i believe

#

lol

mighty fox
#

$paymentIntent = $stripe->paymentIntents->confirm($subscription->latest_invoice->payment_intent->id, ['return_url' => "https://myexample.com/success"]);

inland glen
#

where do i add this piece please?

mighty fox
#

I'd probably do it after checking if ($subscription->latest_invoice->payment_intent->status === 'requires_action')

inland glen
#

alright give me a few lemme implent it and share the result. thanks

#

brb

tacit bridgeBOT
#

codename-mid9it_subscription-manual-redirect

inland glen
mighty fox
#

make sure you're looking at the variable returned by calling the API and not the old one

#

like after you run that code $paymentIntent->next_action->type would definitely be redirect_to_url; and then you can the logic to do the redirect using $paymentIntent->next_action.

inland glen
#

i still don't understand i'm sorry

inland glen
quartz stratus
#

Hi there ๐Ÿ‘‹ jumping in as my teammate needs to step away. Can you share the ID of a request (req_) where you made that follow-up confirmation request passing a return_url? So I can take a closer look at what is happening in your flow.

inland glen
#

hi toby

#

okay

quartz stratus
inland glen
#

but the authentication modal doesn't show up and dashboard still says the payment is incomplete

quartz stratus
#

Let's take a step back.

This started because you wanted to see redirect_to_url as the next_action instead of use_stripe_sdk. That indicates that you want to handle redirecting the customer to the authentication flow instead of letting our SDK handle that for you.

You pass a return_url when making a server-side confirmation request to trigger that behavior, which we see happening in the request that I shared.

#

Are you now directing your customer to the URL that is provided to you so they can complete the authentication flow?

inland glen
# quartz stratus Are you now directing your customer to the URL that is provided to you so they c...

no, i believe i'm not because the url that is provided to me in my "if" logic.

so are you saying i put this

  $paymentIntent = $stripe->paymentIntents->confirm( 
                $subscription->latest_invoice->payment_intent->id,['return_url' => "https://xxxxxx/xxxxx
/MyAccount.php"]);
            
                    // Update $subscription with the latest information
$subscription = $stripe->subscriptions->retrieve($subscription->id, ['expand' => ['latest_invoice.payment_intent']]);


#

before the "if" logic?

quartz stratus
#

I'm not exactly sure I'm following, but maybe. You have the request now that is giving you the URL you need to send the customer to so they can complete the required authentication, you'll now to need to adjust your logic to detect the presence of that URL and direct your customer to it.

inland glen
#

so if my the confirm paymentIntent code changes the use_stripe_sdk to redirect url does it mean that i should place the confirm paymentIntent code before my "if" logic?

quartz stratus
#

Sounds like it, does the flow work as expected in your testing if you do?

inland glen
#

okaaayyyy yes it did change the use sdk to redirect url

#

but i'm getting a new error

Notice: Trying to get property 'url' of non-object on line 221

#

and line 221 is

 header("Location: " . $redirectUrl->url);
                exit(); 
quartz stratus
#

What is the code you're running? What object is it looking at? What is the structure of that object?

inland glen
#

this is the code i'm currently running

    // Create the subscription with the found product ID
             $subscription = $stripe->subscriptions->create([
                'customer' => $customer,
                'items' => [['price' => $product_id]],
                "currency" => $_currency,
            "description" => $paydesc,
                'expand' => ['latest_invoice.payment_intent'],
            ]);

           
              //Confirm Payment Intent
                $paymentIntent = $stripe->paymentIntents->confirm( 
                $subscription->latest_invoice->payment_intent->id,['return_url' => "https://bnlf.org.uk/join-us/MyAccount.php"]);
            
                    // Update $subscription with the latest information
$subscription = $stripe->subscriptions->retrieve($subscription->id, ['expand' => ['latest_invoice.payment_intent']]);


                    
            // Check if 3DS authentication is required
            if ($subscription->latest_invoice->payment_intent->status === 'requires_action' &&
                $subscription->latest_invoice->payment_intent->next_action->type === 'redirect_to_url'
            ) {
                // Redirect the customer to the 3DS authentication page
                $redirectUrl = $subscription->latest_invoice->payment_intent->next_action->redirect_to_url->url; 
                header("HTTP/1.1 303 See Other");
                header("Location: " . $redirectUrl->url);
                exit(); 
                
                
            } else {

i was given this header by another support few hours ealier

  header("HTTP/1.1 303 See Other");
                header("Location: " . $redirectUrl->url);
                exit(); 

i believe the url is supposed to be gotten from stripe to redirect to the user bank and the return_url should be after the user has authenicated the payment from their bank

quartz stratus
#

It seems like you're probably already getting the URL directly inside of $redirectUrl and don't need to point to it with ->url. If you log out the contents of $redirectUrl, what does it contain?

inland glen
#

let me do that now

#

YES!!!!

#

IT WORKS!!!!!

#

so the redirect->url return as empty

#

because the url was directly in the $redirectUrl

#

THANKSS A LOT

#

YOU JUST SAVED MY JOB. I'VE A MEETING WITH MY CLIENTS concerning this right now loooool

#

thank you so so so much