API платежного запроса Tez - PullRequest
0 голосов
/ 03 июля 2018

Я пытаюсь интегрировать оплату Google-Tez на свой сайт, но когда я вызываю request.show (), появляется сообщение об ошибке как

"Получатель платежа не является действительным продавцом"

, когда я вызываю checkCanMakePayment (), получаю сообщение об ошибке как

«Невозможно запросить платежный запрос»

и я прилагаю свой код ниже. Мой идентификатор UPI: " 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();
...