Okay, you cannot dynamically change the value of the tag in the AndroidManifest.xml at runtime since the manifest is compiled into the APK. However, you can achieve the desired functionality by using a different approach.
One way to handle this scenario is to set the application ID programmatically at runtime based on the garage location. You can remove the tag from the AndroidManifest.xml and instead set the application ID in your code before initializing the Square In-App Payments SDK.
Here’s an example of how you might do this in your application:
// Determine the garage location (US or Canada)
String garageLocation = getGarageLocation();
// Set the application ID based on the garage location
String squareApplicationId = "";
if ("US".equals(garageLocation)) {
squareApplicationId = "US_APPLICATION_ID";
} else if ("Canada".equals(garageLocation)) {
squareApplicationId = "CANADA_APPLICATION_ID";
}
// Initialize the Square In-App Payments SDK with the appropriate application ID
PaymentsSdk.INSTANCE.initialize(context, squareApplicationId);
In this example, getGarageLocation()
is a method that you would implement to determine the garage location (US or Canada). You would replace “US_APPLICATION_ID” and “CANADA_APPLICATION_ID” with the actual application IDs for your US and Canada locations, respectively.
By setting the application ID programmatically, you can ensure that the correct ID is used based on the garage location, and you won’t need to modify the AndroidManifest.xml file for each location.
hi @Bryan-Square
Could you please let us know the dependency used for the following code?
PaymentsSdk.INSTANCE.initialize(context, squareApplicationId);
-
It would be great if you could provide documentation on integrating the In-App Payments SDK without using a meta tag from the AndroidManifest.xml in Android app Project?
-
Where should the SDK be installed? At application level ?
The dependency used for the code PaymentsSdk.INSTANCE.initialize(context, squareApplicationId);
is the Square In-App Payments SDK for Android. To integrate the SDK into your Android app project without using a meta tag in the AndroidManifest.xml, you can follow the steps below:
- Add the Square In-App Payments SDK dependency to your app’s
build.gradle
file:
dependencies {
implementation 'com.squareup.sdk.in-app-payments:card-entry:1.5.0'
implementation 'com.squareup.sdk.in-app-payments:google-pay:1.5.0'
}
- Initialize the SDK in your
Application
class or Activity
class:
import com.squareup.sdk.inappayments.PaymentsSdk;
public class MyApplication extends Application {
@Override
public void onCreate() {
super.onCreate();
String squareApplicationId = "REPLACE_WITH_YOUR_APPLICATION_ID";
PaymentsSdk.INSTANCE.initialize(this, squareApplicationId);
}
}
- If you are not using a meta tag in the AndroidManifest.xml to specify the Square application ID, make sure to initialize the SDK before performing any payment-related operations.
The SDK should be installed at the application level, typically in the Application
class, to ensure it is initialized before any payment operations are performed.
For more detailed documentation on integrating the In-App Payments SDK, you can refer to the official Square Developer documentation: https://developer.squareup.com/docs/in-app-payments-sdk/setup
Keep in mind that the version number in the build.gradle
dependency may change, so always check the latest version in the Square Developer documentation or on the Square GitHub repository: GitHub - square/in-app-payments-android-quickstart: In-App Payments Quick Start Sample Android App.
Hi @Bryan-Square
We have added the given dependencies, but we are unable to import the PaymentsSDK. It seems there is no class named PaymentsSDK with the import you provided. We have tried both the latest version (1.6.5) and the version provided (1.5.0), but we are still unable to import the PaymentsSDK.
import com.squareup.sdk.inappayments.PaymentsSdk;
Could you please let us know what we are missing here?
Please reply ASAP.
Hi @Bryan-Square
We have added the given dependencies, but we are unable to import the PaymentsSDK. It seems there is no class named PaymentsSDK with the import you provided. We have tried both the latest version (1.6.5) and the version provided (1.5.0), but we are still unable to import the PaymentsSDK.
import com.squareup.sdk.inappayments.PaymentsSdk;
Could you please let us know what we are missing here?
Please reply ASAP.
The paymentsSDK
is the In-App Payments SDK. Are you not able to initialize it?
Hi @Bryan-Square
Yes, We were not able to initialize with the given dependencies. It seems there is no PaymentSdk class.
dependencies {
implementation 'com.squareup.sdk.in-app-payments:card-entry:1.5.0'
implementation 'com.squareup.sdk.in-app-payments:google-pay:1.5.0'
}
Adding screenshots for reference
Sorry yes, it doesn’t have paymentsSDK
. If you try SQIPInAppPaymentsSDK
does it work?
Hi @Bryan-Square,
We have tried using SQIPInAppPaymentsSDK
, its not working.
Can you please provide the proper documentation for Android Google Pay integration with multiple Square accounts?
Here is the documentation on installing the In-App Payments SDK for Android. You’ll need to make sure the application ID that you want to install it with is configured with the right account.
Hi @Bryan-Square
We have added the given dependencies, but we are unable to import the PaymentsSDK. It seems there is no class named PaymentsSDK with the import you provided. We have tried both the latest version (1.6.5) and the version provided (1.5.0), but we are still unable to import the PaymentsSDK.
import com.squareup.sdk.inappayments.PaymentsSdk;
We have separate application IDs for our US and Canada locations (2 Application IDs) and need to access the respective ID based on the garage location.
<meta-data
android:name="sqip.SQUARE_APPLICATION_ID"
android:value="@string/GOOGLE_PAY_APPLICATION_ID"/>
- How can we dynamically set the application ID in the
<meta-data>
tag of AndroidManifest.xml based on the specific location, considering that the manifest can only hold one ID at a time and cannot have duplicate names?
Please reply ASAP.
I was mistaken and there is no PaymentsSDK. Are you able to get the In-App Payments SDK going as per our documentation for one Square account application?
Hi @Bryan-Square
Yes, we were able to get the Square SDK running for a single square account. However, we have two accounts—one for the US and another for Canada. We intend to offer Google Pay as an option in both regions. It’s imperative that this SDK supports multiple Square app IDs without relying on the tag in the Android manifest.xml file. This functionality is crucial for our Android app.
Please reply ASAP.
Currently the SDK relies on the application ID that is configured in the AndroidManifest.xml
.
Hi @Bryan-Square
Yes we understand currently the SDK relies on Application ID that is configured in AndroidManifest.xml
using <meta-data>
tag.
Unfortunately we cannot have two different <meta-data>
tags for different Application IDs. And two APK’s isn’t a solution.
Our App supports for both US and Canada region, hence we have two Square Accounts. Now for implementing the transaction smoothly between the two regions we need to configure the Application ID dynamically based on the region.
This is our at most priority and crucial as we have to roll out Google Pay supporting Canada region. Could you please let us know how we can assign Application ID dynamically. ASAP.
According to the team you can set the application id programmatically instead of XML.
/**
* Lets the application read and write the Square application ID via the [squareApplicationId]
* property. You can also specify the application ID at build time in the AndroidManifest.xml:
*
* ```
* <application>
* <meta-data
* android:name="sqip.SQUARE_APPLICATION_ID"
* android:value="your application id"/>
* </application>
* ```
*
* @property squareApplicationId The Square application ID used to obtain a card nonce.
*/
object InAppPaymentsSdk {
@JvmStatic
var squareApplicationId: String by SquareApplicationId
}
You can initialize the In-App Payments SDK by doing InAppPaymentsSdk.squareApplicationId = USD_APP_ID
Hi @Bryan-Square
-
We have implemented the above solution in the sandbox environment for both Canada and US region using below code.
if ("US" == value) {
squareApplicationId = US_APPLICATION_ID
} else if ("CA" == value) {
squareApplicationId = CA_APPLICATION_ID
}
// Initialize the Square In-App Payments SDK with the appropriate application ID
InAppPaymentsSdk.squareApplicationId = squareApplicationId
Here is the error, which we receive.
-
We confirmed that the same Canada sandbox credential when initialised from the AndroidManifest.xml
file, it works as expected.
<meta-data
android:name="sqip.SQUARE_APPLICATION_ID"
android:value="CA_APPLICATION_ID"/>
Can you please let us know are there any other steps to be implemented after this code InAppPaymentsSdk.squareApplicationId = squareApplicationId
to make it work.
Or are there any other ways of achieving multiple Square application Id at runtime in single APK.
Were you able to generate a token that was passed to the server or is this failing on the client?
Hi @Bryan-Square
This is failing on the client side. We receive the below error as soon as we click on the GPay button.
What is the location_id
that your trying to process a payment for?