0
我在做一個Web應用程序。我想讓用戶使用PayPal付款。一旦用戶付款,我希望貝寶向我發送通知,以更新「預訂」表中的'paid_at'列。爲了做到這一點,我使用IPN。這是我的代碼:PayPal Notification未收到Rails 4
控制器
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 => '[email protected]',
: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
如果我嘗試在本地主機上創建作爲貝寶不能將其發送到本地主機的通知。
curl -d "txn_id=1&invoice=2&payment_status=Completed" http://localhost:3000/payment_notifications
它正常工作! :D
但是,當我在Amazon上部署並且我希望PayPal向我發送通知時,它不起作用,將創建一個空PaymentNotification。我究竟做錯了什麼?
P.S .:我使用沙箱測試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"=>"[email protected]", "address_country"=>"United States", "num_cart_items"=>"1", "mc_handling1"=>"0.00", "address_city"=>"San Jose", "verify_sign"=>"AbzlMQfnGCW1kgs7W9U77Rx7TroaAGJzDnLnXH7bFEGd0xPQWC6s6R8I", "payer_email"=>"[email protected]", "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"=>"[email protected]", "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: [email protected]\naddress_country: United States\nnum_cart_items: '1'\nmc_handling1: '0.00'\naddress_city: San Jose\nverify_sign: AbzlMQfnGCW1kgs7W9U77Rx7TroaAGJzDnLnXH7bFEGd0xPQWC6s6R8I\npayer_email: [email protected]\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: [email protected]\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收到? – bobomoreno 2014-12-08 10:11:05
嗨!我已經添加了日誌文件。謝謝@bobomoreno:D – Naster 2014-12-08 14:28:56