Integrating Google Pay
In this initial step, must set up your project and implement Google Pay in your Android application.
1.Configure your Project
To set up your project, follow the instructions described in the Google Pay Setup Guide.
In this step, you must add dependencies either by importing the library from Google Play Services or choosing the APIs you want to compile. And then, to enable Google Pay in your Android application, you will have to modify the "AndroidManifest.xml" file of your project according to the instructions given on the page.
2. Implement Google Pay
To integrate Google Play into your app, follow all the steps described in the Google Pay Tutorial Guide.
For the correct integration of Google Pay via Cielo, it is necessary to pay attention to the points below:
Gateway Definition
In step "Step 2: Request a payment token for your payment provider", follow the model indicated as "GATEWAY" and assign the value "PAYMENT_GATEWAY" to the type
parameter and the value "cielo" to the gateway
parameter, according to the given example:
private static JSONObject getTokenizationSpecification() {
JSONObject tokenizationSpecification = new JSONObject();
tokenizationSpecification.put("type", "PAYMENT_GATEWAY");
tokenizationSpecification.put(
"parameters",
new JSONObject()
.put("gateway", "cielo")
.put("gatewayMerchantId", "exampleMerchantId"));
return tokenizationSpecification;
}
Fill in the gatewayMerchantId
parameter with your store's identifier, generated by the gateway. The store identifier follows the format "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX" (type GUID / size 36).
Card brands definition
In "Step 3: Define supported payment card networks", configure according to the flags accepted by the wallet.
Environment definition
In "Step 5: Create a PaymentsClient instance", use the value "WalletConstants.ENVIRONMENT_TEST" for the test environment.
It is recommended that, before conducting the tests, the developer joins the specific group of Google Pay users to gain access to new test cards that are used with the Google integration checklist.
Shopping Data definition
In "Step 7: Create a PaymentDataRequest object", use the "BRL" value for the currencyCode
parameter. The merchantName
field is the name that the shopper will see throughout the Google Pay payment process. Thus, the use of a recognizable friendly name is recommended.
Payment data recovery
In "Step 9: Handle the response object", the Activity.RESULT_OK
event is described, in which an object is returned with all the payment data, including payment tokens.
From the PaymentData
, the PaymentMethodToken
object is obtained, by calling the getPaymentMethodToken()
method. Click here for more information.
Next, you must get the string that contains payment tokens from the GetToken()
method of the PaymentMethodToken
object. Click here for more information.
The string obtained in the previous step has a structure like the one shown below. Click here for more information.
{
"protocolVersion": "ECv1",
"signature": "TJVA95OrM7E2cBab30RMHrHDcEfxjoYZgeFONFh7HgQ",
"signedMessage": "{\"encryptedMessage\":
\"ZW5jcnlwdGVkTWVzc2FnZQ==\",\"ephemeralPublicKey\":
\"ZXBoZW1lcmFsUHVibGljS2V5\",\"tag\": \"c2lnbmF0dXJl\"}"
}
Parameter | Type | Description |
---|---|---|
signedMessage | string | Signed message. |
signature | string | Message signature. |
Save the signedMessage
and signature
data, which will be required for authorization via the API E-commerce Cielo in STEP 2, described below.
Updated 2 days ago