App reviews, troubleshooting, and recommendations
Hi guys,
i am trying to implement Shopify app recurring charge but i can't find proper Node JS code for the reference. can anyone please share?
I am doing this first time hence need proper example.
Thanks in advance 🙂
Hey @Girish_Rajwani
Sure! I can provide you with an example of how to implement Shopify app recurring charges using Node.js. Below is a sample code snippet that demonstrates how to create a recurring charge for a Shopify app using the Shopify API and the 'shopify-api-node' package:
const Shopify = require('shopify-api-node');
// Create a new instance of the Shopify API client
const shopify = new Shopify({
shopName: 'your-shop.myshopify.com',
apiKey: 'your-api-key',
password: 'your-api-password',
});
// Set up the recurring charge parameters
const recurringCharge = {
name: 'Your Recurring Charge',
price: '9.99',
return_url: 'https://your-app.com/charge/accepted',
test: true, // Set to false when testing is complete
trial_days: 7, // Optional trial period
};
// Create the recurring charge
shopify.recurringApplicationCharge.create(recurringCharge)
.then(charge => {
console.log(charge);
// Redirect the user to the confirmation URL
// charge.confirmation_url will contain the URL
})
.catch(error => {
console.error(error);
});
Make sure to replace 'your-shop.myshopify.com', 'your-api-key', and 'your-api-password' with your actual Shopify store's domain, app API key, and app API password respectively. Also, customize the 'recurringCharge' object with the relevant details for your recurring charge.
This example uses the 'shopify-api-node package', which provides a convenient way to interact with the Shopify API in Node.js. You can install this package by running 'npm install shopify-api-node' in your project directory.
Note that this is just a basic example, and you may need to modify it according to your specific requirements and application logic. Refer to the Shopify API documentation for more information on the available methods and options for recurring charges.
If I managed to help you then, don't forget to Like it and Mark it as Solution!
Best Regards,
Moeed
hey moeed,
getting 401 unauthorized error. i am using default scaffold provided by Shopify. can you please share that whole code OR Link ?
I'm also facing a challenge with implementing recurring charges in Shopify app. Have you found any solution?
Explore the 30-30-30 rule, a dynamic social media strategy for new businesses. Learn how t...
By Trevor Sep 20, 2023Discover how to leverage the often overlooked footer of your ecommerce site to gain custom...
By Skye Sep 15, 2023In this blog, we’ll be shining a light on Shopify Partners, Experts, and Affiliates. Who a...
By Imogen Sep 13, 2023