Skip to content

PhotoPay Germany results

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

German payment slip scanning results

Initializing the scanning of German slips

To initialize the scanning of Austrian 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 = @"de";


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

    // Add recognizer for German payslips
    [settings.scanSettings addRecognizerSettings:[[PPDeSlipRecognizerSettings alloc] init]];

    // Add recognizer for German payment QR codes
    [settings.scanSettings addRecognizerSettings:[[PPDeQrRecognizerSettings alloc] init]];


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

    // Set your license key here. This specific key is for demo purposes only!
    settings.licenseSettings.licenseKey = @"RQEKQUVC-JUIUZZFN-M4DQ4ZVS-NJIA3G4W-ADQAKOVM-C7DHMGRR-VV7X4PWZ-FE7WVUKW";

    // 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 German payslips are obtained as instances of two possible classes: PPDeSipRecognizerResult (if payment slip was scanned), or PPDeQrRecognizerResult (if payment QR code was scanned). 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:[PPDeSlipRecognizerResult class]]) {
            PPDeSlipRecognizerResult* deSlipResult = (PPDeSlipRecognizerResult*)result;
            [self processDeSlipRecognizerResult:deSlipResult scanningViewController:scanningViewController];
        }

        if ([result isKindOfClass:[PPDeQrRecognizerResult class]]) {
            PPDeQrRecognizerResult* deQrResult = (PPDeQrRecognizerResult*)result;
            [self processDeQrRecognizerResult:deQrResult scanningViewController:scanningViewController];
        }
    };
}

- (void)processDeSlipRecognizerResult:(PPDeSlipRecognizerResult*)deSlipResult
               scanningViewController:(UIViewController<PPScanningViewController> *)scanningViewController {

    // Here we log all field in PPDeSlipRecognizerResult object

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

    NSLog(@"Amount is %@", [deSlipResult amount]);
    NSLog(@"Currency is %@", [deSlipResult currency]);

    NSLog(@"IBAN is %@", [deSlipResult iban]);
    NSLog(@"bankCode is %@", [deSlipResult bankCode]);
    NSLog(@"accountNumber is %@", [deSlipResult accountNumber]);

    NSLog(@"referenceNumber is %@", [deSlipResult referenceNumber]);

    NSLog(@"paymentDescription is %@", [deSlipResult paymentDescription]);

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

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"German slip"
                                                                             message:[deSlipResult description]
                                                                      preferredStyle:UIAlertControllerStyleAlert];

    // pause scanning until the user presses OK buttom
    [scanningViewController pauseScanning];

    UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK"
                                                       style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * _Nonnull action) {
                                                         // resume scanning when OK is pressed
                                                         [scanningViewController dismissViewControllerAnimated:YES completion:nil];
                                                     }];

    [alertController addAction:okAction];

    // present alert on top of scanning view controller
    [scanningViewController presentViewController:alertController animated:YES completion:nil];
}

- (void)processDeQrRecognizerResult:(PPDeQrRecognizerResult*)deQrResult
             scanningViewController:(UIViewController<PPScanningViewController> *)scanningViewController {

    // Here we log all field in PPDeQrRecognizerResult object

    NSLog(@"German QR code results\n");

    NSLog(@"Amount is %@", [deQrResult amount]);
    NSLog(@"Currency is %@", [deQrResult currency]);

    NSLog(@"IBAN is %@", [deQrResult iban]);
    NSLog(@"bankCode is %@", [deQrResult bankCode]);
    NSLog(@"accountNumber is %@", [deQrResult accountNumber]);

    NSLog(@"referenceNumber is %@", [deQrResult referenceNumber]);

    NSLog(@"paymentDescription is %@", [deQrResult paymentDescription]);

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

    NSLog(@"bic is %@", [deQrResult bic]);
    NSLog(@"formType is %@", [deQrResult formType]);
    NSLog(@"formVersion is %@", [deQrResult formVersion]);
    NSLog(@"formFunction is %@", [deQrResult formFunction]);
    NSLog(@"purposeCode is %@", [deQrResult purposeCode]);
    NSLog(@"displayData is %@", [deQrResult displayData]);

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"German QR code"
                                                                             message:[deQrResult description]
                                                                      preferredStyle:UIAlertControllerStyleAlert];

    // pause scanning until the user presses OK buttom
    [scanningViewController pauseScanning];

    UIAlertAction* okAction = [UIAlertAction actionWithTitle:@"OK"
                                                       style:UIAlertActionStyleDefault
                                                     handler:^(UIAlertAction * _Nonnull action) {
                                                         // resume scanning when OK is pressed
                                                         [scanningViewController dismissViewControllerAnimated:YES completion:nil];
                                                     }];

    [alertController addAction:okAction];

    // present alert on top of scanning view controller
    [scanningViewController presentViewController:alertController animated:YES completion:nil];
}
Clone this wiki locally