GithubHelp home page GithubHelp logo

Comments (9)

priyank-gupta avatar priyank-gupta commented on September 14, 2024 1

@cellis Thanks!!!.
I think we should use Spree.user_class across this extension to work with custom user models.
@praveendhawan Can you look into this ?

from spree-account-recurring.

cellis avatar cellis commented on September 14, 2024

Same problem.

from spree-account-recurring.

praveendhawan avatar praveendhawan commented on September 14, 2024

@abrambailey, @cellis Could you please specify the steps to reproduce this problem.

from spree-account-recurring.

cellis avatar cellis commented on September 14, 2024

@abrambailey, @praveendhawan this is probably happening because I'm not using Spree::User but instead using custom authentication, which user_decorator.rb is unable to see, and therefore has_many :subscriptions doesn't get added. I tried adding has_many :subscriptions, class_name: "Spree::Subscriptions" but that doesn't work either.

from spree-account-recurring.

priyank-gupta avatar priyank-gupta commented on September 14, 2024

@cellis Can you try adding has_many :subscriptions, class_name: 'Spree::Subscription' in your user model ?

from spree-account-recurring.

cellis avatar cellis commented on September 14, 2024

@priyank-gupta I've already tried that.

from spree-account-recurring.

priyank-gupta avatar priyank-gupta commented on September 14, 2024

@cellis Yeah, but the code you pasted above has s in Spree::Subscription. Not sure if its a typo you did here or in code.

from spree-account-recurring.

cellis avatar cellis commented on September 14, 2024

@priyank-gupta yeah I typed that out manually. I get the same problem.

from spree-account-recurring.

cellis avatar cellis commented on September 14, 2024

Alright, I've figured it out, for anyone coming after and seeing this bug:

If you use custom authentication, you'll need to create your own user decorator.

#spree-app/app/models/user_decorator.rb
#note, not using Spree::User
User.class_eval do
  has_many :subscriptions, class_name: "Spree::Subscription", foreign_key: "user_id"

  def find_or_create_stripe_customer(token=nil)
    return api_customer if stripe_customer_id?
    customer = if token
      Stripe::Customer.create(description: email, email: email, card: token)
    else
      Stripe::Customer.create(description: email, email: email)
    end
    update_column(:stripe_customer_id, customer.id)
    customer
  end

  def api_customer
    Stripe::Customer.retrieve(stripe_customer_id)
  end
end

After adding this file, I see

Running via Spring preloader in process 17727
Loading development environment (Rails 4.2.2)
oirb(main):001:0> User.first.subscriptions
  User Load (4.8ms)  SELECT  "users".* FROM "users"  ORDER BY "users"."id" ASC LIMIT 1
  Spree::Subscription Load (0.3ms)  SELECT "spree_subscriptions".* FROM "spree_subscriptions" WHERE "spree_subscriptions"."user_id" = $1  [["user_id", 1]]
=> #<ActiveRecord::Associations::CollectionProxy []>
irb(main):002:0>

from spree-account-recurring.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.