2016-09-17 38 views
0

我似乎無法獲得與Ruby一起使用的商家會話驗證。試圖HTTParty和RESTClient實現和我越來越:Apple在紅寶石的Web商家會話中支付

的OpenSSL :: SSL :: SSLError(所以SSL_connect退換= 1個=錯誤號= SSLv3的讀取完成A 0狀態:SSLV3警報證書過期):

我試過同證書與這個節點服務器的例子,https://github.com/tomdale/apple-pay-merchant-session-server,它工作得很好,所以它必須是我的紅寶石代碼中的東西。

有沒有人設法使此工作?

回答

4

我遇到了同樣的問題。在你參考的例子和https://github.com/norfolkmustard/ApplePayJS的實現的幫助下(另見關於https://forums.developer.apple.com/thread/51580的實現的討論),我能夠得到它的工作。

對我來說是正確的證書(蘋果支付商人身份證書)的傳遞,就像蘋果公司提供,並得到像這樣的證書鍵鍵:

一旦你有了自己的商家ID(會話)來自Apple的證書,通過雙擊將其導入到Mac上的keychain.app中,右鍵單擊鑰匙串中的證書並將組合的私鑰和證書導出爲.p12文件,然後在終端中: -

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

添加應用程序從蘋果樂收費商家標識證書和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() 
) 

希望幫助別人節省一些時間和白髮!