Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Subscription's payment profile #158

Open
rscardinho opened this issue Oct 15, 2017 · 1 comment
Open

Update Subscription's payment profile #158

rscardinho opened this issue Oct 15, 2017 · 1 comment

Comments

@rscardinho
Copy link

rscardinho commented Oct 15, 2017

Hey,

In the platform that I'm working on, I got blocked (for a short period) because this gem doesn't support the change_payment_profile endpoint add by July 2016.

I was thinking about adding support for the endpoint and using it like this:

subscription = Chargify::Subscription.find(id)
payment_profile = Chargify::PaymentProfile.create

subscription.update_payment_profile(payment_profile.id)

Any suggestions?

API reference
https://reference.chargify.com/v1/subscriptions/cancel-subscription-remove-delayed-method#change-default-payment-profile

@blakeprudhomme
Copy link
Contributor

@rscardinho we ran into this issue as well when we wanted to allow our subscribers to add and/or switch between multiple payment methods. Currently we are accomplishing it like this...

module Chargify
  class SubscriptionPaymentProfile < Base
    set_prefix "/subscriptions/:subscription_id/"
    self.collection_name = "payment_profiles"
    include ResponseHelper

    def change_payment_profile
      post :change_payment_profile
    end
  end
end
def update_default_payment_profile(payment_profile_id)
  sub = Chargify::Subscription.find(sub_id)

  pp = Chargify::SubscriptionPaymentProfile.new
  pp.id = payment_profile_id
  pp.prefix_options = { subscription_id: sub.id }
  pp.instance_variable_set(:@persisted, true)
  pp.change_payment_profile
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants