被错误地重定向到旧的PayPal UI

时间:2018-06-06 15:34:18

标签: paypal

我已经使用ruby on rails将paypal集成到我的电子商务中,但它总是重定向到旧的paypal UI而不是最新的UI。这是我提到的旧UI:

enter image description here

这里大致是我的代码。按下创建订单提交按钮后,我的订单控制器将重定向到加密的PayPal链接。

order_controller.rb

def create
    redirect_to @order.paypal_url(root_url, shipping_fees, payment_notification_url)

在我的订单模型中,加密链接代码如下:

order.rb

def paypal_url(return_url, shipping_fees, notify_url)
    encrypted = {
      :cmd => "_s-xclick",
      :encrypted => self.encrypt_for_paypal(return_url, shipping_fees, notify_url),
    }
    "https://www.paypal.com/cgi-bin/webscr?" + encrypted.to_query
end

def encrypt_for_paypal(return_url, shipping_fees, notify_url)
#def paypal_url(return_url, shipping_fees, notify_url)
  values = {
    :business => 'cxxx@hotmail.com',
    :cmd => '_cart',
    :upload => 1,
    :currency_code => 'MYR',
    :return => return_url,
    :invoice => self.number,
    :notify_url => notify_url,
    :cert_id => "XXX",

  }

  line_items.each_with_index do |item, index|
    values.merge!({
      "amount_#{index+1}" => item.final_price,
      "item_name_#{index+1}" => Product.where(id: item.variant.product_id).pluck(:title),
      "item_number_#{index+1}" => item.variant.SKU,
      "quantity_#{index+1}" => item.quantity,
      "shipping_1" => shipping_fees
    })
  end
  encrypted_paypal(values)
end



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 encrypted_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

请告知,因为我读到了我需要插入的地方:method => POST到链接,但我不知道如何。非常感谢

0 个答案:

没有答案