third_party/gpay/src/upi_handler.js
/**
   * Convert Tez payment data to GPay payment data if payment succeeded, or
   * reject if payment failed
   *
   * @private
   * @param {!PaymentData} tezPaymentData The payment data object from Tez.
   * @param {!PaymentDataRequest} paymentDataRequest The payment data request.
   * @param {!Object} upiPaymentMethod UPI paymentmethod in
   * allowedPaymentMethods array
   * @returns {!Promise<PaymentData>} A promise containing payment data or
   *     error message.
   */
Convert Tez payment data to GPay payment data if payment succeeded, or
reject if payment failed

@private
@param {!PaymentData} tezPaymentData The payment data object from Tez.
@param {!PaymentDataRequest} paymentDataRequest The payment data request.
@param {!Object} upiPaymentMethod UPI paymentmethod in
allowedPaymentMethods array
@returns {!Promise} A promise containing payment data or
error message.
Convert Tez payment data to GPay payment data if payment succeeded or reject if payment failed @private @param { !PaymentData } tezPaymentData The payment data object from Tez . @param { !PaymentDataRequest } paymentDataRequest The payment data request . @param { !Object } upiPaymentMethod UPI paymentmethod in allowedPaymentMethods array @returns { !Promise } A promise containing payment data or error message .
processData_(tezPaymentData, paymentDataRequest, upiPaymentMethod) {
    const tezResponse = JSON.parse(tezPaymentData['tezResponse']);
    if (tezResponse['Status'] === 'FAILURE') {
      let error;
      switch (tezResponse['responseCode']) {
        case 'ZM':
          error = {
            'errorCode': PublicErrorCode.BUYER_ACCOUNT_ERROR,
            'errorMessage': 'Payment failure due to invalid MPIN.'
          };
          break;
        case 'Z9':
          error = {
            'errorCode': PublicErrorCode.BUYER_ACCOUNT_ERROR,
            'errorMessage': 'Payment failure due to insufficient funds.'
          };
          break;
        case '91':
          error = {
            'errorCode': PublicErrorCode.INTERNAL_ERROR,
            'errorMessage':
                'Payment failure due to transaction timeout or connection' +
                ' issue.'
          };
          break;
        default:
          error = {'errorMessage': 'Payment cancelled.'};
      }
      return Promise.reject(error);
    }
    const signedMessage = {
      'paymentMethodType': 'UPI',
      'payeeVpa': upiPaymentMethod['parameters']['payeeVpa'],
      'status': tezResponse['Status'],
      'transactionReferenceId':
          upiPaymentMethod['parameters']['transactionReferenceId'],
      'transactionId': upiPaymentMethod['parameters']['transactionId'] ?
          upiPaymentMethod['parameters']['transactionId'] :
          tezResponse['txnId'],
      'transactionInfo': paymentDataRequest['transactionInfo'],
    };
    let paymentData = {
      'apiVersion': paymentDataRequest['apiVersion'],
      'apiVersionMinor': paymentDataRequest['apiVersionMinor'],
      'paymentMethodData': {
        'type': upiPaymentMethod['type'],
        'tokenizationData': {
          'type': 'DIRECT',
          'token': {
            'protocolVersion': 'ECv1',
            'signature': '',
            'signedMessage': signedMessage
          }
        }
      }
    };
    return Promise.resolve(paymentData);
  }
processData_ ( tezPaymentData , paymentDataRequest , upiPaymentMethod ) { const tezResponse = JSON . parse ( tezPaymentData [ 'tezResponse' ] ) ; if ( tezResponse [ 'Status' ] === 'FAILURE' ) { let error ; switch ( tezResponse [ 'responseCode' ] ) { case 'ZM' : error = { 'errorCode' : PublicErrorCode . BUYER_ACCOUNT_ERROR , 'errorMessage' : 'Payment failure due to invalid MPIN.' } ; break ; case 'Z9' : error = { 'errorCode' : PublicErrorCode . BUYER_ACCOUNT_ERROR , 'errorMessage' : 'Payment failure due to insufficient funds.' } ; break ; case '91' : error = { 'errorCode' : PublicErrorCode . INTERNAL_ERROR , 'errorMessage' : 'Payment failure due to transaction timeout or connection' + ' issue.' } ; break ; default : error = { 'errorMessage' : 'Payment cancelled.' } ; } return Promise . reject ( error ) ; } const signedMessage = { 'paymentMethodType' : 'UPI' , 'payeeVpa' : upiPaymentMethod [ 'parameters' ] [ 'payeeVpa' ] , 'status' : tezResponse [ 'Status' ] , 'transactionReferenceId' : upiPaymentMethod [ 'parameters' ] [ 'transactionReferenceId' ] , 'transactionId' : upiPaymentMethod [ 'parameters' ] [ 'transactionId' ] ? upiPaymentMethod [ 'parameters' ] [ 'transactionId' ] : tezResponse [ 'txnId' ] , 'transactionInfo' : paymentDataRequest [ 'transactionInfo' ] , } ; let paymentData = { 'apiVersion' : paymentDataRequest [ 'apiVersion' ] , 'apiVersionMinor' : paymentDataRequest [ 'apiVersionMinor' ] , 'paymentMethodData' : { 'type' : upiPaymentMethod [ 'type' ] , 'tokenizationData' : { 'type' : 'DIRECT' , 'token' : { 'protocolVersion' : 'ECv1' , 'signature' : '' , 'signedMessage' : signedMessage } } } } ; return Promise . resolve ( paymentData ) ; }
Convert Tez payment data to GPay payment data if payment succeeded, or
 reject if payment failed
Convert Tez payment data to GPay payment data if payment succeeded or reject if payment failed
// payment failure due to invalid MPIN // payment failure due to insufficient funds // payment failure due to transaction timeout or connection issue // payment failure due to user cancel or other issues // TODO: Verify that response comes from tez and // add signature and encrypt signed message here