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 7_webhooks.md #791

Closed
wants to merge 1 commit into from
Closed

Update 7_webhooks.md #791

wants to merge 1 commit into from

Conversation

pyrabbit
Copy link

added eager_load caveat to custom webhook processor documentation

added eager_load caveat to custom webhook processor documentation
@pyrabbit
Copy link
Author

I wanted to add some additional documentation to the custom webhook processor documentation that could have helped me understand why my processors weren't executing in my development environment. Due to eager loading, the processors were never loaded into memory thus not registered with the Pay processor registry. If there is a better way to do this I would love to know.

@excid3
Copy link
Collaborator

excid3 commented Mar 10, 2023

Hmm, where are you defining your custom webhook processor class?

I haven't needed to ever enable eager loading for development and I don't think we want to recommend that. We should probably figure out the issue and then recommend a place to define the classes.

For example, I just put mine in config/initializers/pay.rb most times.

@excid3 excid3 closed this Mar 29, 2023
@pyrabbit
Copy link
Author

pyrabbit commented Apr 3, 2023

@excid3 Sorry I missed your response. I still experience this issue when I put them into the directory app/pay_processors/. For example consider the following in app/pay_processors/fulfill_checkout_processor.rb:

class FulfillCheckoutProcessor
  def call(event)
    order = event.data.object
    return if order.payment_status != "paid"
    checkout_session = Stripe::Checkout::Session.retrieve(order.id)
    pay_customer = Pay::Customer.find_by!(processor: :stripe, processor_id: checkout_session.customer)
    checkout_session.list_line_items.each do |item|
      Purchase.create!(
        user_id: pay_customer.owner_id,
        charge_method: 'Stripe::Checkout::Session',
        charge_id: checkout_session.id,
        product_id: item.price.product
      )
    end
  end
end

Pay::Webhooks.delegator.subscribe "stripe.checkout.session.completed", FulfillCheckoutProcessor.new
Pay::Webhooks.delegator.subscribe "stripe.checkout.session.async_payment_succeeded", FulfillCheckoutProcessor.new

Are you putting the delegator.subscribe pieces in app/initializers/pay.rb? If that is the case then maybe I can change this to reflect that.

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

Successfully merging this pull request may close these issues.

None yet

2 participants