Sha256: e2fe046ffd5333616600705e71fb2fe0850159b6635f0f537f1d18664b2e38b7

Contents?: true

Size: 1.11 KB

Versions: 28

Compression:

Stored size: 1.11 KB

Contents

require_dependency "wbase/application_controller"

module Wbase
  class StripeWebhooksController < ApplicationController
    skip_before_filter :verify_authenticity_token

    def create
      @event = StripeWebhook.new(event_params)

      if @event.save
        @event.process!
        render json: @event
      else
        render json: @event.errors.full_messages, status: :unprocessable_entity
      end
    end

    private

    def event_params
      adaptor = WebhookAdaptor.new(params)
      adaptor.to_h
    end
  end

  class WebhookAdaptor
    attr_reader :params

    def initialize(params)
      @params = params
    end

    def external_id
      params['id']
    end

    def created
      Time.at(params['created'])
    end

    def to_h
      {
        external_id: external_id,
        object: params['object'],
        api_version: params['api_version'],
        created: created,
        data: params['data'],
        livemode: params['livemode'],
        pending_webhooks: params['pending_webhooks'],
        external_type: params['type'],
        external_request: params['request']
      }
    end
  end
end

Version data entries

28 entries across 28 versions & 1 rubygems

Version Path
wbase-0.3.20 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.19 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.18 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.17 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.16 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.15 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.14 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.13 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.12 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.11 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.10 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.9 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.8 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.7 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.6 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.5 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.4 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.3 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.2 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.3.1 app/controllers/wbase/stripe_webhooks_controller.rb