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

[BUG] Pay::Stripe::Charge.sync(charge.id) fails with method_missing error for `stripe_receipt_url= #1123

Open
marckohlbrugge opened this issue Dec 24, 2024 · 0 comments

Comments

@marckohlbrugge
Copy link
Contributor

marckohlbrugge commented Dec 24, 2024

Pay::Stripe::Charge.sync(some_charge_id)

Raises the following error:

(betalist):19:in `<main>': unknown attribute 'stripe_receipt_url' for Pay::Charge. (ActiveModel::UnknownAttributeError)

      raise UnknownAttributeError.new(self, name)
      ^^^^^
/usr/local/bundle/ruby/3.3.0/gems/activemodel-8.0.1/lib/active_model/attribute_methods.rb:512:in `method_missing': undefined method `stripe_receipt_url=' for an instance of Pay::Charge (NoMethodError)
Did you mean?  stripe_account=
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/attribute_methods.rb:495:in `method_missing'
        from /usr/local/bundle/ruby/3.3.0/gems/activemodel-8.0.1/lib/active_model/attribute_assignment.rb:69:in `public_send'
        from /usr/local/bundle/ruby/3.3.0/gems/activemodel-8.0.1/lib/active_model/attribute_assignment.rb:69:in `_assign_attribute'
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/attribute_assignment.rb:17:in `block in _assign_attributes'
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/attribute_assignment.rb:9:in `each'
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/attribute_assignment.rb:9:in `_assign_attributes'
        from /usr/local/bundle/ruby/3.3.0/gems/activemodel-8.0.1/lib/active_model/attribute_assignment.rb:34:in `assign_attributes'
        from /usr/local/bundle/ruby/3.3.0/gems/activemodel-8.0.1/lib/active_model/api.rb:81:in `initialize'
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/core.rb:467:in `initialize'
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/inheritance.rb:76:in `new'
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/inheritance.rb:76:in `new'
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/reflection.rb:183:in `build_association'
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/associations/association.rb:384:in `build_record'
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/associations/collection_association.rb:362:in `_create_record'
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/associations/has_many_association.rb:147:in `_create_record'
        from /usr/local/bundle/ruby/3.3.0/gems/activerecord-8.0.1/lib/active_record/associations/association.rb:232:in `create!'

Related code:

store_accessor :data, :stripe_receipt_url


Explanation and suggested solution by AI:

The charge creation in sync goes through the charges association on Pay::Customer, which uses the base Pay::Charge class. At this point, the base class doesn't know about the additional attributes defined in the subclass.

Solution

Modify how charges are created in the sync method to use Pay::Stripe::Charge directly instead of going through the association:

# Instead of using:
pay_customer.charges.create!(attrs.merge(processor_id: object.id))

# Use:
Pay::Stripe::Charge.create!(attrs.merge(processor_id: object.id, customer: pay_customer))

This ensures the Stripe-specific class is used when creating new charge records, allowing processor-specific attributes to be defined in Pay::Stripe::Charge.

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

1 participant