Hello,
Currently, I am using Reader SDK with square hardware and now I have to move to a new Mobile Payments SDK. In new SDK for the auth document says I need to have a server for the access token. So is it possible to get an access token without a server/backend? I don’t want to have a server for this and want to handle all the processes by the iOS app.
Please guide.
I’m Square Dev AI, here to help answer your question!
Based on the information you’ve provided, the following documentation will help answer your question:
Additional Documentation
Deploy the Server
In-App Payments SDK Quickstart
In-App Payments SDK Quickstart
If this documentation helped you find a solution, please check the box indicating that this reply solves the problem.
Otherwise one of our Developer Advocates will provide additional assistance shortly.
No, it’s not possible to get an access token without a server. For security reasons, Square’s Mobile Authorization API requires that access tokens must not be stored on mobile devices. They must be stored securely on a server and requests to the Square API must be proxied through that server. This is to ensure the security of your transactions and protect sensitive information.
This answer was reviewed by @Bryan-Square.
Ok understood.
Another question:
- Do we need to initialize the SDK in the
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
method only? Because for the very first time, the app launches app will not have the location ID as I am not storing the ID in the app. The app will get the location ID from the API on another screen after the app launch. But on that screen app will not have launchOptions
for the initialization of the SDK.
How can I initialize it properly?
You don’t need to initialize the Square Mobile Payments SDK in didFinishLaunchingWithOptions
. Here’s the recommended approach:
- Create a Payment Manager Class (Singleton pattern)
- Hold the SDK instance
- Handle initialization
- Manage location ID
- Initialize When Ready
// After getting location ID from your API
[[PaymentManager shared] initializeSDKWithLocationId:locationId];
- Best Practices
- Initialize SDK after getting location ID from your API
- Store location ID locally for future app launches
- Check SDK initialization status before making calls
- Handle errors appropriately
You can initialize the SDK at any time after getting the location ID - it doesn’t have to be during app launch. 
Hi Bryan,
Sorry, it is not Location ID but application ID as this method [SQMPMobilePaymentsSDK initializeWithApplicationLaunchOptions:launchOptions squareApplicationID:@"test"];
only supports application ID.
I could not find any method like initializeSDKWithLocationId
in the example or SDK. Do you have the latest example code?
Hi Bryan,
I am just following the documentation and trying to initialize the SDK as below:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[SQMPMobilePaymentsSDK initializeWithApplicationLaunchOptions:launchOptions squareApplicationID:@"actualProductionAppID"];
return YES;
}
but app crashes at initialize:
*** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Invalid parameter not satisfying: urls’
terminating due to uncaught exception of type NSException
My info.plist
Am I missing anything here to set up?
The app was crashing because I had Reader SDK in my project and I added
SQMPMobilePaymentsSDK
. So now I have removed the Reader SDK and keep only SQMPMobilePaymentsSDK
and its working fine.
Ah, that will definitely do it. Glad to hear that you figured out the issue and it’s working as expected. Thank you for sharing your findings. 