https://discord.gg/botpress logo
#šŸ’»developers
Title
# šŸ’»developers
g

green-school-10640

03/14/2024, 12:19 PM
hey I am beginner in botpress, I am creating a chatbot for my company i have finished the flow of the conversation but in the end I want the functionality to redirect the users to the payment page here I am using square for payments i think the code is working but the nothing showing in the url and it is showing empty how to fix it // Define the async function within the Botpress action or event handler context const sendPayment = async (event: any, { bp }: any) => { const squareApiUrl = 'https://connect.squareupsandbox.com/v2/checkout'; const locationId = ' My id'; const accessToken = ' My token '; const payload = { idempotency_key: payment-${Date.now()}, order: { line_items: [ { name: workflow.selectedMedicine, quantity: workflow.medicineQuantity, base_price_money: { amount: parseFloat(workflow.totalAmount) * 100, currency: 'GBP' } } ] }, }; try { const response = await axios.post(${squareApiUrl}/${locationId}/checkouts, payload, { headers: { 'Authorization': Bearer ${accessToken}, 'Content-Type': 'application/json', 'Accept': 'application/json' } }); const checkoutUrl = response.data.checkout.checkout_page_url; workflow.url = checkoutUrl const text = You can complete your payment by clicking on the following link: ${checkoutUrl}; await bp.events.replyToEvent(event, { type: 'text', text }); } catch (error) { console.error('Failed to create checkout session with Square:', error); const errorMessage = 'Sorry, there was a problem processing your payment. Please try again later.'; await bp.events.replyToEvent(event, { type: 'text', text: errorMessage }); } }; this is my code please somebody help me