Created
May 1, 2019 19:38
-
-
Save staycreativedesign/7fc3e86a8464f5f348fb3402d048e8c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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