Skip to main content

Stripe connect managed accounts

Rails • Asked by josh edgar

I'm trying to add webhooks to stripe using stripe connect and managed accounts https://stripe.com/docs/connect/webhooks

I'm using the stripe_events plugin and have followed your stripe webhooks video. I nearly have it working but I have to add an "account" attribute somewhere?!?! I've been looking at the screen to long. Can you please help!

#initializers/strip.rb

Stripe.api_key = Rails.configuration.stripe[:secret_key]

class RecordAccount
    def call(event)
        event = event.data.object
        account = event.account

        #Look up StripeAccount in our database
        stripe_account = StripeAccount.where(stripe_id: account).last

        #Record Verification details, status in StripeAccount
        u = stripe_account.update_attributes(verification_status: event.legal_entity.verification.status, verification_details: event.legal_entity.verification.details)
        u.save

    end
end


StripeEvent.configure do |events|
  events.subscribe 'account.updated', RecordAccount.new
end

Ended up removing the stripe_event gem and set up webhooks manually. Was very easy...

created a webhooks_controller.rb and new post route

begin
            payload = JSON.parse(request.body.read)
            # Verify the event by fetching it from Stripe
            if payload['account'].present?

              # This is for connected accounts
              event = Stripe::Event.retrieve(payload['id'], stripe_account: payload['account'])
              @stripe_object = event.data.object
              @stripe_account_update = StripeAccount.where(stripe_id: payload['account']).first!

                    # update verification status etc in db
              u = @stripe_account_update.update_attributes(
                    verification_status: @stripe_object.legal_entity.verification.status, 
                    verification_details: @stripe_object.verification.fields_needed
                )

            else
              # Normal events not using stripe_event
              Stripe::Event.retrieve(payload['id'])
            end

            rescue Stripe::StripeError => e
            # Handle this however you prefer
            raise ActiveRecord::RecordNotFound.new(e)
        end

Only thing I need to figure out is how to read the event type "account_created", "account_updated" etc. Haven't looked into it yet. But I'm sure there's nothing to it.


Login or Create An Account to join the conversation.

Subscribe to the newsletter

Join 24,647+ developers who get early access to new screencasts, articles, guides, updates, and more.

    By clicking this button, you agree to the GoRails Terms of Service and Privacy Policy.

    More of a social being? We're also on Twitter and YouTube.