Swift Setup

For Objective-C setup see Objective-C Setup.

  1. Create / Setup a VouchrConfig with your values. You can alternatively use a plist file to provide values. See VouchrConfig 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
    
  2. Instantiate a VouchrEngine with your preferred dependencies and the VouchrConfig you created.

    let vouchrEngineSDK:VouchrEngine = VouchrEngine(config: vouchrConfig, builder: { (builder) in
        // override any default managers here
        // eg. builder.networkManager = YourNetworkManager()        
    })
    
  3. Instantiate a VoucherCreationManager:

    let creationManager:VoucherCreationManager = VoucherCreationManager(builder:{ (builder) in
        // override any default settings 
        // eg. builder.dialogViewTheme = SurpriiseTheme().themeForVouchrDialogScreenFromBaseTheme()
    })
    
  4. Instantiate a VoucherCreationFlowCoordinator:

    let voucherCreationFlowCoordinator = VoucherCreationFlowCoordinator(manager: creationManager, vouchrTheme: SurpriiseTheme().themeForCreateScreenFromBaseTheme(), delegate: self)
    
  5. Implement the VoucherCreationFlowDelegate methods that is passed into the VoucherCreationFlowCoordinator. 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)
    }
    
  6. Instantiate PersonalizationOptions 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
    }))
    
  7. Launch the Voucher Creation flow:

    voucherCreationFlowCoordinator.startFlow(on: self, personalizationOptions: personalizationOptions)