簡體   English   中英

PayPal通知未收到Rails 4

[英]PayPal Notification is not receive Rails 4

我正在做一個Web應用程序。 我想讓用戶使用貝寶付款。 用戶付款后,我希望PayPal向我發送通知以更新表“ Bookings”的“ paid_at”列。 為了做到這一點,我正在使用IPN。 這是我的代碼:

控制者

class PaymentNotificationsController < ApplicationController
  protect_from_forgery :except => [:create]

  def create
    PaymentNotification.create!(:params => params, :booking_id => params[:invoice],     :status => params[:payment_status], :transaction_id => params[:txn_id])
    render :nothing => true
  end

end

視圖

<%= link_to "Pay tour", @booking.paypal_url(tour_booking_url(@tour, @booking), payment_notifications_url) %>

Booking.rb

def paypal_url(return_url, notify_url)
    values = {
        :business => 'tourify-facilitator@gmx.com',
        :cmd => '_cart',
        :upload => 1,
        :return => return_url,
        :notify_url => notify_url,
        :invoice => id,
        :currency_code => tour.currency
    }
    values.merge!({
        "amount_1" => tour.price,
        "item_name_1" => tour.title,
        "item_number_1" => tour.id,
        "quantity_1" => '1'
    })
    "https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query
  end

模型類PaymentNotification <ActiveRecord :: Base

    belongs_to :booking
    serialize :params
    after_create :booking_as_purchased

    private

        def booking_as_purchased
            if status == "Completed"
                booking.update_attribute(:paid_at, Time.now)
            end
        end

end

耙路

 payment_notification GET    /payment_notifications/:id(.:format)           payment_notifications#show
                      PATCH  /payment_notifications/:id(.:format)        payment_notifications#update
                      PUT    /payment_notifications/:id(.:format)        payment_notifications#update
                      DELETE /payment_notifications/:id(.:format)        payment_notifications#destroy

如果我在本地主機上嘗試,則會創建通知,因為PayPal無法將其發送到本地主機。

curl -d "txn_id=1&invoice=2&payment_status=Completed" http://localhost:3000/payment_notifications

而且它正常工作! :D

但是,當我在Amazon上部署並且希望PayPal向我發送通知時,該通知不起作用,將創建一個空的PaymentNotification。 我究竟做錯了什么?

PS:我使用沙盒測試PayPal。

日志:

Started POST "/payment_notifications" for xxx.xxx.xxx.xxx at 2014-12-08 14:18:15 +0000
Processing by PaymentNotificationsController#create as HTML
Parameters: {"mc_gross"=>"100.00", "invoice"=>"1", "protection_eligibility"=>"Eligible", "address_status"=>"confirmed", "item_number1"=>"1", "payer_id"=>"EFKVBTWPRKNG2", "tax"=>"0.00", "address_street"=>"1 Main St", "payment_date"=>"06:17:52 Dec 08, 2014 PST", "payment_status"=>"Pending", "charset"=>"windows-1252", "address_zip"=>"95131", "mc_shipping"=>"0.00", "mc_handling"=>"0.00", "first_name"=>"Test", "address_country_code"=>"US", "address_name"=>"Test Buyer", "notify_version"=>"3.8", "custom"=>"", "payer_status"=>"verified", "business"=>"buyer@xxx.com", "address_country"=>"United States", "num_cart_items"=>"1", "mc_handling1"=>"0.00", "address_city"=>"San Jose", "verify_sign"=>"AbzlMQfnGCW1kgs7W9U77Rx7TroaAGJzDnLnXH7bFEGd0xPQWC6s6R8I", "payer_email"=>"payer@xxx.com", "mc_shipping1"=>"0.00", "tax1"=>"0.00", "txn_id"=>"0C655528WK741393U", "payment_type"=>"instant", "last_name"=>"Buyer", "address_state"=>"CA", "item_name1"=>"Visit Málaga", "receiver_email"=>"xxx@xxx.com", "quantity1"=>"1", "receiver_id"=>"24D33E98DC7TW", "pending_reason"=>"multi_currency", "txn_type"=>"cart", "mc_gross_1"=>"100.00", "mc_currency"=>"EUR", "residence_country"=>"US", "test_ipn"=>"1", "transaction_subject"=>"", "payment_gross"=>"", "ipn_track_id"=>"fb978c14e5cf7"}
(0.1ms)  begin transaction
SQL (0.2ms)  INSERT INTO "payment_notifications" ("booking_id", "created_at", "params", "status", "transaction_id", "updated_at") VALUES (?, ?, ?, ?, ?, ?)  [["booking_id", 1], ["created_at", "2014-12-08 14:18:15.461260"], ["params", "--- !ruby/hash:ActionController::Parameters\nmc_gross: '100.00'\ninvoice: '1'\nprotection_eligibility: Eligible\naddress_status: confirmed\nitem_number1: '1'\npayer_id: EFKVBTWPRKNG2\ntax: '0.00'\naddress_street: 1 Main St\npayment_date: 06:17:52 Dec 08, 2014 PST\npayment_status: Pending\ncharset: windows-1252\naddress_zip: '95131'\nmc_shipping: '0.00'\nmc_handling: '0.00'\nfirst_name: Test\naddress_country_code: US\naddress_name: Test Buyer\nnotify_version: '3.8'\ncustom: ''\npayer_status: verified\nbusiness: tourify-facilitator@gmx.com\naddress_country: United States\nnum_cart_items: '1'\nmc_handling1: '0.00'\naddress_city: San Jose\nverify_sign: AbzlMQfnGCW1kgs7W9U77Rx7TroaAGJzDnLnXH7bFEGd0xPQWC6s6R8I\npayer_email: tourify-buyer@gmx.com\nmc_shipping1: '0.00'\ntax1: '0.00'\ntxn_id: 0C655528WK741393U\npayment_type: instant\nlast_name: Buyer\naddress_state: CA\nitem_name1: Visit Málaga\nreceiver_email: xxx@xxx.com\nquantity1: '1'\nreceiver_id: 24D33E98DC7TW\npending_reason: multi_currency\ntxn_type: cart\nmc_gross_1: '100.00'\nmc_currency: EUR\nresidence_country: US\ntest_ipn: '1'\ntransaction_subject: ''\npayment_gross: ''\nipn_track_id: fb978c14e5cf7\naction: create\ncontroller: payment_notifications\n"], ["status", "Pending"], ["transaction_id", "0C655528WK741393U"], ["updated_at", "2014-12-08 14:18:15.461260"]]

謝謝!

我有類似的問題。 要從PayPal接收IPN,需要在sendbox賣方帳戶首選項中設置通知URL。

要在本地測試IPN,可以使用https://ngrok.com/

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM