Skip to content

Instantly share code, notes, and snippets.

@jperrine
Created January 5, 2012 16:08
Show Gist options
  • Save jperrine/1565902 to your computer and use it in GitHub Desktop.
Save jperrine/1565902 to your computer and use it in GitHub Desktop.
stripe callbacks
class StripeCallbacksController < ApplicationController
def create
@user = User.find_by_stripe_customer_token(params[:customer])
if ["recurring_payment_failed", "recurring_payment_succeeded", "subscription_final_payment_attempt_failed"].include? params[:event]
send(params[:event])
end
respond_to do |format|
format.json { render :json => {}, :status => :ok }
end
end
private
def recurring_payment_failed
@user.last_payment_succeeded = false
@user.save(false)
end
def recurring_payment_succeeded
@user.last_payment_succeeded = true
@user.save(false)
end
def subscription_final_payment_attempt_failed
recurring_payment_failed
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment