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

Confused about Gateway / Provider deprecations #2476

Closed
hhff opened this issue Jan 2, 2018 · 7 comments
Closed

Confused about Gateway / Provider deprecations #2476

hhff opened this issue Jan 2, 2018 · 7 comments

Comments

@hhff
Copy link

hhff commented Jan 2, 2018

Steps to reproduce

I'm making the switch from Spree to Solidus, and as part of the codebase (seeds, etc) we create orders programatically.

In Spree, I would do:

order = Spree::Order.create! email: "guest@user.com"
order.contents.add(Spree::Product.first.variants.first, 1)

# go to state: payment
order.next 

# create payment method
payment_method = Spree::Gateway::StripeGateway.where({
  name: "Credit Card",
  active: true,
  auto_capture: true
}).first_or_create!
payment_method.set_preference :secret_key, Rails.application.secrets[:stripe_secret_key]
payment_method.set_preference :publishable_key, Rails.application.secrets[:stripe_publishable_key]
payment_method.save

# fetch payment method
payment_method = Spree::Gateway::StripeGateway.first

# create credit card
credit_card = Spree::CreditCard.create!({
  number: "4111111111111111",
  month: 1,
  year: 2020,
  verification_value: 123,
  name: "Guest User"
})

# create order payment
payment = order.payments.create!({
  payment_method: payment_method,
  amount: order.total,
  source: credit_card
})

 # go to state: complete
order.next

System configuration

Solidus Version: 2.4.2

Deprecations produced:

DEPRECATION WARNING: Using Spree::Gateway as parent class of payment methods is deprecated. Please use Spree::PaymentMethod::CreditCard for credit card based payment methods or Spree::PaymentMethod for non credit card payment methods instead.

DEPRECATION WARNING: provider is deprecated and will be removed from Solidus 3.0 (use gateway instead)

DEPRECATION WARNING: provider_class is deprecated and will be removed from Solidus 3.0 (use gateway_class instead)

I had a look around and couldn't find much documentation on the change. How should I re-write the above in the new Solidus way so that it wont output deprecations?

Thanks for the hard work!

@jhawthorn
Copy link
Contributor

This was changed in Solidus 2.3 for more clear naming (See #2000). There should be no difference other than naming

@hhff
Copy link
Author

hhff commented Jan 2, 2018

Thanks @jhawthorn - to use Stripe would I do:

payment_method = Spree::PaymentMethod::StripeGateway.create! ?

ie - How do I refer to a specific gateway in the new format?

Also - as i understand it - that will only fix one of the deprecations. How would I fix the others?

@mamhoff
Copy link
Contributor

mamhoff commented Jan 3, 2018

@hhff The deprecations probably do not come out of code you wrote yourself, but out of the solidus_gateway gem . Try updating that.

@hhff
Copy link
Author

hhff commented Jan 4, 2018

I still don't understand I'm sorry. I'm using solidus_gateway: 1.2.0 which appears to be the latest release on Ruby Gems.

How do I create a Stripe Gateway in the new naming convention?

@kennyadsl
Copy link
Member

@hhff Spree::Gateway::StripeGateway.new/create should work. 1.2.0 is quite old (released on July 24, 2017), for now the new code is only on github master.

@hhff
Copy link
Author

hhff commented May 5, 2018

Hi All,

Noticed 1.3 is up on ruby gems, so I thought I'd take another stab at getting these deprecation warnings out of my Tests!

After updating, I'm having this same problem. This is the code change I'm making:

def test_gateway
    # -> From This
    #payment_method = Spree::Gateway::StripeGateway.where(name: "Credit Card", active: true, auto_capture: true).first_or_create!

    # -> To This
    payment_method = Spree::PaymentMethod::CreditCard.where(name: "Credit Card", active: true, auto_capture: true).first_or_create!

    # No changes after this line
    payment_method.set_preference :secret_key, Rails.application.secrets[:stripe_secret_key]
    payment_method.set_preference :publishable_key, Rails.application.secrets[:stripe_publishable_key]
    payment_method.save
    payment_method
end
  1) Wallet::CreateOrderPayouts will create the appropriate wallet_entries
     Failure/Error: payment_method.set_preference :secret_key, Rails.application.secrets[:stripe_secret_key]

     NoMethodError:
       secret_key preference not defined
     # /Users/hhff/.rvm/gems/ruby-2.3.1/gems/solidus_core-2.4.2/lib/spree/preferences/preferable.rb:81:in `has_preference!'
     # /Users/hhff/.rvm/gems/ruby-2.3.1/gems/solidus_core-2.4.2/lib/spree/preferences/preferable.rb:60:in `set_preference'
     # ./spec/rails_helper.rb:120:in `test_gateway'

The preferable module appears to not know about Stripe configs? I'm sure I'm not initializing the new payment_method correctly, but for the life of me can't figure out what I should be doing. Please advise!

Thank you! Solidus Rules!

@kennyadsl
Copy link
Member

Closing this one, there is https://github.com/solidusio-contrib/solidus_stripe that is compatible with the new naming and could be taken as a reference, just in case someone else is still looking for an answer.

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

5 participants