Sending a Voucher
1. Create / Setup a VOConfig
with your values. You can alternatively use a plist file to provide values. See VOConfig
for details.
In order to provide users access to Youtube, Giphy or Google Image personalizations, you must obtain a corresponding API key and assign them appropriately to your VOConfig
.
VOConfig *vouchrConfig = [VOConfig 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
vouchrConfig.youtubeAccessKey = @"" // Google API key
vouchrConfig.giphyApiKey = @"" // Giphy API key
vouchrConfig.googleImageSearchEngineId = @"" // Google Image Search Engine ID
vouchrConfig.googleImageApiKey = @"" // Google Image API key
let vouchrConfig = VOConfig()
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
vouchrConfig.youtubeAccessKey = "" // Google API key
vouchrConfig.giphyApiKey = "" // Giphy API key
vouchrConfig.googleImageSearchEngineId = "" // Google Image Search Engine ID
vouchrConfig.googleImageApiKey = "" // Google Image API key
2. Instantiate a VOEngine
with your preferred dependencies and the VOConfig
you created.
VOEngine *vouchrEngineSDK = [VOEngine vouchrEngineWithConfig:vouchrConfig builder:^(VouchrEngineBuilder *builder) {
// override any default managers here
// eg. builder.networkManager = [YourNetworkManager new];
}];
let vouchrEngineSDK:VOEngine = VOEngine(config: vouchrConfig, builder: { (builder) in
// override any default managers here
// eg. builder.networkManager = YourNetworkManager()
})
3. Instantiate a VOVoucherCreationManager
:
VOVoucherCreationManager *creationManager = [VOVoucherCreationManager voucherCreationManagerWithBuilder:^(VoucherCreationManagerBuilder *builder) {
// override any default settings
// eg. builder.fullScreenLoadingView = [[VOLoadingView alloc] initWithFrame:CGRectZero];
}];
let creationManager:VOVoucherCreationManager = VOVoucherCreationManager(builder:{ (builder) in
// override any default settings
// eg. builder.fullScreenLoadingView = VOLoadingView(frame: CGRect.zero)
})
4. Instantiate a VOVoucherCreationFlowCoordinator
:
VOVoucherCreationFlowCoordinator *voucherCreationFlowCoordinator = [VOVoucherCreationFlowCoordinator voucherCreationFlowCoordinatorWithCreationManager:creationManager
discoverManager:discoverManager
vouchrTheme:[VOConfig defaultVouchrTheme]
delegate:self];
let voucherCreationFlowCoordinator = VOVoucherCreationFlowCoordinator(creationManager: creationManager, discoverManager:discoverManager, vouchrTheme: VOConfig.defaultVouchrTheme(), delegate: self)
5. Implement the VOVoucherCreationFlowDelegate
methods that is passed into the VOVoucherCreationFlowCoordinator
. Most are optional. The two that must be implemented:
- (void)collectPaymentInfoOnViewController:(UIViewController *)viewController forVoucher:(VOVoucher *)voucher onCompletion:(void (^)(NSDictionary<NSString *, id> * _Nullable, NSError * _Nullable))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);
}
func collectPaymentInfo(on viewController: UIViewController?, for voucher: VOVoucher?, onCompletion completion: @escaping ([String : Any?]?, Error?) -> Void) {
// get payment info here for the voucher
// MUST CALL completion block when finished
completion(nil, nil)
}
func showLogin(on viewController: UIViewController!, onCompletion completion: ((Error?) -> Void)!) {
// 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 VOPersonalizationOption
s for all personalizations that will be available to the user.
NSMutableArray <VOPersonalizationOption *> *personalizationOptions = [NSMutableArray new];
[personalizationOptions addObject:[VORecipientPersonalizationOption recipientPersonalizationOptionWithBuilder:^(VORecipientPersonalizationOptionBuilder *builder) {
// set builder properties here
}]];
[personalizationOptions addObject:[VOTitlePersonalizationOption titlePersonalizationOptionWithBuilder:^(VOTitlePersonalizationOptionBuilder *builder) {
// set builder properties here
}]];
[personalizationOptions addObject:[VOPhotoPersonalizationOption photoPersonalizationOptionWithBuilder:^(VOPhotoPersonalizationOptionBuilder *builder) {
// set builder properties here
}]];
var personalizationOptions:[VOPersonalizationOption] = []
personalizationOptions.append(VORecipientPersonalizationOption (builderBlock:{ (builder) in
// set builder properties here
}))
personalizationOptions.append(VOTitlePersonalizationOption (builderBlock: { (builder) in
// set builder properties here
}))
personalizationOptions.append(VOPhotoPersonalizationOption (builderBlock: { (builder) in
// set builder properties here
}))
7. Launch the Voucher Creation flow:
[voucherCreationFlowCoordinator launchCreationScreenOnViewController:selectedViewController personalizationOptions:personalizationOptions];
voucherCreationFlowCoordinator.launchCreationScreen(on: selectedViewController, personalizationOptions: personalizationOptions)