Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save staycreativedesign/7fc3e86a8464f5f348fb3402d048e8c1 to your computer and use it in GitHub Desktop.
Save staycreativedesign/7fc3e86a8464f5f348fb3402d048e8c1 to your computer and use it in GitHub Desktop.
class CheckIfDonorIsMemberService
def call
if Membership.find_by(email: @email)
@current_user = Membership.find_by(email: @email)
else
false
end
end
private
def initialize(params)
@email = params[:email]
end
end
def create
amount = CorrectMoneyService.new(params).call
if donor = CheckIfDonorIsMemberService.new(params).call
binding.pry
FindStripeId.new(@current_user, params).call
else
stripe = CreateStripeCustomerService.new(params).call
@current_user = Membership.create(name: params[:name], password: ' ', email: params[:email], role: 'donor', stripe_id: stripe.id)
session[:user_id] = @current_user.id
cookies[:temp_password] = @temp_password
end
donation_type = CheckChargeType.new(@current_user,params, amount).call
flash[:notice] = 'Thank you so much for your donation.'
redirect_to membership_path(@current_user)
rescue Stripe::CardError => e
flash[:error] = e.message
redirect_to new_donation_path
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment