如何使用paypal完成付款后向用户发送电子邮件

时间:2015-11-20 08:01:11

标签: ruby-on-rails ruby-on-rails-3 paypal ruby-on-rails-3.2 paypal-sandbox

我想在完成交易后向用户发送电子邮件。现在paypal对我来说工作正常,但用户在完成交易后没有收到邮件通知?如何获取用户的电子邮件通知。

这是我的代码 这是我的控制器代码

这是我的paypal功能

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 'https://www.payumoney.com/'
      # end
    else
      flash[:alert] = 'Billing and shipping address fields are required!'
      render :addresses
    end
end

这是我对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

任何帮助都是值得赞赏的

0 个答案:

没有答案