【问题标题】:Not receiving paypal notifications through active merchant未通过活跃商家收到贝宝通知
【发布时间】:2012-08-21 23:20:24
【问题描述】:

我正在开发一个需要使用 ipn 的应用程序,但它似乎无法正常工作。

我正在尝试在成功操作中获取通知,并在 paypal 沙箱中指定了正确的 url。

def success
        topup = current_user.topups.last
        logger.debug "topup -------->"
        logger.debug topup.amount.to_i
        # raise request
        details = EXPRESS_GATEWAY.details_for(topup.express_token)
        logger.debug "details ------->"
        logger.debug details.payer_id
        # raise params[:payer_id]
        response = EXPRESS_GATEWAY.purchase(topup.price_in_cents,{
          :ip               => request.remote_ip,
          :token            => topup.express_token,
          :payer_id         => details.payer_id
        })

        logger.debug "Response starts here --------->"
        logger.debug response

        if response.success?
            amount = topup.amount.to_i
            current_user.credits = current_user.credits.to_i +  amount
            current_user.save!
            flash[:success] = "Thank you for the top up"
            # @account_history = current_user.account_histories.build
            # @account_history.update_attribute(:type => "Top Up", :details => "", :amount => amount, :user_id => current_user.id)
            redirect_to current_user


            notify = Paypal::Notification.new request.raw_post

            logger.info "Notifying --------->"
            logger.info notify
            logger.info notify.status
            logger.info "Notifying 2 --------->"
            logger.info notify.acknowledge

            logger.debug notify.status

            if notify.acknowledge
                logger.debug "Notifying --------->"
                logger.debug notify.mc_gross
                logger.debug notify.txn_id
            end

        else
            redirect_to root_url
        end

    end

notify.acknowledge 不返回任何内容(它是空白的)

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 paypal-ipn activemerchant


    【解决方案1】:

    在敲了很长时间之后,我能够解决这个问题。发布我的解决方案以防万一有人陷入类似情况:-

    重要的一点是 IPN 将发布数据发送到 IPN 侦听器,因此请确保为此定义了路由。

    我还有一个 before_filter :authenticate_user! ,因此我得到了 html 代码 401。必须在过滤器之前跳过通知操作。

    def pay_with_account
            topup = Topup.find(params[:id])
            response = EXPRESS_GATEWAY.setup_purchase(topup.price_in_cents,{
              :ip                => request.remote_ip,
              :currency_code     => 'GBP',
              :return_url        => topups_success_url(topup),
              :notify_url        => topups_notify_url(topup),
              :cancel_return_url => topups_cancel_url(topup),
              # :allow_guest_checkout => true,
              :items => [{:name => "Topup", :quantity => 1,:description => "Top up my account", :amount => topup.price_in_cents}]
            })
            topup.update_attribute :express_token, response.token
            redirect_to EXPRESS_GATEWAY.redirect_url_for(response.token)
        end
    

    这是返回网址:-

    def success
            topup = current_user.topups.last
            details = EXPRESS_GATEWAY.details_for(topup.express_token)
            response = EXPRESS_GATEWAY.purchase(topup.price_in_cents,{
              :ip               => request.remote_ip,
              :currency_code    => 'GBP',
              :token            => topup.express_token,
              :payer_id         => details.payer_id
            })
    
            if response.success?
                amount = topup.amount.to_i
                current_user.credits = current_user.credits.to_i +  amount
                current_user.save!
                redirect_to user_payments_path(current_user)
                flash[:success] = "Your transaction was successfully completed"
            else
                flash[:error] = "Your transaction could not be compelted"
                redirect_to user_payments_path(current_user)
            end
    
        end
    

    这是通知网址:-

    def notify
            notify = Paypal::Notification.new(request.raw_post) 
    
            if notify.acknowledge
                @account_history = topup.user.account_histories.build
                @account_history.update_attributes(:payment_type => "Top up",:status => notify.status, :amount => notify.gross)
                if params[:payer_status] == "verified"
                    @account_history.update_attributes(:details => "Pay Pal #{@account_history.id}")
                elsif params[:payer_status] == "unverified"
                    @account_history.update_attributes(:details => "Credit Card #{@account_history.id}")
                end
                @account_history.save
            end
    
             render :nothing => true
        end
    

    路线:-

      get "topups/pay_with_account"
      get "topups/pay_without_account"
      get "topups/success"
      get "topups/cancel"
      get "topups/notify"
      post "topups/notify
    

    【讨论】:

      猜你喜欢
      • 2016-04-15
      • 2016-07-31
      • 2016-03-07
      • 1970-01-01
      • 1970-01-01
      • 2018-06-29
      • 1970-01-01
      • 1970-01-01
      • 2011-07-08
      相关资源
      最近更新 更多