2017-10-11 54 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) 
     })...