#mathersdis
1 messages · Page 1 of 1 (latest)
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
nop
I'm sorry but I'm a bit confused
{
$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
i hope this clears it up
honestly not really
ok on the redirect url from the confirm payment method on the docs payment intent client secret is appended to the url so i can use it to retrieve the payment method and use it accordingly but instead of doing it using status.js from here https://stripe.com/docs/connect/collect-then-transfer-guide i am doing it server side so i can handle it as i want
Can you help me understand the issue?
sure
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.
}
});```
Sure
the return_url is is appended with the payment intent client secret so i can retreive it and handle it correct?
Yep, Stripe.js appends that automatically
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
Ok
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);
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
ohh really
so the return url is suppose to be created on the stripe dashboard so it automatically append it?
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
ohh i see
You need to just manually append it and it to your return_url yourself
ok thank you i will do that
can i come back for follow up questions?
Sure