【问题标题】:Apple Pay on the web merchant session in rubyruby 中的 Apple Pay 网络商家会话
【发布时间】:2017-01-25 07:38:39
【问题描述】:

我似乎无法使用 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​​ 代码中的东西。

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

【问题讨论】:

    标签: ruby applepay


    【解决方案1】:

    我遇到了同样的问题。在您引用的示例和https://github.com/norfolkmustard/ApplePayJS 的实现的帮助下(另请参阅https://forums.developer.apple.com/thread/51580 关于实现的讨论),我能够让它工作。

    对我来说,关键是传递正确的证书(Apple Pay Merchant Identity 证书),就像 Apple 提供的一样,并像这样获取证书密钥:

    从 Apple 获得 Merchant ID(会话)证书后,通过双击将其导入 Mac 上的 keychain.app,右键单击钥匙串中的证书并将组合的私钥和证书导出为 . p12 文件,然后在终端:-

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

    将 Apple 的 Apple Pay Merchant Identification 证书和 ApplePay.key.pem 文件的内容添加到环境变量后,我能够使用 Ruby 的 Net::HTTP 类构造以下请求...

    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()
      )
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-01-03
      • 1970-01-01
      • 2019-07-31
      • 2021-03-08
      • 1970-01-01
      • 2019-04-14
      • 2020-04-30
      • 2020-04-16
      相关资源
      最近更新 更多