Не приходят уведомления PayPal через активного продавца

Я работал над приложением, в котором мне нужно работать с ipn, но, похоже, оно не работает.

Я пытаюсь получить уведомление об успешном действии и указал правильный URL-адрес в песочнице PayPal.

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 ничего не возвращает (пусто)


person Dev R    schedule 27.08.2012    source источник


Ответы (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

Это обратный URL: -

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

Это URL-адрес уведомления: -

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
person Dev R    schedule 29.08.2012