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

Friendly docs for beginners #135

Open
zsid opened this issue Jul 5, 2020 · 1 comment
Open

Friendly docs for beginners #135

zsid opened this issue Jul 5, 2020 · 1 comment

Comments

@zsid
Copy link

zsid commented Jul 5, 2020

Hi. Thank you very much for creating the gem. It really solves the problem of setup and verifications for Stripe.

I have just started picking up Rails again and really struggling to set up the gem. I have copied and pasted the examples and tried to make something work but to no vail. I was wondering what your thoughts are on creating an example folder and a rails project which people can clone and see it working.

I am doing webhooks by following the setup mentioned in Stripe's docs with stripe-cli. I can see that things are happening in my rails terminal when the app is running but when I tried to create a new order for example it failed. I have also tried using a logger but that didnt work either

config/stripe.rb

Stripe.api_key = Rails.application.credentials.dig(:stripe, :secrect_key) # this is not a type for the secret
StripeEvent.signing_secret = 'whsec_7KN2VtuaSbwZHf2KvgokYmhIqmN6CXA9'

StripeEvent.configure do |events|
  # events.subscribe 'checkout.session.completed', Stripe::CheckoutEventHandler.new
  # events.subscribe 'checkout.session.completed' do |event|

  # end
  events.all Testing::BillingEventLogger.new(Rails.logger)
  # events.subscribe 'checkout.session', Testing::CheckoutEventHandler.new

end

These are the different things that I have tried

app/services/testing/checkout_event_handler.rb
# module Stripe
#   class CheckoutEventHandler
#     def call(event)
#       begin
#         self.send handle_checkout_session_completed, event
#       rescue JSON::ParserError => e
#         # handle the json parsing error here
#         raise # re-raise the exception to return a 500 error to stripe
#       rescue NoMethodError => e
#         #code to run when handling an unknown event
#       end
#     end
  
#     def handle_checkout_session_completed(event)
#       Test.create(name: 'hi')
#     end
#   end

#   def Testing
#     def call(event)
#       Test.create(name: 'Testing')
#     end
#   end

# end

module Testing
  # class CheckoutEventHandler
  #   def call(event)
  #     begin
  #       self.send handle_checkout_session_completed, event
  #     rescue JSON::ParserError => e
  #       # handle the json parsing error here
  #       raise # re-raise the exception to return a 500 error to stripe
  #     rescue NoMethodError => e
  #       #code to run when handling an unknown event
  #     end
  #   end
  
  #   def handle_checkout_session_completed(event)
  #     Test.create(name: 'hi')
  #   end
  # end

  class BillingEventLogger
    def initialize(logger)
      @logger = logger
    end
  
    def call(event)
      @logger.info "I AM CALLED ******** ZHIVKO"
      @logger.info "BILLING:#{event.type}:#{event.id}"
    end
  end
end

Looking forward to your thoughts and any feedback welcome. Thanks.

@tannerhallman
Copy link

have you subscribed to those events in the stripe dashboard?

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