Swift Setup
For Objective-C setup see Objective-C Setup.
Create / Setup a
VouchrConfig
with your values. You can alternatively use a plist file to provide values. SeeVouchrConfig
for details.let vouchrConfig:VouchrConfig = VouchrConfig() vouchrConfig.serverUrl = "" // This will be given to you by Vouchr vouchrConfig.sdkString = "" // This will be given to you by Vouchr
Instantiate a
VouchrEngine
with your preferred dependencies and theVouchrConfig
you created.let vouchrEngineSDK:VouchrEngine = VouchrEngine(config: vouchrConfig, builder: { (builder) in // override any default managers here // eg. builder.networkManager = YourNetworkManager() })
Instantiate a
VoucherCreationManager
:let creationManager:VoucherCreationManager = VoucherCreationManager(builder:{ (builder) in // override any default settings // eg. builder.dialogViewTheme = SurpriiseTheme().themeForVouchrDialogScreenFromBaseTheme() })
Instantiate a
VoucherCreationFlowCoordinator
:let voucherCreationFlowCoordinator = VoucherCreationFlowCoordinator(manager: creationManager, vouchrTheme: SurpriiseTheme().themeForCreateScreenFromBaseTheme(), delegate: self)
Implement the
VoucherCreationFlowDelegate
methods that is passed into theVoucherCreationFlowCoordinator
. Most are optional. The two that must be implemented:func voucherCreationShowPayment(on viewController: UIViewController, for voucher: Voucher, isEditing: Bool, onCompletion completion: @escaping ([AnyHashable : 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) }
Instantiate
PersonalizationOption
s for all personalizations that will be available to the user.var personalizationOptions:[PersonalizationOption] = [] personalizationOptions.append(RecipientPersonalizationOption (builderBlock:{ (builder) in builder!.canSendToEmail = true builder!.canChangeUnwrapDate = true builder!.canMakeItARace = true builder!.canSendToPhoneNumber = true builder!.vouchrTheme = SurpriiseTheme().themeForRecipientScreenFromBaseTheme() })) personalizationOptions.append(MoneyPersonalizationOption (builderBlock: { (builder) in }))
Launch the Voucher Creation flow:
voucherCreationFlowCoordinator.startFlow(on: self, personalizationOptions: personalizationOptions)