Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass paymentIntent to my app use SiriKit on payment?

Can SiriKit pass the INSendPaymentIntent to my app? The intent has to be handled by my app, instead of in the Siri extension. But the INSendPaymentIntentResponse does not have the .continueInApp like INStartAudioCallIntentResponseCode. There is .failureRequiringAppLaunch, but that behavior is not the preferred one. Have any idea? How to pass object to my app ?

like image 501
Kadir GÜZEL Avatar asked Oct 27 '25 03:10

Kadir GÜZEL


1 Answers

In IntentHandler Extension, there is a handle method which works when user clicks "Send" button in Siri UI Extension. (Swift 3, iOS 10 and 11)

class IntentHandler: INExtension, INSendPaymentIntentHandling {

    func handle(intent: INSendPaymentIntent, completion: @escaping (INSendPaymentIntentResponse) -> Void) {
        if let _ = intent.payee, let currencyAmount = intent.currencyAmount {
            // Handle the payment here!

            // Create a user activity to pass it to our application
            let userActivity = NSUserActivity(activityType:"myActivityName")

            // Pass parameter dictionary to the userinfo  
            userActivity.userInfo = ["amount": Int(truncating: currencyAmount.amount!)] 

            // By providing a userActivity to the intent response, Siri will open up the app and continue the payment there
            completion(INSendPaymentIntentResponse.init(code: .inProgress, userActivity: userActivity))
        }
    }
}

After that continueUserActivity is called in our application

-(BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restorationHandler:(void (^)(NSArray * _Nullable))restorationHandler
{
    // Parse userActivity.userInfo parameter to get the amount etc.

    return YES;
}
like image 64
ondermerol Avatar answered Oct 29 '25 19:10

ondermerol



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!