#ramires-gomes_api

1 messages ยท Page 1 of 1 (latest)

sterile mountainBOT
inland magnetBOT
#

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.

sterile mountainBOT
#

๐Ÿ‘‹ 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.

arctic edge
#

Hi, first you should be the one setting up that URL. How can it be somewhere you don't control?

stone urchin
#

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

arctic edge
#

Sure np

#

It should be redirected back to route('cart.stripe.finish_order', $instanceUuid) , isn't it?

stone urchin
#

I don't know how to return my application after this

stone urchin
arctic edge
#

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?

stone urchin
#

I really hope it redirects back, but there is no back button on this screen

arctic edge
#

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

stone urchin
#

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?

arctic edge
#

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

stone urchin
#

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?

arctic edge
#

Yes, the webhook event

arctic edge
stone urchin
#

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?

arctic edge
#

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

stone urchin
#

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

arctic edge
#

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

stone urchin
#

The "reference" and "entity" data are not generated by me, they come from the multibanco. I will show it with the image

arctic edge
#

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?

stone urchin
#
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
arctic edge
#

can you do Retrieve Checkout Session with expand: ['payment_intent.payment_method']?

stone urchin
#

Like this?

arctic edge
#

Yeah

#

Please try it

stone urchin
#

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?

arctic edge
#

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

stone urchin
#

For sure.
I confess that I was a little desperate about having to make separate requests for each sub-level.

arctic edge
#

yeah so let's look at the PaymentMethod

stone urchin
#

In this case I'm getting a card one, as I still don't have the session_id of one with multibanco

arctic edge
#

You finished that Checkout Session with multibanco?

#

Let's finish one and get an example

arctic edge
#

ie succeed_immediately@example.com

stone urchin
#

Sorry, I couldn't understand where I should enter the email for the test

arctic edge
#

When put on the Checkout page before redirecting

#

the Stripe hosted page

stone urchin
#

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

arctic edge
#

Yeah you can quickly start a Stripe CLi with stripe listen

stone urchin
#

I will install

#

That's is so cool ๐Ÿ™‚

arctic edge
#

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

stone urchin
#

Let me try this

#

Or can I redeem the checkout session directly

arctic edge
#

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

stone urchin
#

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
arctic edge
#

Sorry that's the event

#

You need the Checkout Session Id cs_test_xxx

stone urchin
#

Yeah

arctic edge
#

Okie I guess you would want to build a simple webhook handler first

stone urchin
#

Done

arctic edge
#

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