2017-10-11 76 views
1

我正在嘗試整合付款申請api,但我在這裏丟失了一些東西.. 如何驗證使用api進行的付款? 當用戶支付我的回撥時,我怎麼知道付款已完成? 這是我的代碼。驗證Google付款申請API

paymentRequest.show() 
    .then((paymentResponse) => { 
     fetch('http://validate-payment/api') 
     .then((response) => { 
      return response.json(); 
     }) 
     .then((json) => { 
      return paymentResponse.complete('fail'); // Hardcode fail 
     }) 
     .catch((error) => { 
      reject(); 
     }) 
    }) 
    .catch((error) =>{ 
     console.log(error.message) 
    }); 
+0

檢查'response.ok',如果這是真的,然後調用'response.json()';否則調用'.complete('fail')'。 – sideshowbarker

+0

請注意,此API是「付款請求API」,與Google無關。請不要將此稱爲「Google Payment Request API」。 https://medium.com/dev-channel/addressing-common-misconceptions-about-the-payment-request-api-4d0db51dae75 – agektmr

回答

2

當您收到paymentResponse對象,這並不意味着支付完成。您必須像現在這樣將信息發佈到支付網關來處理付款。

通過paymentResponse.details獲取付款明細並將其張貼到支付網關(在您的代碼中,它可能是「validate-payment/api」)。

來自支付網關的響應將指示支付是否成功。

當您使用此API(特別是處理原始信用卡信息時)時,請注意PCI合規性。條紋例如does this on behalf of you但不是很多付款網關做類似的。

paymentRequest.show() 
    .then((paymentResponse) => { 
     var details = paymentResponse.details; 
     fetch('https://validate-payment/api', { 
      method: 'POST', 
      body: JSON.stringify(details) 
     })...