Objective-C Setup

For Swift setup see Swift Setup.

  1. Create / Setup a VouchrConfig with your values. You can alternatively use a plist file to provide values. See VouchrConfig for details.

    VouchrConfig *vouchrConfig = [VouchrConfig config];
    vouchrConfig.serverUrl = @"https://www.vouchrsdk.com"; // This will be given to you by Vouchr
    vouchrConfig.sdkString = @"SDK_STRING"; // This will be given to you by Vouchr
    
  2. Instantiate a VouchrEngine with your preferred dependencies and the VouchrConfig you created.

    VouchrEngine *vouchrEngineSDK = [VouchrEngine vouchrEngineWithConfig:vouchrConfig builder:^(VouchrEngineBuilder *builder) {
        // override any default managers here
        // eg. builder.networkManager = [YourNetworkManager new];
    }];
    
  3. Instantiate a VoucherCreationManager:

    VoucherCreationManager *creationManager = [VoucherCreationManager voucherCreationManagerWithBuilder:^(VoucherCreationManagerBuilder *builder) {
        // override any default settings 
        // eg. builder.fullScreenLoadingView = [[SurpriiseLoadingView alloc] initWithFrame:CGRectZero];
    }];
    
  4. Instantiate a VoucherCreationFlowCoordinator:

    VoucherCreationFlowCoordinator *voucherCreationFlowCoordinator = [VoucherCreationFlowCoordinator voucherCreationFlowCoordinatorWithManager:creationManager
                                                                                                                                   vouchrTheme:[VouchrConfig defaultVouchrTheme]
                                                                                                                                      delegate:self];
    
  5. Implement the VoucherCreationFlowDelegate methods that is passed into the VoucherCreationFlowCoordinator. Most are optional. The two that must be implemented:

    - (void)voucherCreationShowPaymentOnViewController:(UIViewController *)viewController forVoucher:(Voucher *)voucher onCompletion:(void(^)(NSDictionary *paymentInfo, NSError *error))completion {
        // get payment info here for the voucher
        // MUST CALL completion block when finished
        completion(nil, nil);
    }
    
    - (void)showLoginOnViewController:(UIViewController *)viewController onCompletion:(void(^)(NSError *error))completion {
        // log in the user here
        // if a login view controller needs to be presented, present it on viewController.
        // MUST CALL to userManager loginWithCredentials:refreshTokenClient:onSuccess:onError before calling completion.
        // MUST CALL completion block when finished
        completion(nil);
    }
    
  6. Instantiate PersonalizationOptions for all personalizations that will be available to the user.

    NSMutableArray <PersonalizationOption *> *personalizationOptions = [NSMutableArray new];
    
    [personalizationOptions addObject:[RecipientPersonalizationOption recipientPersonalizationOptionWithBuilder:^(RecipientPersonalizationOptionBuilder *builder) {
            builder.vouchrTheme = [self recipientVouchrTheme]; 
            builder.canChangeUnwrapDate = YES;
            builder.canMakeItARace = YES;
            builder.canSendToEmail = YES;
            builder.canSendToPhoneNumber = YES;
    }]];
    
    [personalizationOptions addObject:[TitlePersonalizationOption titlePersonalizationOptionWithBuilder:^(TitlePersonalizationOptionBuilder *builder) {
    }]];
    
    [personalizationOptions addObject:[PhotoPersonalizationOption photoPersonalizationOptionWithBuilder:^(PhotoPersonalizationOptionBuilder *builder) {
            builder.canAddMultiple = NO;
            builder.canUploadPhotos = NO;
            builder.canAddGoogleImages = YES;
            builder.canTakePhotos = YES;
            builder.suggestedSearchTerms = @[@"one", @"two", @"three"];
    }]];
    
  7. Launch the Voucher Creation flow:

    [voucherCreationFlowCoordinator startFlowOnViewController:self.selectedViewController personalizationOptions:personalizationOptions];