Skip to main content

Step 2: Open the Checkout URL in WebView

Once you have a checkout URL from your backend, use WePaySDK.openCheckoutUrl() to present the checkout screen.


Usage​

import WePaySDK

class ViewController: UIViewController {

func openWePayCheckout(checkoutUrl: String) {
WePaySDK.openCheckoutUrl(
from: self,
checkoutUrl: checkoutUrl
)
}
}

What Happens Automatically​

Calling WePaySDK.openCheckoutUrl() will:

  1. Create a WebViewPaymentViewController
  2. Embed it in a UINavigationController
  3. Present it full screen (modalPresentationStyle = .fullScreen)
  4. Watch URL redirects for /success or /error
  5. Show an alert and dismiss the screen automatically

SwiftUI Support​

If you are using SwiftUI, wrap the call in a UIViewControllerRepresentable or trigger it from a UIHostingController:

import SwiftUI
import WePaySDK

struct CheckoutButton: View {
let checkoutUrl: String
@State private var showCheckout = false

var body: some View {
Button("Pay Now") {
showCheckout = true
}
.fullScreenCover(isPresented: $showCheckout) {
WePayCheckoutView(checkoutUrl: checkoutUrl)
}
}
}

struct WePayCheckoutView: UIViewControllerRepresentable {
let checkoutUrl: String

func makeUIViewController(context: Context) -> UINavigationController {
let webVC = WebViewPaymentViewController(checkoutUrl: checkoutUrl)
let nav = UINavigationController(rootViewController: webVC)
nav.modalPresentationStyle = .fullScreen
return nav
}

func updateUIViewController(_ uiViewController: UINavigationController, context: Context) {}
}

Next Step​

See Step 3 — Advanced Usage if you prefer to use WebViewPaymentViewController directly, or skip to Configuration for Info.plist settings.