1

我正在尝试将 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();
4

1 回答 1

0

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

解决方法:使用为商户签发的 VPA。

于 2020-07-18T17:44:04.880 回答