All things Shopify and commerce
We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more
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
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
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