#mathersdis

1 messages · Page 1 of 1 (latest)

charred scarabBOT
lone mulch
#

👋 happy to help

#

I'm not sure I follow

#

is this on your backend?

past sigil
#

ok so basically the code i shared above is from status.js code sample on the official docs so instead of doing it that way i am handling the redirect url via the backend

past sigil
lone mulch
#

I'm sorry but I'm a bit confused

past sigil
#
    {

        $stripe = new \Stripe\StripeClient(env('STRIPE_PUBLISHABLE_KEY'));


        //  try {
        // Retrieve the PaymentIntent

        $clientSecret = $request->query('payment_intent_client_secret');

        $paymentIntent = $stripe->paymentIntents->retrieve($clientSecret);

        $mid = $paymentIntent->metadata->mid;

        // Inspect the paymentIntent->status to decide what to show to the customer
        if($paymentIntent->status == 'succeeded') {


            if(auth()->check()){

                $tip= Tip::create([
                    'user_from' => auth()->user()->uid,
                    'user_to' => $mid,
                    'amount' => $paymentIntent->amount,
                    'payment_method' => 'stripe'
                ]);

                $intentId = $paymentIntent->id;

                $setIntent = $this->updateIntent($tip->tid,$intentId);


                $request->session()->flash('success','Tip Payment Successful');

                return redirect()->url('member-detail', ['uid' => $mid]);


            } ``` this is my code and the other code i shared is the way it is on the stripe documentation
#

so basically ```
const {error} = await stripe.confirmPayment({
//Elements instance that was used to create the Payment Element
elements,
confirmParams: {
return_url: 'http://174.138.34.46/fan-tip-redirect',
},
});

#

and the first code i shared is how stripe documented it offically

past sigil
lone mulch
#

honestly not really

charred scarabBOT
past sigil
dim girder
#

Can you help me understand the issue?

past sigil
#

so basically this is my confirm payment method right? ```const form = document.getElementById('payment-form');

form.addEventListener('submit', async (event) => {
event.preventDefault();

const {error} = await stripe.confirmPayment({
//Elements instance that was used to create the Payment Element
elements,
confirmParams: {
return_url: 'https://example.com/order/123/complete',
},
});

if (error) {
// This point will only be reached if there is an immediate error when
// confirming the payment. Show error to your customer (for example, payment
// details incomplete)
const messageContainer = document.querySelector('#error-message');
messageContainer.textContent = error.message;
} else {
// Your customer will be redirected to your return_url. For some payment
// methods like iDEAL, your customer will be redirected to an intermediate
// site first to authorize the payment, then redirected to the return_url.
}
});```

dim girder
#

Sure

past sigil
#

the return_url is is appended with the payment intent client secret so i can retreive it and handle it correct?

dim girder
#

Yep, Stripe.js appends that automatically

past sigil
#

and this is how i can handle the return_url ```// Initialize Stripe.js using your publishable key
const stripe = Stripe('pk_test_x8UNwravzaMgy9x83CTVU29z');

// Retrieve the "payment_intent_client_secret" query parameter appended to
// your return_url by Stripe.js
const clientSecret = new URLSearchParams(window.location.search).get(
'payment_intent_client_secret'
);

// Retrieve the PaymentIntent
stripe.retrievePaymentIntent(clientSecret).then(({paymentIntent}) => {
const message = document.querySelector('#message')

// Inspect the PaymentIntent status to indicate the status of the payment
// to your customer.
//
// Some payment methods will [immediately succeed or fail][0] upon
// confirmation, while others will first enter a processing state.
//
// [0]: https://stripe.com/docs/payments/payment-methods#payment-notification
switch (paymentIntent.status) {
case 'succeeded':
message.innerText = 'Success! Payment received.';
break;

case 'processing':
  message.innerText = "Payment processing. We'll update you when payment is received.";
  break;

case 'requires_payment_method':
  message.innerText = 'Payment failed. Please try another payment method.';
  // Redirect your user back to your payment page to attempt collecting
  // payment again
  break;

default:
  message.innerText = 'Something went wrong.';
  break;

}
});``` so instead of doing it this way i am doing it via the backend

dim girder
#

Ok

past sigil
#

but i am failing to get the client secret from the url using this ```
$clientSecret = $request->query('payment_intent_client_secret');

    $paymentIntent = $stripe->paymentIntents->retrieve($clientSecret);
dim girder
#

Yeah I suspect that if your return_url is a backend service then we don't automatically append the pi_abc_secret_xyz

#

As it's Stripe.js that handles that

past sigil
#

so the return url is suppose to be created on the stripe dashboard so it automatically append it?

dim girder
#

I don't understand

#

Your return_url would generally be the page where your customer clicked pay and you call confirmPayment. On that page, you have Stripe.js

#

Stripe.js appends the query parameters. If your return_url is a page/endpoint without Stripe.js, then it can't append it

dim girder
#

You need to just manually append it and it to your return_url yourself

past sigil
#

can i come back for follow up questions?

dim girder
#

Sure