paypal自适应支付:ipnNotificationUrl

时间:2016-06-01 05:12:36

标签: ruby-on-rails ruby paypal controller paypal-ipn

我在PayPal中使用自适应支付。也使用ngrok进行测试。收到付款后,通常会通过通知。当通知传递时,我试图用t更新我的数据库。我没有从我的代码中收到t,如果没有数据库中的更新,我甚至知道notificationURL正在运行?也许有人可以帮助我?谢谢!!

在控制器的底部是我为数据库发出通知的地方。在paypal业务工具中,我把我的网站网址。

RegistrationsController:

def create 

         #send request to paypal
         @reservation = current_user.reservations.create(reservation_params)
        @reviser = Reviser.find(params[:reviser_id])

        if @reservation

            require 'paypal-sdk-adaptivepayments'


        reviserprice = @reservation.total
        commission = 0.05

        # Build API call
        @api = PayPal::SDK::AdaptivePayments.new
        @pay = @api.build_pay({
            :actionType => "PAY",
            :cancelUrl => "http://4e8c6120.ngrok.io/revisers/#{@reviser.id}",
            :returnUrl => "http://4e8c6120.ngrok.io/revisers/#{@reviser.id}",
            :currencyCode => "USD",
            :feesPayer => "SENDER",
            #ipnNotificationUrl                                     ipn_notify
            :ipnNotificationUrl => "http://4e8c6120.ngrok.io/paypal/ipn_notify",
            :item_name => "@reservation.reviser.essay_type",
            :item_number => "@reservation.id",
            :receiverList => {
                :receiver => [
                    {
                        :amount => reviserprice * 0.1,
                        :email => "birdsinthatcity-facilitator@gmail.com",
                        # :primary => true
                    },
                    {
                        #Before deploying make sure to change the email to current_user.email
                        :amount => reviserprice * 0.9,
                        :email => "birdsinthatcity-buyer@gmail.com",
                        # :primary => false
                    }
                ]
            },
        } || default_api_value)

        # Make API call
                    @pay_response = @api.pay(@pay)

        # Access Response
                if @pay_response.success? && @pay_response.payment_exec_status != "ERROR"
                  @pay_response.payKey

                    redirect_to @api.payment_url(@pay_response)  # Url to complete payment

                    # redirect_to @reservation.room, alert: "Yes"

                else
                  @pay_response.error
                    redirect_to @reservation.reviser, alert: "FUCK"
                end


        else
            redirect_to @reservation.reviser, alert: "Opps, Something went wrong!!"
    end
end

protect_from_forgery except: [:notify]
def notify
    params.permit!
    status = params[:payment_status]

    reservation = Reservation.find(params[:item_number])

    if status = "Completed"
        reservation.update_attributes status: true
    else
        reservation.destroy
    end
    render nothing: true
end

0 个答案:

没有答案