Skip to content

PhotoPay Hungarian results

Nenad Mikša edited this page Oct 22, 2016 · 8 revisions

Hungarian payment slip scanning results

Initializing the scanning of Hungarian slips

To initialize the scanning of Hungarian slips, use the following intialization code:

- (PPCameraCoordinator*)coordinatorWithError:(NSError **)error {

    // Check if photopay is supported
    if ([PPCameraCoordinator isScanningUnsupportedForCameraType:PPCameraTypeBack error:error]) {
        return nil;
    }

    // 1. ******* Instantiate Scanning settings ********/
    PPSettings* settings = [[PPSettings alloc] init];


    // 2. ************* Setup UI Settings **************/

    // Instantiate PhotoPay UI settings. This allows more customization in the initialization process.
    PPPhotoPayUiSettings* photopayUiSettings = [[PPPhotoPayUiSettings alloc] init];
    settings.uiSettings = photopayUiSettings;

    // Use english language for UI texts
    settings.uiSettings.language = @"en";


    // 3. ************* Setup Scan Settings **************/

    // Add recognizer for Hungarian payslips
    [settings.scanSettings addRecognizerSettings:[[PPHuSlipRecognizerSettings alloc] init]];


    // 4. ************* Setup License Settings **************/

    // Set your license key here. This specific key is for demo purposes only!
    settings.licenseSettings.licenseKey = @"KKPFVILU-LIGQJN43-NHTQBNSC-JNGWJD7Z-QXRPFDGT-747A5PUX-MY2EV4PT-EKEXTFI6";

    // Allocate the recognition coordinator object
    PPCameraCoordinator *coordinator = [[PPCameraCoordinator alloc] initWithSettings:settings];
    
    return coordinator;
}

- (void)showCoordinatorError:(NSError *)error {

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Warning"
                                                                             message:[error localizedDescription]
                                                                      preferredStyle:UIAlertControllerStyleAlert];

    UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK"
                                                       style:UIAlertActionStyleDefault
                                                     handler:nil];

    [alertController addAction:okAction];

    [self presentViewController:alertController animated:YES completion:nil];
}

- (IBAction)didTapScan:(id)sender {

    /** Instantiate the scanning coordinator */
    NSError *error;
    PPCameraCoordinator *coordinator = [self coordinatorWithError:&error];

    /** If scanning isn't supported, show an error */
    if (coordinator == nil) {
        [self showCoordinatorError:error];
        return;
    }

    /** Allocate and present the scanning view controller */
    UIViewController<PPScanningViewController>* scanningViewController = [PPViewControllerFactory cameraViewControllerWithDelegate:self overlayViewController:overlayVC coordinator:coordinator error:nil];

    scanningViewController.autorotate = YES;
    scanningViewController.supportedOrientations = UIInterfaceOrientationMaskLandscape;

    /** You can use other presentation methods as well */
    [self presentViewController:scanningViewController animated:YES completion:nil];
}

Retrieving results

Scanning results for Hungarian payslips are obtained as instances of a class PPHuSlipRecognizerResult. See the header files or sample below for all fields contained in these objects.

- (void)scanningViewController:(UIViewController<PPScanningViewController> *)scanningViewController
              didOutputResults:(NSArray *)results {

    // Here you process scanning results. Scanning results are given in the array of PPRecognizerResult objects.

    // Collect data from the result
    for (PPRecognizerResult* result in results) {

        if ([result isKindOfClass:[PPHuSlipRecognizerResult class]]) {
            PPHuSlipRecognizerResult* huSlipResult = (PPHuSlipRecognizerResult*)result;
            [self processHuSlipRecognizerResult:huSlipResult];
            
            [self dismissViewControllerAnimated:YES completion:nil];
        }
    };
}

- (void)processHuSlipRecognizerResult:(PPHuSlipRecognizerResult*)huSlipResult {

    // Here we log all field in PPHuSlipRecognizerResult object

    NSLog(@"Hungarian payment slip results\n");

    NSLog(@"Amount is %d", (int)[huSlipResult intAmount]);
    NSLog(@"Currency is %@", [huSlipResult currency]);

    NSLog(@"bankCode is %@", [huSlipResult bankCode]);
    NSLog(@"accountNumber is %@", [huSlipResult accountNumber]);

    NSLog(@"payerId is %@", [huSlipResult payerId]);
    NSLog(@"recipientName is %@", [huSlipResult recipientName]);

    NSLog(@"payerBankCode is %@", [huSlipResult payerBankCode]);
    NSLog(@"payerAccountNumber is %@", [huSlipResult payerAccountNumber]);

    NSLog(@"Slip ID %d", (int)[huSlipResult slipId]);
}
Clone this wiki locally