Callbacks
VoucherCreationFlowDelegate
is used to delegate out of the VouchrSDK throughout the create process for input and additional customization.
Required Methods
At a minimum, the following methods must be implemented:
- (void)voucherCreationShowPaymentOnViewController:(UIViewController *)viewController forVoucher:(Voucher *)voucher isEditing:(BOOL)isEditing onCompletion:(void(^)(NSDictionary *paymentInfo, NSError *error))completion;
- (void)showLoginOnViewController:(UIViewController *)viewController onCompletion:(void(^)(NSError *error))completion;
func voucherCreationShowPayment(on viewController: UIViewController!, for voucher: Voucher!, isEditing: Bool, onCompletion completion:(([AnyHashable : Any]?, Error?) -> Void)!)
func showLogin(on viewController: UIViewController!, onCompletion completion: ((Error?) -> Void)!)
Example Implementation
- (void)voucherCreationShowPaymentOnViewController:(UIViewController *)viewController
forVoucher:(Voucher *)voucher
onCompletion:(void(^)(NSDictionary *paymentInfo, NSError *error))completion {
// optionally present a view controller here that collects payment information
NSDictionary *fakeCreditCardInfo = @{@"paymentType": @"CREDIT_CARD",
@"billingCardNumber": [self encryptString:@"4111111111111111"],
@"billingCVV": [self encryptString:@"111"],
@"billingCardHolderName": @"Test test",
@"billingAddress1": @"123 anywhere street",
@"billingCity": @"San Fransisco",
@"billingRegion": @"CA",
@"billingCountry": @"US"};
if (completion) {
completion(fakeCreditCardInfo, nil);
}
}
- (void)showLoginOnViewController:(UIViewController *)viewController onCompletion:(void(^)(NSError *error))completion {
[self.facebookManager loginFromViewController:viewController
onSuccess:^{
if (completion) {
completion(nil);
}
} onError:^(NSError *error) {
if (completion) {
completion(error);
}
}];
}
func voucherCreationShowPayment(on viewController: UIViewController!, for voucher: Voucher!, isEditing: Bool, onCompletion completion:(([AnyHashable : Any]?, Error?) -> Void)!) {
// optionally present a view controller here that collects payment information
let fakeCreditCardInfo = [
"paymentType": "CREDIT_CARD",
"billingCardNumber": self.encryptString(string:"4111111111111111"),
"billingCVV": self.encryptString(string:"111"),
"billingCardHolderName": "Test test",
"billingAddress1": "123 anywhere street",
"billingCity": "San Fransisco",
"billingRegion": "CA",
"billingCountry": "US"
]
if (completion != nil) {
completion(fakeCreditCardInfo, nil);
}
}
func showLogin(on viewController: UIViewController!, onCompletion completion: ((Error?) -> Void)!) {
self.facebookManager?.login(from:viewController, handler: {[weak self] (result: Any?, error: Error?) in
if (completion != nil) {
completion(error)
}
})
}
Optional Methods
Example Implementation
- (NSArray <id<SectionDataSourceProtocol>> *)summaryScreenDataSourcesForVoucher:(Voucher *)voucher {
// You can mix default and custom sections
// default data source
SummaryScreenClaimerInfoDataSource *claimerInfoDataSource = [[SummaryScreenClaimerInfoDataSource alloc] initWithClaimer:voucher.claimer
claimDate:voucher.claimDate
vouchrTheme:self.vouchrTheme];
// custom data source
CustomSummaryScreenClaimerInfoDataSource *customDataSource = [CustomSummaryScreenClaimerInfoDataSource dataSourceWithVoucher:voucher];
return @[claimerInfoDataSource, customDataSource];
}
- (void)showDisclaimerForPaymentMerchantInfo:(PaymentMerchantInfo *)paymentMerchantInfo
onViewController:(UIViewController *)viewController
withCompletion:(void(^)(void))onCompletion {
// some merchants require accepting a disclaimer / UELA before choosing this payment option
if (paymentMerchantInfo.type == PaymentMerchantInfoVanillaVisa) {
[self showDisclaimerForVanillaVisaWithCompletion:onCompletion];
} else {
onCompletion();
}
}
func summaryScreenDataSources(for voucher: Voucher?) -> [SectionDataSourceProtocol?]? {
// You can mix default and custom sections
// default data source
let claimerInfoDataSource = SummaryScreenClaimerInfoDataSource(claimer: voucher?.claimer, claimDate: voucher?.claimDate, vouchrTheme: vouchrTheme)
// custom data source
let customDataSource = CustomSummaryScreenClaimerInfoDataSource(voucher: voucher)
return [claimerInfoDataSource, customDataSource]
}
func showDisclaimer(for paymentMerchantInfo: PaymentMerchantInfo?, on viewController: UIViewController?, withCompletion onCompletion: @escaping () -> Void) {
// some merchants require accepting a disclaimer / UELA before choosing this payment option
if paymentMerchantInfo?.type == PaymentMerchantInfoVanillaVisa {
showDisclaimerForVanillaVisa(withCompletion: onCompletion)
} else {
onCompletion()
}
}