当客户成功使用 paypal 进行交易时,我正在尝试向他发送电子邮件。
我已经设法在 custom 中将自定义 email
参数发送到 paypal|他们提供的参数。
我现在拥有的
我的产品
模型:
class Product < ActiveRecord::Base
# This defines the paypal url for a given product sale
def paypal_url(return_url, cancel_return, useremail)
values = {
:business => 'your_business_email@example.com',
:cmd => '_xclick',
:upload => 1,
:return => return_url,
:rm => 2,
:cancel_return => cancel_return,
:custom => useremail
}
values.merge!({
"amount" => unit_price,
"item_name" => name,
"item_number" => id,
"quantity" => '1'
})
# For test transactions use this URL
"https://www.sandbox.paypal.com/cgi-bin/webscr?" + values.to_query
end
has_many :payment_notifications
end
在这里,我为 :custom
对象传递了一个参数,我在按钮 link_to
帮助程序中对其进行了硬编码:
<%= link_to 'checkout', @product.paypal_url(payment_notification_index_url, root_url, 'testing@testing.com') %>
这非常有效,我能够将自定义
电子邮件存储在数据库中:
class PaymentNotificationController < ApplicationController
protect_from_forgery except: [:create]
def create
# @payment = PaymentNotification.create!(params: params, product_id: params[:invoice], status: params[:payment_status], transaction_id: params[:txn_id] )
@payment = PaymentNotification.create!(params: params, product_id: 1, status: params[:payment_status], transaction_id: params[:txn_id], email: params[:custom] )
# render nothing: true
if @payment.status == 'Completed'
PaymentTransactions.success(@payment).deliver_now
redirect_to root_url, notice: 'Success!'
else
redirect_to root_url, notice: 'Error'
end
end
end
问题
我如何让客户在字段中输入他们的电子邮件并将该值传递给 link_to
的参数,以便 paypal 返回电子邮件,以便我可以将其存储在数据库中并发送给客户发邮件?
谢谢
最佳答案
你不应该使用 link_to,而应该使用 form_tag 方法::get
<%= form_tag (@product.paypal_url(payment_notification_index_url, root_url, :custom)),method: :post do %>
<%= text_field_tag :custom %>
<%= submit_tag 'checkout' %>
<% end %>
关于ruby-on-rails - 将 text_field 自定义参数传递给 link_to paypal IPN,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31999516/