Sha256: 29fd691a7a00a10a8ca4acaca6ce9a6e33f64c3da903ec171bbe2265a1d7683c
Contents?: true
Size: 1.29 KB
Versions: 3
Compression:
Stored size: 1.29 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) subscription.charge_disputed end render nothing: true end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
koudoku-0.0.11 | app/controllers/koudoku/webhooks_controller.rb |
koudoku-0.0.10 | app/controllers/koudoku/webhooks_controller.rb |
koudoku-0.0.9 | app/controllers/koudoku/webhooks_controller.rb |