Re: The obtained OPC always returns an invalid argument error when using it in Google Pay on Android

imadahddaddev
Regular Visitor

The obtained OPC always returns an invalid argument error when using it in Google Pay on Android.

I am using Visa In-App Provisioning to obtain an OPC (Opaque Payment Card) for Google Pay. The OPC object I receive is as follows (Sandbox😞

{
"paymentAccountReference": "V1234567890124514231274459132",
"last4": "9132",
"expirationDate": {"month": "12", "year": "2030"},
"encAddress": "eyJraWQiOiJiNTFkZmEyMyIsImVuYy.....",
"opaquePaymentCard": "eyJhdWQiOiIxODk5NzZhNi0yZm......",
"vCardID": "v-123-c1a347c1-bd85-43e3-88c2-a8070f4d1901"
}

I then encode this object to Base64 using the following code:

String encodedResponseBody = Base64.getEncoder().encodeToString(responseBody.getBytes());
System.out.println("Base64 Encoded Response Body:");
System.out.println(encodedResponseBody);

I pass the Base64-encoded OPC to the PushTokenizeRequest for Google Pay, as explained in the Google Pay documentation.

 

However, when running the app on Android and after confirming the address in Google Pay, I encounter an error message: "Something went wrong. Invalid argument."

Could you please help verify if the OPC is correctly formatted and whether there might be an issue with my implementation? Additionally, if there are specific requirements or common issues that could be causing this error, please let me know.

 

 

 

 

 

 

 

 

 

3 REPLIES 3
SyedSa
Community Moderator

Re: The obtained OPC always returns an invalid argument error when using it in Google Pay on Android

Hi @imadahddaddev, Thank you for reaching out. An agent will get back to you as soon as possible. Until then, if any community member has information that may be helpful, please reply to this thread.

imadahddaddev
Regular Visitor

Re: The obtained OPC always returns an invalid argument error when using it in Google Pay on Android

Hi @SyedSa , It’s been a couple of days since I posted my question, and I haven’t received any response .

API_Products
Visa Developer Support Specialist

Re: The obtained OPC always returns an invalid argument error when using it in Google Pay on Android

Hey @imadahddaddev,

 

To diagnose the issue with the Visa In-App Provisioning and Google Pay integration, let's break down the steps and check common pitfalls. Here’s a checklist and some guidance:

 

Verify OPC Format
Ensure that the OPC object you receive from Visa is correctly formatted and contains all the required fields. From your provided example, it seems to be fine. However, ensure all fields meet the expected structure and content.

### Base64 Encoding in Java
Make sure the encoding is correctly implemented. Your current encoding approach seems correct, but let's confirm:

 

```java
import java.util.Base64;

public class OPCEncodeExample {
public static void main(String[] args) {
String responseBody = "{"
+ "\"paymentAccountReference\": \"V1234567890124514231274459132\","
+ "\"last4\": \"9132\","
+ "\"expirationDate\": {\"month\": \"12\", \"year\": \"2030\"},"
+ "\"encAddress\": \"eyJraWQiOiJiNTFkZmEyMyIsImVuYy.....\","
+ "\"opaquePaymentCard\": \"eyJhdWQiOiIxODk5NzZhNi0yZm......\","
+ "\"vCardID\": \"v-123-c1a347c1-bd85-43e3-88c2-a8070f4d1901\""
+ "}";

String encodedResponseBody = Base64.getEncoder().encodeToString(responseBody.getBytes());
System.out.println("Base64 Encoded Response Body:");
System.out.println(encodedResponseBody);
}
}
```

 

PushTokenizeRequest for Google Pay
Ensure the Base64-encoded OPC is correctly passed to the PushTokenizeRequest. Here’s a conceptual example for Android:

 

```java
// Import necessary Google Pay API classes
import com.google.android.gms.wallet.Wallet;
import com.google.android.gms.wallet.WalletConstants;
import com.google.android.gms.wallet.Wallet.WalletOptions;
import com.google.android.gms.wallet.PaymentDataRequest;
import com.google.android.gms.wallet.PaymentMethodTokenizationParameters;

public void pushTokenizeRequest(String encodedOPC) {
WalletOptions walletOptions = new WalletOptions.Builder()
.setEnvironment(WalletConstants.ENVIRONMENT_TEST)
.build();

Wallet.getPaymentsClient(this, walletOptions);

PaymentDataRequest request = PaymentDataRequest.newBuilder()
.setPaymentMethodTokenizationParameters(
PaymentMethodTokenizationParameters.newBuilder()
.setTokenizationType(WalletConstants.PAYMENT_METHOD_TOKENIZATION_TYPE_PAYMENT_GATEWAY)
.addParameter("gateway", "example")
.addParameter("gatewayMerchantId", "exampleGatewayMerchantId")
.addParameter("opaquePaymentCard", encodedOPC)
.build())
.build();

// Start PaymentDataRequest process, e.g., using an Intent
}
```

 

Common Issues and Requirements
1.Google Pay API Configuration:

Ensure your Google Pay API configuration is correct and matches the expected format for tokenization.

2. Address Validation:
Sometimes, address validation issues can cause errors. Ensure the `encAddress` is correctly formatted and valid.

3. Environment Settings:
Ensure you are testing in the correct environment (sandbox vs. production). Mismatched environments can cause unexpected errors.

4. Error Logs:
Check the detailed error logs from both Visa and Google Pay. They often provide more specific information about what went wrong.

 

Additional Debugging
- Print and Verify Encoded OPC:
Print the Base64-encoded OPC and manually verify it for any discrepancies or encoding issues.

- Google Pay Documentation:
Revisit the Google Pay documentation to ensure compliance with all requirements, especially around the `PushTokenizeRequest`.

 

By following these steps and ensuring all configurations and data are correctly formatted, you should be able to identify and resolve the issue.




Thanks,

Diana H.



Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.