Tez付款请求API

时间:2018-07-03 13:41:39

标签: payment-request-api google-tez

我正在尝试将Google-Tez付款集成到我的网站中,但是当我调用request.show()时,错误消息为

  

“收款人不是有效的商家”

,当我致电checkCanMakePayment()时,错误消息为

  

“无法查询付款请求”

,我在下面附上我的代码。我的UPI ID是“ hsbc ”。谁能帮助我解决此问题?我需要知道是否有任何程序需要商人在Google Tez中注册

    

    function onBuyClicked() {

        const creditCardPaymentMethod = {
            supportedMethods: 'basic-card',
            data: {
                supportedNetworks: ['visa', 'mastercard'],
                supportedTypes: ['credit', 'debit']
            }
        };
        const supportedInstruments = [   
            {     
                supportedMethods: ['https://tez.google.com/pay'],
                //supportedMethods:[creditCardPaymentMethod],
                data: {

                    pa:'**********',
                    pn:'**********',
                    tr:'123456ABCDEFSD',
                    url:'***********',
                    mc:'*********',
                    tn:'Purchase in Merchant'
                }   
            } 
        ];

        var details = 
            {   
            total: 
                {     
                label:'Total',     
                amount: {       
                    currency:'INR',       
                    value:'10.01' //sample amount 
                }
            },
            displayItems: [
                {
                    label:'Original Amount',     
                    amount: {       
                        currency:'INR',       
                        value:'10.01'
                    }
                }
            ]
        };
        var request =null;
        try {
            request = new PaymentRequest(supportedInstruments, details);
            console.log(request);
            /*request.show()
            .then(function(result){
                alert("hai");
            })
             .catch(function(err){
                alert('Payment Request Error: '+ err.message+' 74'); 
            });*/
        }catch (e) {
            alert('Payment Request Error: '+ e.message+'77'); 
            console.log('Payment Request Error: '+ e.message);
            //return;
        } 
        if (!request) {  
            alert('Web payments are not supported in this browser 77'); 
            console.log('Web payments are not supported in this browser.'); 
            // return;
        } 

        var canMakePaymentPromise = checkCanMakePayment(request);
        canMakePaymentPromise
        .then(function(result){
            showPaymentUI(request,result)
        })
        .catch(function(err){
            console.log('Error in calling checkCanMakePayment: ' + err); 
        });
    }

    const canMakePaymentCache = 'canMakePaymentCache';

    function checkCanMakePayment(request){
        // Checks canMakePayment cache, and use the cache result if it exists. 
        if(sessionStorage.hasOwnProperty(canMakePaymentCache)){
            return Promise.resolve(JSON.parse(sessionStorage[canMakePaymentCache]));
        }

        // If canMakePayment() isn't available, default to assuming that the method is supported
        var canMakePaymentPromise = request.canMakePayment();

        if(request.canMakePayment){
            canMakePaymentPromise = request.canMakePayment();
        }

        return canMakePaymentPromise
        .then(function(result){
            sessionStorage[canMakePaymentCache] = result;
            return result;
        })
        .catch(function (err){
            alert('Error calling canMakePayment: '+ err);
            console.log('Error calling canMakePayment: '+ err);
        });
    }

    function showPaymentUI(request, canMakePayment){
        if(!canMakePayment){
            handleNotReadyToPay();
            return;
        }
        // Set payment timeout.
        var paymentTimeout = window.setTimeout(function(){
            window.clearTimeout(paymentTimeout);
            request.abort()
            .then(function(){
                alert('Payment timed out after 20 mins 129');
                console.log('Payment timed out after 20 mins');
            }).catch(function(){
                alert('Unable to abort,user is in process of paying 132');
                console.log('Unable to abort,user is in process of paying');
            }); 
       }, 20 * 60 * 1000);
       request.show()
       .then(function(paymentResponse){
            window.clearTimeout(paymentTimeout);
            alert("Request Success");
            console.log(paymentResponse);
            processResponse(paymentResponse); // Handle response from browser
       })
       .catch(function (err){
           alert(err +'142');
           console.log(err);
       });
    }

    function handleNotReadyToPay(){
        alert("Tez is not ready to handle 149");
    }

    function processResponse(paymentResponse){
        var paymentResponseString = paymentResponseToJsonString(paymentResponse);
        console.log(paymentResponseString);
       /* fetch('/buy',{
            method: 'POST',
            headers: new Headers({'Content-Type':'application/json'}),
            body:paymentResponseString
        })
        .then(function(buyResult){
            console.log('Buy Result'+buyResult);   
        })
        .catch(function(err){
          console.log('Unable to process payment. '+err);   
        });*/
    }

    onBuyClicked();

1 个答案:

答案 0 :(得分:0)

在“ pa”字段中使用客户VPA代替商家VPA时,出现“收款人不是有效的商家”错误。

解决方案: 使用为商家发行的VPA。