Sha256: ae2534c306f2586d549bc21de42eb45d7f3a667e27218303a6c98c03ffdea06a
Contents?: true
Size: 1.33 KB
Versions: 1
Compression:
Stored size: 1.33 KB
Contents
module Koudoku class WebhooksController < ApplicationController def create raise "API key not configured. For security reasons you must configure this in 'config/koudoku.rb'." unless Koudoku.webhooks_api_key.present? raise "Invalid API key. Be sure the webhooks URL Stripe is configured with includes ?api_key= and the correct key." unless params[:api_key] == Koudoku.webhooks_api_key data_json = JSON.parse request.body.read if data_json['type'] == "invoice.payment_succeeded" stripe_id = data_json['data']['object']['customer'] amount = data_json['data']['object']['total'].to_f / 100.0 subscription = ::Subscription.find_by_stripe_id(stripe_id) subscription.payment_succeeded(amount) elsif data_json['type'] == "charge.failed" stripe_id = data_json['data']['object']['customer'] subscription = ::Subscription.find_by_stripe_id(stripe_id) subscription.charge_failed elsif data_json['type'] == "charge.dispute.created" stripe_id = data_json['data']['object']['customer'] subscription = ::Subscription.find_by_stripe_id(stripe_id) listing = subscription.listing subscription.charge_disputed end render nothing: true end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
koudoku-0.0.8 | app/controllers/koudoku/webhooks_controller.rb |