I want to sent email to user after transcation done. now paypal is working fine for me, but user is not getting mail notification after transcation done? how to get email notification for user .
Here is my code This is my controller code
This is my paypal function
def pay if @order.update order_params @order.update_attributes(:invoice_id => rand.to_s[2..11]) if current_user.billing_address.blank? current_user.create_billing_address(@order.billing_address.dup.attributes) end if current_user.shipping_address.blank? current_user.create_shipping_address(@order.shipping_address.dup.attributes) end # @cart.calculate_shipping if @order.total == 0 return redirect_to checkout_thank_you_path end # if !params['payment'].present? # return redirect_to :back, notice: 'Select Payment Gateway!' # end # if params['payment']=='paypal' @order.order_statuses.create(status_type: 1) item_details=[] @order.line_items.each do |item| item_details << {:name => item.title, :quantity => item.quantity, :amount => item.amount.fractional} end logger.info item_details.inspect response = EXPRESS_GATEWAY.setup_purchase(@cart.total.fractional, :ip => request.remote_ip, :currency =>"USD", :items => item_details, :order_id => @order.invoice_id, :return_url => checkout_thank_you_url, :cancel_return_url => cart_url ) return redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token) # else # return redirect_to 'http://ift.tt/1eI8tja' # end else flash[:alert] = 'Billing and shipping address fields are required!' render :addresses end end
This is my thank function for paypal
def thank_you @order = Order.find(session[:order_id]) details = EXPRESS_GATEWAY.details_for(params[:token]) response = EXPRESS_GATEWAY.purchase(@cart.total.fractional, { ip: request.remote_ip, token: params[:token], payer_id: details.payer_id, items: @order.line_items.map{|l| {name: l.title, quantity: l.quantity, amount: l.amount.fractional}} }) if response.success? # logger.info payment_params.inspect payment_params = {gateway: 'PayPal Express Checkout', transaction_id: response.params['token'], ip: request.remote_ip, amount: response.params['gross_amount']} @cart.order.created_at = DateTime.now @cart.order.status = 'Paid' @cart.order.save session.delete :order_id # OrderMailer.order_confirmation(@order).deliver # OrderMailer.admin_receipt(@order).deliver else redirect_to :cart_checkout, alert: 'Something went wrong. Please try again. If the problem persists, please contact us.' end @cart = Cart.new current_or_null_user.id, session[:order_id], session[:currency] # Start a new cart end
Any help is appreciatable
Aucun commentaire:
Enregistrer un commentaire