Retrieving data from Google Pay™

The buyer data is returned to the mobile application in a PaymentData object (also called “payload”).

In order to process the payload data, override the onActivityResult() method of your activity as follows:

Excerpt from the code sample:

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
    super.onActivityResult(requestCode, resultCode, data)
    // Manage Google Pay result 
   if (requestCode == GooglePayManagement.GOOGLE_PAYMENT_CODE_RESULT) {
        when (resultCode) {
            Activity.RESULT_OK -> {
                if (data != null) {
                    val paymentData = PaymentData.getFromIntent(data)
                    val googlePayData = paymentData!!.toJson()
                    // Execute payment   
                 PayZenPayment.executeTransaction(googlePayData, this)
                } else {
                    PayZenPayment.returnsResult(false, PayZenPaymentErrorCode.UNKNOWN_ERROR, "Unknown error", this)
                }
            }
            Activity.RESULT_CANCELED -> {
                PayZenPayment.returnsResult(false, PayZenPaymentErrorCode.PAYMENT_CANCELLED_ERROR, "Payment cancelled by user", this)
            }
            AutoResolveHelper.RESULT_ERROR -> {
                PayZenPayment.returnsResult(false, PayZenPaymentErrorCode.UNKNOWN_ERROR, "Unknown error", this)
            }
        }
    }
}

If you have opted for express checkout, you must transform the payload into a JSON object and analyze it in order to save the necessary data (buyer contact details, shipping address, etc.)

Example of retrieving the shipping address:

when (resultCode) {
	Activity.RESULT_OK -> {
		if (data != null) {
			val paymentData = PaymentData.getFromIntent(data)
			val googlePayData = paymentData!!.toJson()
			val billingAddress =
							JSONObject(
								JSONObject(
									JSONObject(
										googlePayload!!.toJson()
									).getString("paymentMethodData")
								).getString("info")
							).getString("billingAddress")			

Example of a PaymentData object:

JSON result Example :{
	"apiVersionMinor":0,   
	"apiVersion":2,
	"paymentMethodData":{
		"description":"Visa •••• 3513",     
		"tokenizationData":{          
			"type":"PAYMENT_GATEWAY",        
			"token":"{\"signature\":\"MEUCIC1+XSqhtgCWQa\/3k7OFIesJX0SYBtCeOKjD+O2JBWO9AiEAg03FhXVVwD0NRhiPnjGWdfTqTXm39fnzr+XvHdbecY4\\u003d\",\"protocolVersion\":\"ECv1\",\"signedMessage\":\"{\\\"encryptedMessage\\\":\\\"qjXoUw7ptqWE\/G+PSOb8QoR+hqzM7h1S7iQ3jH\/mxmjJi\/\/MY5Kem6WmuQxMQbz0pXeX5mxjmUxvbIQzGhtLLELoTWxuAF\/mLSuoIznPbvJNxQ9xGOVMQYuo0jTKqUUv6QrjMBTSCcQx2ktkDS3EjHOWBPTw22mI\/kXz0wn5x6jlMLEUTFkNlPZYjeoFRvUXpw0XoECNdouiiJwub52zmyebY7pz1JlG5DQOMWRvrCnj5Kgs9sxzXp1VJJ+rIqewoBOgl\/BgKsf87fOxVJFYqOmq+LR\/wk8PDKE9VE1XakQBG8kxhSflMQaqC+ObObJfoUC9ruIDK7iFkT8EFV3FVWHu8ZVYmoek3HWabZ36NdRPUyGtDCjOR+CmT8tneRHyqRzy8S4Yk5LyCObTZ+rbI0toveNchZdakUhMLyFFLqkgnc\/g3WJnLpujRy3jgOe6\/+ymb1gaiOnQQA\\\\u003d\\\\u003d\\\",\\\"ephemeralPublicKey\\\":\\\"BKB3qFuCrmNI0bOxVg\/kVCcCtswHrwabcrm18JtPTB+w5L\/d39dnrgaGajdYvdLrFRQc5RyQ52Ug3e151yDNE6E\\\\u003d\\\",\\\"tag\\\":\\\"rJ5SapWOGc\/f4eqzif+P9D\/wSg\/yvfOJ63yVbRc1lGY\\\\u003d\\\"}\"}"
		},     
		"type":"CARD",
		"info":{          
			"cardNetwork":"VISA",        
			"cardDetails":"3513",        
			"billingAddress":{             
				"address3":"",           
				"sortingCode":"",
				"address2":"",
				"countryCode":"FR",
				"address1":"109 Rue de l'Innovation",
				"postalCode":"31670",
				"name":"My Network",
				"locality":"Labège",
				"administrativeArea":""         
			}
		}
	},
	"shippingAddress":{       
		"address3":"",     
		"sortingCode":"",     
		"address2":"",     
		"countryCode":"FR",
		"address1":"109 Rue de l'Innovation",     
		"postalCode":"31670",
		"name":"My Network",     
		"locality":"Labège",     
		"administrativeArea":""
	},  
	"email":"network.gpay@gmail.com"
}