ruby-on-rails - 将 text_field 自定义参数传递给 link_to paypal IPN

标签 ruby-on-rails paypal parameters parameter-passing paypal-ipn

当客户成功使用 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

enter image description here

问题

我如何让客户在字段中输入他们的电子邮件并将该值传递给 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/

相关文章:

C++ 将参数类型解释为构造函数

ms-access - MS Access 交叉表查询参数

ruby-on-rails - 为什么 Heroku 拒绝这个 git push?

paypal - 设置 PayPal 返回 URL 并使其自动返回?

c - 传递 char[] 参数根本不起作用

android - Android 版 PayPal MPL 返回错误 ID 589023

php - 有一种方法可以使用 paypal 进行类似预订的付款吗?

ruby-on-rails - 在 Rails 中扩展内置类功能的最佳位置在哪里?

ruby-on-rails - 在 rspec 中 stub 未实现的方法

css - LESS 优化与缩小 CSS 文件