How to redirect customer back from offsite payment portal to Shopify checkout with payment details.

How to redirect customer back from offsite payment portal to Shopify checkout with payment details.

Anilket26
Shopify Partner
12 0 0

I have created offsite payment app extension and provide the session url in extension to redirect the customer on payment portal for payment. 

How to redirect customer back to Shopify with payment details?

I have not checkout URL to redirect the customer back.

Kindly help me.

Thanks

Replies 2 (2)

Small_Task_Help
Shopify Partner
559 17 39

Hi,

 

You need to do following

 

Create a Redirect Endpoint - Setup Payment Gateway - Verify Payment Details-Update Order Status in Shopify-Redirect Customer to Shopify

 

Code example for redirect point -

 

 

const express = require('express');
const app = express();
const bodyParser = require('body-parser');
const axios = require('axios');

app.use(bodyParser.json());

app.post('/payment-redirect', async (req, res) => {
    const paymentDetails = req.body; // Assuming the payment gateway sends a POST request with payment details

    // Verify payment details (implement your own verification logic)
    const isValid = verifyPaymentDetails(paymentDetails);

    if (isValid) {
        // Update order status in Shopify
        const orderId = paymentDetails.order_id; // Get order ID from payment details
        const shopifyAccessToken = 'your-shopify-access-token';
        const shopifyStoreUrl = 'your-shopify-store.myshopify.com';

        try {
            await axios.post(`https://${shopifyStoreUrl}/admin/api/2023-01/orders/${orderId}.json`, {
                order: {
                    id: orderId,
                    financial_status: 'paid'
                }
            }, {
                headers: {
                    'X-Shopify-Access-Token': shopifyAccessToken,
                    'Content-Type': 'application/json'
                }
            });

            // Redirect customer to Shopify
            const checkoutCompleteUrl = `https://${shopifyStoreUrl}/checkout/order/${orderId}/thank_you`;
            res.redirect(checkoutCompleteUrl);
        } catch (error) {
            console.error('Error updating order status:', error);
            res.status(500).send('Internal Server Error');
        }
    } else {
        res.status(400).send('Invalid Payment Details');
    }
});

function verifyPaymentDetails(details) {
    // Implement your own verification logic
    return true;
}

const port = process.env.PORT || 3000;
app.listen(port, () => {
    console.log(`Server is running on port ${port}`);
});

 

 

If you still need help you can contact us

Click here to Contact and Get Shopify Store Help
E-mail - hi@ecommercesmalltask.com
We are Shopify Experts in India
Google My Business - Ecommerce Small Task
Anilket26
Shopify Partner
12 0 0

Hi
Thanks for reply!
I have only one question now. How to get the Order ID from the payment portal because Shopify did not send the order id in the payment session request?
I followed this doc.
https://shopify.dev/docs/apps/build/payments/request-reference#offsite-payment

Payment session request have request Id not the order Id.

Thanks