Using Stripe Terminal iOS SDK with Nativescript

Viewed 105

I'm attempting to use the Stripe Terminal SDK in the Nativescript plugin seed and test it in the demo-angular app. I'm able to initialize the SDK by setting the connection token provider. When the SDK calls the provider's fetchConnectionToken method, the app crashes with no terminal output when the method calls the SDK-supplied completion handler. Debugging in XCode shows _EXC_BAD_ACCESS code=2.

Relevant code:

iOSFetchConnectionToken(completion: (p1: string, p2: NSError) => void) {
    /* No crash if the following two lines are uncommented */
    // completion(hardCodedTokenSecret, nullError);
    // return;
    Http.request({
        url: DemoSharedStripeterminalBasic.serverAddress,
        method: 'POST',
        headers: { 
            "Content-Type": "application/json",
            "Stripe-Public-Key": this.stripeTestKey
        },
        content: JSON.stringify({
            connectedAccountId: this.connectedAccountId
        })
    }).then(response => {
        const result = response.content?.toJSON();
        secret = result.secret;
        completion(secret, null);  // App crashes with no output
    })
}

The above function is assigned to the ConnectionTokenProvider's fetchConnectionToken method. I'm able to call the completion handler successfully before the HTTP request (using hardcoded or null values – see the commented lines at the top), but the crash occurs when I invoke the completion handler in the "then" block of the request, using either the returned value from my API server or a hardcoded/null value. Logging out the completion function gives "function () { [native code] }" which indicates that it's properly accessible in memory. I can't figure out where the bad access is coming from or why it's only happening inside the "then" block.

In the sample above, I'm using Nativescript's built in HTTP module, but I've also tried with JS fetch and have the same issue. I've also tried rewriting using async/await with no luck. My API server correctly returns a valid token (I successfully used the same one for the hard-coded token secret), so I know that isn't the issue either. Any help is hugely appreciated, thanks!

0 Answers
Related