Sha256: d9434934944db290fd80c282de28c59a6b7b536d8b0543c67c6c5ddd8c6f2021
Contents?: true
Size: 1.29 KB
Versions: 4
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) listing = subscription.listing subscription.charge_disputed end end end end
Version data entries
4 entries across 4 versions & 1 rubygems