ruby-on-rails - Railscast 143(Paypal 安全)导致 "We were unable to decrypt the certificate id."

标签 ruby-on-rails paypal railscasts

正在做 railscast #143。代码如下。当我添加安全内容时,我得到“我们无法解密证书 ID”。开发中。当我把安全的东西拿出来时,它又能正常工作了。我已经用新证书等重做了整个过程几次。没有运气。

对接下来要尝试什么有什么想法吗?

我遇到了与这篇文章中完全相同的问题,它在生产中遇到过它并且神奇地开始工作:

Can't get PayPal Encrypted Website Payments to work in Rails

在“购买这些”页面中:

<%= form_tag "https://www.sandbox.paypal.com/cgi-bin/webscr" do %>
<%= hidden_field_tag :cmd, "_s-xclick" %>
<%= hidden_field_tag :encrypted, @cart.paypal_encrypted("#{@url}/buy_these", payment_notifications_url) %>
<p><%= submit_tag "Buy these for #{number_to_currency(@cart.total_price)}" %></p>

在 cart.rb 中:

PAYPAL_CERT_PEM = File.read("#{Rails.root}/certs/paypal_cert.pem")
APP_CERT_PEM = File.read("#{Rails.root}/certs/app_cert.pem")
APP_KEY_PEM = File.read("#{Rails.root}/certs/app_key.pem")

def encrypt_for_paypal(values)
    signed = OpenSSL::PKCS7::sign(OpenSSL::X509::Certificate.new(APP_CERT_PEM), OpenSSL::PKey::RSA.new(APP_KEY_PEM, ''), values.map { |k, v| "#{k}=#{v}" }.join("\n"), [], OpenSSL::PKCS7::BINARY)
    OpenSSL::PKCS7::encrypt([OpenSSL::X509::Certificate.new(PAYPAL_CERT_PEM)], signed.to_der, OpenSSL::Cipher::Cipher::new("DES3"), OpenSSL::PKCS7::BINARY).to_s.gsub("\n", "")
end

def paypal_encrypted(return_url, notify_url)
  values = {
    :business => 'seller_1316654707_biz@myurl.com',
    :cmd => '_cart',
    :upload => 1,
    :return => return_url,
    :invoice => id,
    :notify_url => notify_url,
    :cert_id => 'DVFY6JS476MR8'
  }
things.each_with_index do |item, index|
    values.merge!({
      "amount_#{index+1}" => item.price,
      "item_name_#{index+1}" => item.id,
      "item_number_#{index+1}" => item.id,
      "quantity_#{index+1}" => 1
    })
  end
  encrypt_for_paypal(values)
end

最佳答案

我又重复了几次整个过程,它开始起作用了。还审查了类似于下一个答案的过程中的每个值。不幸的是,每当我切换部署平台时,我似乎都会遇到同样的问题。最终,它再次开始工作。

关于ruby-on-rails - Railscast 143(Paypal 安全)导致 "We were unable to decrypt the certificate id.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7864250/

相关文章:

ruby-on-rails - 语法错误,意外的 ':',期望使用Rails 3以Stripe形式出现 ')'

javascript - 用coffeescript中的图像替换文本

ruby-on-rails - rails : undefined method Error when scoping

ruby-on-rails - rails + 设计 : Custom login failure flash messages?

ruby-on-rails - Rails 中的分片表合并为单个 ActiveRecord 模型

收款人为 paypal_id 的 PayPal 付款

javascript - wordpress 中用于 paypal 按钮的复选框验证

ruby-on-rails - 最小化 json 文档大小会提高 Elasticsearch 的性能吗?

.net - PayPal:付款金额为 'Value too long (max length 10)'

ruby-on-rails - ActiveSupport::TimeZone 偏移量字符串列表