Skip to content

SEPA QR

Nenad Mikša edited this page Oct 28, 2016 · 1 revision

SEPA QR code scanning results

Initializing the scanning of SEPA QR codes

To initialize the scanning of SEPA QR codes, 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 SEPA payment QR codes
    [settings.scanSettings addRecognizerSettings:[[PPSepaQrRecognizerSettings alloc] init]];


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

    // Set your license key here. This specific key is for demo purposes only!
    settings.licenseSettings.licenseKey = @"7KHIDF5P-PRRVZ5EQ-SMDYQF4Q-NRUDZ7O7-NRUDZ7O7-NRUDZ7O7-NRUDZ7J7-76DCOZKC";

    // 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;

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

Retrieving results

Scanning results for SEPA QR codes are obtained as instances of class PPSepaQrRecognizerResult. 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:[PPSepaQrRecognizerResult class]]) {
            PPSepaQrRecognizerResult* sepaQrResult = (PPSepaQrRecognizerResult*)result;
            [self processSepaQrRecognizerResult:sepaQrResult scanningViewController:scanningViewController];
        }
    };
}

- (void)processSepaQrRecognizerResult:(PPSepaQrRecognizerResult*)sepaQrResult
              scanningViewController:(UIViewController<PPScanningViewController> *)scanningViewController {

    // Here we log all field in PPSepaSlipRecognizerResult object

    NSLog(@"SEPA payment QR code results\n");

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

    NSLog(@"IBAN is %@", [sepaQrResult iban]);
    NSLog(@"bic is %@", [sepaQrResult bic]);

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

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

    NSLog(@"displayData is %@", [sepaQrResult displayData]);
    NSLog(@"purposeCode is %@", [sepaQrResult purposeCode]);

    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"SEPA QR code"
                                                                             message:[sepaQrResult 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