I have to integrate Siri in our application for requesting payments without specifying the payer. It's possible to do? how can I do it?
RequestPaymentIntentHandler:
#import "RequestPaymentIntentHandler.h"
@implementation RequestPaymentIntentHandler
#pragma mark - Resolve
-(void)resolvePayerForRequestPayment:(INRequestPaymentIntent *)intent withCompletion:(void (^)(INPersonResolutionResult * _Nonnull))completion {
completion([INPersonResolutionResult notRequired]);
}
-(void)resolveNoteForRequestPayment:(INRequestPaymentIntent *)intent withCompletion:(void (^)(INStringResolutionResult * _Nonnull))completion {
completion([INStringResolutionResult notRequired]);
}
-(void)resolveCurrencyAmountForRequestPayment:(INRequestPaymentIntent *)intent withCompletion:(void (^)(INCurrencyAmountResolutionResult * _Nonnull))completion {
if (! intent.currencyAmount || intent.currencyAmount.amount.doubleValue <= 0)
completion([INCurrencyAmountResolutionResult needsValue]);
else
completion([INCurrencyAmountResolutionResult successWithResolvedCurrencyAmount:intent.currencyAmount]);
}
#pragma mark - Confirm
-(void)confirmRequestPayment:(INRequestPaymentIntent *)intent completion:(void (^)(INRequestPaymentIntentResponse * _Nonnull))completion {
if (! intent || ! intent.currencyAmount)
completion([[INRequestPaymentIntentResponse alloc] initWithCode:INRequestPaymentIntentResponseCodeFailure userActivity:nil]);
else
completion([[INRequestPaymentIntentResponse alloc] initWithCode:INRequestPaymentIntentResponseCodeSuccess userActivity:nil]);
}
#pragma mark - Handle
-(void)handleRequestPayment:(INRequestPaymentIntent *)intent completion:(void (^)(INRequestPaymentIntentResponse * _Nonnull))completion {
INRequestPaymentIntentResponse *response;
if (! intent || ! intent.currencyAmount) {
NSLog(@"NO INTENT ");
response = [[INRequestPaymentIntentResponse alloc] initWithCode:INRequestPaymentIntentResponseCodeFailure userActivity:nil];
response.paymentRecord = [[INPaymentRecord alloc] initWithPayee:nil payer:nil currencyAmount:intent.currencyAmount paymentMethod:INPaymentMethodTypeUnknown note:nil status:INPaymentStatusFailed feeAmount:nil];
} else {
NSLog(@"INTENT VALIDO ");
response = [[INRequestPaymentIntentResponse alloc] initWithCode:INRequestPaymentIntentResponseCodeSuccess userActivity:nil];
response.paymentRecord = [[INPaymentRecord alloc] initWithPayee:nil payer:nil currencyAmount:intent.currencyAmount paymentMethod:INPaymentMethodTypeUnknown note:nil status:INPaymentStatusCompleted feeAmount:nil];
}
completion(response);
}
@end
.notRequired in resolvePayerForRequestPayment doesn't work! It seems that intent.payer must exist. In fact, if I utter: "Charge Alex $30" it works but if I utter: "Charge $30" doesn't work, because Handle method no called. Siri always tells me to continue in the app. No errors, no warnings, nothing!
intent.payer is readOnly therefore it can not be forced.
IntentsExtension:
#import "IntentsExtension.h"
#import "RequestPaymentIntentHandler.h"
@implementation IntentsExtension
-(id)handlerForIntent:(INIntent *)intent {
if ([intent isKindOfClass:[INRequestPaymentIntent class]])
return [RequestPaymentIntentHandler new];
return nil;
}
@end
Thi is Extension plist file: Info.plist
target App AppDelegate:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
if ([INPreferences siriAuthorizationStatus] != INSiriAuthorizationStatusAuthorized)
[INPreferences requestSiriAuthorization:^(INSiriAuthorizationStatus status) {
}];
NSLog(@"--->SIRI LANGUAGE: %@<----", [INPreferences siriLanguageCode]);
return YES;
}
Siri capabilities enabled.
To recap my goal is to not specify the payer. Any ideas?
Thanks.