Mobile Payments SDK - deauthorize and initlization

Hello,

I am deauthorizing the SDK like the below:

[SQMPMobilePaymentsSDK.shared.authorizationManager deauthorizeWithCompletion:^
        {
            NSLog(@"Square SDK deauthorized successfully.");
            if (completion)
                completion();
        }];

when the user changes the payment method.

So now if the user wants to choose square again, the app tries to re-initialize the SDK and it crashes:

SquareMobilePaymentsSDK/MobilePaymentsSDK.swift:34: Fatal error: MobilePaymentsSDK: The SDK has already been initialized

So even after deauthorizing the SDK, the SDK remains initialized?
How can I check if SDK is already initialized or not like the app can check for authorization?

SQMPMobilePaymentsSDK.shared.authorizationManager.state != SQMPAuthorizationStateNotAuthorized

:waving_hand: 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

Build with the Mobile Authorization API
Mobile Authorization API
Enable Apple Pay

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.

After deauthorizing did you checked AuthorizationManager.state? If so what was the result? :slight_smile:

Yes its 0 -

SQMPAuthorizationStateNotAuthorized

if (SQMPMobilePaymentsSDK.shared.authorizationManager.state != SQMPAuthorizationStateNotAuthorized)
    {
        [SQMPMobilePaymentsSDK.shared.authorizationManager deauthorizeWithCompletion:^
        {
            NSLog(@"Square SDK deauthorized successfully. %lu", (unsigned long)SQMPMobilePaymentsSDK.shared.authorizationManager.state );
            if (completion)
                completion();
        }];
    }

Hi Bryan,

So is there any way to detect if SDK is already initialized so I can avoid re-initilization? Because it seems even after deauthorize the SDK is still initialized.

OR do I need to rely on authorize and deauthorize? I think even for authorize I first need to initialize the SDK and if its already initialized then app will crash.

Is there a real reason you need to call deauthorize? If you just check the status and if not authorized the authorize? :slight_smile:

Hi Bryan,

Yes, my app provides multiple payment gateway setups, so if a user chooses a different one, I need to de-auth Square. The app also provides a purchase ON/OFF option to restrict payments so at that time too I need to de-auth Square and authorize again if needed.