Sha256: 85e4657d7730cd656935b03cff2720744de4a49457a33c6c19c5d1fccd3f52cb

Contents?: true

Size: 1.08 KB

Versions: 21

Compression:

Stored size: 1.08 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
        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

21 entries across 21 versions & 1 rubygems

Version Path
wbase-0.2.2 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.2.1 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.2.0 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.1.7 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.1.6 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.1.5 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.1.4 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.1.3 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.1.2 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.1.0 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.0.15 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.0.14 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.0.13 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.0.12 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.0.11 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.0.10 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.0.9 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.0.8 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.0.7 app/controllers/wbase/stripe_webhooks_controller.rb
wbase-0.0.6 app/controllers/wbase/stripe_webhooks_controller.rb