Server side action await question

Hello guys,

I have read many threads trying to figure out how to solve one problem that i’m facing with stripe checkout server-side action.

The code has an await and with that, Bubble saying there’s an error with the Javascript, if I remove the await word from the code the code looks ok, but when trying the action it doesn’t work.

I have seen in the forum a template to use away/sync:

return context.async( async callback => {
try {
let result = await myAsyncCall( args );
callback( undefined, bubble_return_object );
}
catch ( err ) {
callback( err );
}
});

But I can’t figure out how to use it with my code:

const stripe = require(‘stripe’)(‘’+properties.stripe_sk_key+‘’);
const session = await stripe.checkout.sessions.create({
success_url: ‘’+properties.success_url+‘’,
cancel_url: ‘’+properties.cancel_url+‘’,
customer: ‘’+properties.customer+‘’,
payment_method_types: [‘card’],
line_items: [ {price: ‘’+properties.plan_id+‘’, quantity: 1}, ],
mode: ‘subscription’
});

    return { "session_id": session.id };

Any idea how I should format the javascript code?
Many thanks in advance

1 Like

Move your code to inside the try { } block (:
But you’ll likely need to do more than just that, at least var whatever = context.async... and then in the end something like return { "session_id": whatever.id }

Can you help me with the code? Would be possible to show me how you would do using my code?

Thanks in advance @vini_brito

Upp. Someone else who can helps with this?

Thanks!

This topic was automatically closed after 70 days. New replies are no longer allowed.