ruby 中的 Apple Pay 网络商家会话

Apple Pay on the web merchant session in ruby

我似乎无法使用 Ruby 进行商家会话验证。尝试了 HTTParty 和 RestClient,我得到:

OpenSSL::SSL::SSLError (SSL_connect returned=1 errno=0 state=SSLv3 read finished A: sslv3 alert certificate expired:

我用这个节点服务器示例尝试了相同的证书,https://github.com/tomdale/apple-pay-merchant-session-server,它工作正常,所以它一定是我的 ruby 代码中的东西。

有没有人设法让这个工作?

我遇到了同样的问题。在您引用的示例和 https://github.com/norfolkmustard/ApplePayJS (see also the discussion about the implementation at https://forums.developer.apple.com/thread/51580) 中的实施的帮助下,我能够使其正常工作。

我的关键是传递正确的证书(Apple Pay 商家身份证书),就像 Apple 提供的那样,并像这样获取证书密钥:

Once you have your Merchant ID (session) certificate from Apple, import that into keychain.app on your Mac by double-clicking it, right click on the cert in keychain and export the combined private-key and cert as a .p12 file then, in terminal:-

openssl pkcs12 -in your_merchant_identity_cert_name.p12 -out ApplePay.key.pem -nocerts -nodes

将来自 Apple 的 Apple Pay 商家标识证书和 ApplePay.key.pem 文件的内容添加到环境变量后,我能够使用 Ruby 的 [=27= 构造以下请求] class...

class YourControllerName < ApplicationController

  def apple_pay_validation
    respond_to do |format|
      format.json { render json: start_apple_session(params[:url]) } if params[:url].include?('apple.com')
    end
  end

  private

  def start_apple_session(url)
    uri = URI.parse(url) # the url from event.validationURL
    data = {'merchantIdentifier' => "merchant.com.your_site_name", 'domainName' => "your_doamin", 'displayName' => "your_company_name"}
    pem = File.read('path/to/your/merchant_id.cer')
    key = ENV['APPLE_PAY_MERCHANT_ID_ KEY']
    passphrase = 'passphrase set up when exporting certificate in keychain' # Should be an environment variable
    http = Net::HTTP.new(uri.host, uri.port)
    http.use_ssl = true
    http.ssl_version = :TLSv1_2
    http.ciphers = ['ECDHE-RSA-AES128-GCM-SHA256']
    http.cert = OpenSSL::X509::Certificate.new(pem)
    http.key = OpenSSL::PKey::RSA.new(key, passphrase)
    http.verify_mode = OpenSSL::SSL::VERIFY_PEER
    request = Net::HTTP::Post.new(uri.request_uri, 'Content-Type' => 'application/json')
    request.body = data.to_json
    response = http.request(request)
    response.body
  end

end

这是从我的 performValidation 函数(从上面列出的 ApplePayJS 存储库修改而来)调用的,看起来像这样..

performValidation = (valURL) ->
  new Promise((resolve, reject) ->
    xhr = new XMLHttpRequest
    xhr.open 'GET', '/your_controller_name/apple_pay_validation?url=' + valURL
    xhr.onerror = reject
    xhr.onload = ->
      data = JSON.parse(@responseText)
      resolve data
    xhr.send()
  )

希望这有助于节省一些时间和白发!