Wallet
Integrating Wallet
To use Wallet, you need to implement VNWalletDelegate
and pass the instance to the VNWallet.configure(delegate:)
method.
Configure Wallet as follows:
public func applicationDidFinishLaunching(_ application: UIApplication) {
/// ....
//Configure wallet with optional theme
//For custom theme Subclass VNWalletBaseTheme or create new object that conforms to protocol VNWalletThemable
VenueNext.configure(wallet: VNWallet.shared, walletDelegate: self, theme: MyCustomTheme())
//turn on wallet for VNOrder
VenueNext.enableWallet(for: VNOrder.shared)
//...
}
configure(wallet: <VNWalletProtocol>, walletDelegate: <VNWalletDelegate>)
- Required and must be called with VNWallet singleton, delegate must conform to VNWalletDelegate
enableWallet(for: <VNOrderProtocol>)
- optional configuration however must be called if you want VNWallet to be enabled on cart
VNWalletDelegate
has the following requirements:
@objc public protocol VNWalletDelegate {
/*
* Provide a login controller that will be handling the login process
* Be sure to call `completion` when you have successfully authenticated the user.
* - parameter completion:NSError: Passing an error to this function will restart the login process (i.e. loginController will get called again)
*/
func loginController(completion: @escaping (VNWalletUser?, NSError?) -> Void) -> UIViewController
/*
* If user object is passed in, it will bypass login screen and take you directly to wallet
*/
@objc func walletUser() -> VNWalletUser?
}
Additional Notes
loginController(completion:)
- If you don’t have the concept of a login, or only use login for Wallet, you can return an instance of a login controller to be presented. In the case of a successful login, use the user’s data to create a VNWalletUser, eg: VNWalletUser(firstName: "Bob", lastName: "Doe", email: "bob@somewhere.com", externalID: "<userID>")
, and pass the VNWalletUser to the completion. If an error is passed to the completion
, a new login controller will be requested and shown to the user.
walletUser()
- In the case that login presentation and control is managed elsewhere, such as app launch/start, you can use this method to construct and return a VNWalletUser. This will bypass the need to present authentication or login in order to present wallet, and the user will be presented their balance. If you don’t have this data, you can simply return nil
.
Launching Wallet
import VenueNextWalletUI
navigationController?.pushVNWalletViewController(animated: true)