#ramires-gomes_api
1 messages ยท Page 1 of 1 (latest)
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.
- ramires_checkout-connect, 2 hours ago, 18 messages
- ramires-gomes_code, 3 hours ago, 9 messages
๐ 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/1273795207837782107
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hi, first you should be the one setting up that URL. How can it be somewhere you don't control?
Sorry for my naivety on the subject, I'll show you my code
try {
$session = $this->stripeClient->checkout->sessions->create([
'line_items' => $instance->products->map(function ($product) {
return [
'price_data' => [
'currency' => 'eur',
'product_data' => ['name' => $product->title],
'unit_amount' => Number::convertMoneyStringToInteger($product->unit_price_with_iva)
],
'quantity' => $product->qty,
];
})->toArray(),
'payment_intent_data' => [
'application_fee_amount' => Number::convertMoneyStringToInteger(
formatMoney($this->getOrderTotalValue($instance) * 0.049)
)
],
'shipping_options' => [[
'shipping_rate_data' => [
'type' => 'fixed_amount',
'fixed_amount' => [
'amount' => Number::convertMoneyStringToInteger($instance->shipping_cost),
'currency' => 'eur'
],
'display_name' => 'Custo total do porte',
]
]],
'customer_email' => $client->email,
'mode' => 'payment',
'ui_mode' => 'embedded',
'return_url' => route('cart.stripe.finish_order', $instanceUuid) . "?session_id={CHECKOUT_SESSION_ID}"
], $this->getConnectedAccountData());
} catch (Exception $e) {
dd($e->getMessage());
}
Here I created the session and sent it to the front-end
on the front-end I selected the ATM option and clicked on pay
Sure np
It should be redirected back to route('cart.stripe.finish_order', $instanceUuid) , isn't it?
When I select payment with a yes card, but with an multibanco, it goes to the URL I provided above
Ah that's where the customer to confirm multibanco. After that it should be redirected back to your URL, eventually
Or do you mean that multibanco URL doesn't have a button to redirect further?
I really hope it redirects back, but there is no back button on this screen
Ah okie I see what you mean
Because Multibanco is a delayed notification payment method, you need to use a method such as webhooks to monitor the payment status and handle order fulfillment
So does this mean that from this screen the client can close the browser tab and the system waits for the request to come from the webhook?
Could you tell me how I can test this part of the webhook with Multibanco, please?
Yes correct. You can setup a webhook listener and listen for the action when customer click on button of this screen. There would be no event if customer does nothing or just close the tab
Forgive me if the next question was too naive.
I've already worked with webhooks on the back-end, which sends POST requests to my endpoint.
Do the events you mentioned work this way?
Yes, the webhook event
You can refer to the Doc link here
Perfect, I will follow the documentation you indicated.
Another question:
Generally, when I work with multibanco, I put the reference and entity data on the customer's panel if they haven't written it down. Is there any way I can do this?
Could you elaborate a bit more on this customer's panel? Where do you put it exactly?
If it is about putting note (any kind of information) on a Customer, you can look at metadata
My application is an ecommerce, and in it my client has an area where they can change their registration data and view their purchases.
When a purchase is made on the website it appears in this area, however when it comes to a payment with an multibanco I generally leave the multibanco entity and reference in this area for the customer to make the payment, the same data that is displayed on the multibanco page from stripe
Probably when the checkout.session.completed event is triggered I will receive the data from the multibanco to write to the database and thus be able to display it on the customer panel
Okie. You can then put the reference and entity data on the Checkout Session metadata when you create it. It will then come back on checkout.session.completed inside the Checkout Session object
The "reference" and "entity" data are not generated by me, they come from the multibanco. I will show it with the image
Oh I see
Inside the Checkout Session, could you expand to see it's PaymentIntent, then the PaymentMethod inside the PaymentIntent? (2 levels down)
inside PaymentMethod object, could you look at this multibanco field to see if they are here?
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
my code
dd($stripeSession->payment_intent);
browser
"pi_3PoAs0Ldge9R5kB120zmkhF3" // app/Http/Controllers/Frontend/StripeOrderController.php:265
StripeSession is a Stripe\Checkout\Session
I think I understand, I'm testing
try this:
$stripeSession = $this->stripeClient->checkout->sessions->retrieve(
id: $sessionId,
opts: $this->getConnectedAccountData()
);
$paymentIntent = $this->stripeClient->paymentIntents->retrieve($stripeSession->payment_intent);
dd($paymentIntent);
response error
"No such payment_intent: 'pi_3PoAs0Ldge9R5kB120zmkhF3'" // app/Http/Controllers/Frontend/StripeOrderController.php:254
can you do Retrieve Checkout Session with expand: ['payment_intent.payment_method']?
Like this?
Yeah
Please try it
Doc for expanding is here https://docs.stripe.com/expand
Very good.
Now I had access to both levels "payment_intent" and "payment_method"
Is it more recommended to use expand or make separate requests?
It has the maximum depth levels of 4
It's up to you really, it could be a bit slower for expanding more
But it could save you API calls
For sure.
I confess that I was a little desperate about having to make separate requests for each sub-level.
yeah so let's look at the PaymentMethod
In this case I'm getting a card one, as I still don't have the session_id of one with multibanco
You finished that Checkout Session with multibanco?
Let's finish one and get an example
Please use the email value here https://docs.stripe.com/payments/multibanco/accept-a-payment?web-or-mobile=web&payments-ui-type=stripe-hosted#test-the-integration
ie succeed_immediately@example.com
Sorry, I couldn't understand where I should enter the email for the test
On this page?
Oh i see
One moment
I believe I now need to configure the webhook, right?
I already have the endpoint in my application, I just don't know where I should register it in stripe yet
Yeah you can quickly start a Stripe CLi with stripe listen
Yeah so you can grag the checkout.session.async_payment_succeeded id there evt_1Po....
And do a Retrieve Checkout Session and expand as we discussed
Let me try this
Should I use constructEvent as per this link?
https://docs.stripe.com/checkout/fulfillment#create-payment-event-handler
Or can I redeem the checkout session directly
Well eventually you would need to build the webhook endpoint which use the constructEvent
But for now let's just use the Id and test the multibanco field first
I tried it:
$this->stripeClient->checkout->sessions->retrieve(
id: 'evt_1PoF4tLdge9R5kB14e52J0bT',
params: ['expand' => ['payment_intent.payment_method']],
opts: $this->getConnectedAccountData()
);
And get that:
No such checkout.session: evt_1PoF4tLdge9R5kB14e52J0bT
Yeah
Okie I guess you would want to build a simple webhook handler first
Download from here https://docs.stripe.com/webhooks/quickstart, host in localhost, then stripe listen --forward-to your localhost
Yeah alright, now let's trigger a session.async_payment_succeeded by paying in the Stripe hosted Checkout flow, and catch the event on your server