I've built an app which implements the recurring charge api and I have some issues...
In the docs (https://help.shopify.com/api/reference/recurringapplicationcharge) it states:
Each shop may have only one recurring charge per application. When a new RecurringApplicationCharge is activated for a shop that already has a recurring charge for that application, the existing recurring charge will be cancelled and replaced by the new charge. The new recurring charge will then activate. This means that upgrading and downgrading a user’s recurring charge or plan is straightforward; just change their plan, have them accept, and Shopify takes care of the rest.
So I have some users which I have on either "test" recurring charge and some on "trial"... how can I "force" them to accept the new plan (change of the name of the plan or price)...
The thing that bugs me is that you're supposed to check for any active reccuring charges, example from the app sample on github (https://github.com/Shopify/example-ruby-app/blob/master/02%20Charging%20For%20Your%20App/app.rb):
def create_recurring_application_charge # checks to see if there is already an RecurringApplicationCharge created and activated unless ShopifyAPI::RecurringApplicationCharge.current recurring_application_charge = ShopifyAPI::RecurringApplicationCharge.new( name: "Gift Basket Plan", price: 9.99, return_url: "https:\/\/#{APP_URL}\/activatecharge", test: true, trial_days: 7, capped_amount: 100, terms: "$0.99 for every order created") # if the new RecurringApplicationCharge saves,redirect the user to the confirmation URL, # so they can accept or decline the charge if recurring_application_charge.save @tokens[:confirmation_url] = recurring_application_charge.confirmation_url redirect recurring_application_charge.confirmation_url end end end
the method in charge of checking for an active payment is (https://github.com/Shopify/shopify_api/blob/master/lib/shopify_api/resources/recurring_application_charge.rb):
module ShopifyAPI class RecurringApplicationCharge < Base undef_method :test class << self def current (all || []).find { |c| c.status == 'active' } end [:pending, :cancelled, :accepted, :declined].each do |status| define_method(status) { (all || []).select { |c| c.status == status.to_s } } end end def usage_charges UsageCharge.find(:all, params: { recurring_application_charge_id: id }) end def cancel load_attributes_from_response(self.destroy) end def activate load_attributes_from_response(post(:activate)) end def customize(customize_recurring_app_charge_params = {}) load_attributes_from_response(put(:customize, recurring_application_charge: customize_recurring_app_charge_params )) end end end
Disclaimer: I've never coded in ruby nor is my app built in ruby, but this is the only example I could find, other were just carbon copies of the official test app.
So as far as I undrestand this method just checks the API for an active reccuring charge before issuing another reccuring charge call.
So If I change the plan "name" or "price" nothing is going to happen because there's an existing 'active' recurring charge (the check is done before the call to create a new reccuring plan).
So I don't get it... how can I make this work?
Also what happens to the current test users (they also have a valid 'reccuring test' charge), what about trial users, after trial expiration... does Shopify delete the 'active trial' reccuring plan?
Thank you for all your answers!
I've also posted this on the shopify forums: https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/reccuring-charge-change-activation-402080