Skip to content

Instantly share code, notes, and snippets.

@smoovej
Created November 20, 2012 17:05
Show Gist options
  • Save smoovej/4119290 to your computer and use it in GitHub Desktop.
Save smoovej/4119290 to your computer and use it in GitHub Desktop.
class TripProviders::WebService::SubscriptionPaymentsController < TripProviders::WebServiceController
def create
# unless params.has_key?( :data )
# return head :unprocessable_entity
# end
# errors = {}
# unless params.has_key?( :password ) and ! params[:password].blank?
# errors[ 'User' ] = { password: [ "can't be blank" ] }
# end
# return unless handle_validations( errors, @account, @user, @subscription )
# @account.save!
# @user.account = @account
# @user.save!
# @subscription.account = @account
# @subscription.save!
puts params.to_yaml
@subscription = Subscription.where( 'stripe_token = ?', params['data']['object']['customer'] )
@card = params['data']['object']['card']
puts @subscription.to_yaml
@subscription_payment = SubscriptionPayment.new
@subscription_payment.amount = params['data']['object'][ 'amount' ].to_i / 100.0
@subscription_payment.status = params['data']['object'][ 'paid' ] ? 'paid' : 'failed'
@subscription_payment.card_type = @card['type']
@subscription_payment.card_last4 = @card[ 'last4' ]
puts @subscription_payment.to_yaml
# @subscription_payment.subscription = @subscription
@subscription_payment.save!
# ####################################
head :created
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment