Payments

Nabla iOS Scheduling Payments

Add a payment step

If you enabled payments on the Nabla Console, you need to handle them by adding a step to the appointment booking process in the SDK.

The payment is handled by implementing ScheduleAppointmentDelegate. Use it to provide a UIViewController to handle the payment for that appointment. It can be a UINavigationController if you need multiple screens to implement your payment flow.

When completion is called, the SDK will check that the appointment was marked as paid. Make sure your server is calling Nabla's server to mark as paid and that your app waits for this operation to succeed before calling completion. Otherwise, it will result in an error.

Examples

Here is an example implementation where the ScheduleAppointmentDelegate is implemented by some SchedulingCoordinator:


extension SchedulingCoordinator: ScheduleAppointmentDelegate {
    func paymentViewController(for appointment: Appointment, completion: @escaping (Result<Void, Error>) -> Void) -> UIViewController {
        // Payment is required, return your own UIViewController that handles payment.
        let viewController = MyPaymentViewController(for: appointment)
        // You must call the `completion` block when payment succeeds (or fails).
        viewController.completion = completion
        return viewController
    }

    func scheduleAppointmentDidSucceed(with appointment: Appointment) {
        print("Appointment scheduled: \(appointment)")
        navigationController.dismiss(animated: true)
    }
}

If you don't use coordinators, those delegates can be implemented by your UIViewController or any other class.