Loading dialog
Show the supplied Scan to PayKit loading dialog while you create a code on your backend — for visual consistency with the checkout flow.
The Scan to PayKit SDK ships with a loading dialog you can show during the gap between "customer tapped Pay" and "SDK presents its UI." Most commonly, you'll show it while your backend creates a transaction code.
The dialog is themed to match the rest of the SDK UI, so the customer doesn't see a styling jump. Using it is optional.
When to use it
| Scenario | Use the dialog? |
|---|---|
| You're creating a code server-side after Pay was tapped | Yes |
| You're doing other async work before launching the SDK | Yes |
| You already have your own loader styled to match | Up to you — pick one |
| The code is already on hand | No — launch directly |
Show the dialog
let scanToPay = MPScanToPay()
scanToPay.showLoadingDialogFromController(self)The dialog is presented modally on the supplied controller. It captures user input and shows a branded spinner.
Dismissing
The dialog dismisses automatically when checkout(...), preRegister(...), or walletManagement(...) is called — the SDK transitions from the loader to its own UI.
To dismiss manually (e.g. if your code-creation request fails):
scanToPay.dismissLoadingDialog()Putting it together
A typical "create code, then pay" flow:
@IBAction func payAction(_ sender: Any) {
let scanToPay = MPScanToPay()
// 1. Show the loader
scanToPay.showLoadingDialogFromController(self)
// 2. Call your backend to create a code
yourBackend.createCode(orderId: orderId) { result in
DispatchQueue.main.async {
switch result {
case .failure(let error):
scanToPay.dismissLoadingDialog()
self.showError("Couldn't start payment")
case .success(let code):
// 3. Launch the checkout — the dialog will transition out
scanToPay.checkout(withCode: code,
apiKey: "YOUR_API_KEY",
system: .live,
controller: self,
delegate: self)
}
}
}
}What's next
- Take a payment → Payments
- Drop-in button instead of custom UI → Pay-by-Card button
Updated 2 days ago
