Shopify app recurring charge

Girish_Rajwani
Shopify Partner
70 1 7

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 🙂 

Replies 4 (4)
Moeed
Shopify Partner
2336 591 706

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

Need a Shopify developer? Chat on WhatsApp


- For Shopify Design Changes | Shopify Custom Coding | Custom Modifications

- Expert in Shopify SEO optimization for higher search rankings.


- Your Coffee Tip , my code - a perfect blend! ❤️
Girish_Rajwani
Shopify Partner
70 1 7

hey moeed,

 

getting 401 unauthorized error. i am using default scaffold provided by Shopify. can you please share that whole code OR Link ?

RidaH
Shopify Partner
2 0 0

Hi @Girish_Rajwani 


I'm also facing a challenge with implementing recurring charges in Shopify app. Have you found any solution?

Girish_Rajwani
Shopify Partner
70 1 7

@RidaH  yes it was working but since one day it is giving 422 error.

 

what issue are you facing ?