经常性费用变更激活

Reccuring charge change activation

我构建了一个实现定期收费的应用程序 api 但我遇到了一些问题...

在文档 (https://help.shopify.com/api/reference/recurringapplicationcharge) 中指出:

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.

所以我有一些用户在“测试”定期收费,一些在“试用”...我如何“强迫”他们接受新计划(更改计划名称或价格)...

让我烦恼的是,您应该检查任何活跃的经常性费用,示例来自 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: "[=11=].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

负责检查活动付款的方法是 (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

免责声明:我从未在 ruby 中编码,我的应用程序也不是在 ruby 中构建的,但这是我能找到的唯一示例,其他只是官方测试应用程序的副本.

据我所知,此方法只是检查 API 是否有活动的经常性收费,然后再发出另一个经常性收费电话。

因此,如果我更改计划“名称”或“价格”,则不会发生任何事情,因为存在现有的“有效”经常性费用(检查是在调用创建新的经常性计划之前完成的)。

所以我不明白...我该怎么做?

还有当前测试用户会怎样(他们也有有效的“重复测试”费用),试用用户呢,试用期满后... Shopify 会删除“有效试用”重复计划吗?

谢谢大家的回答!

我还在 shopify 论坛上发布了这个:https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/reccuring-charge-change-activation-402080

只需删除处于测试或试用状态的有效费用,并发出新的费用。简单的。当商家选择接受新的费用时,它将取代旧的,应该提供给他们。