Step 1: Get Checkout URL from Your Backend
Before you can open the WePay checkout in the iOS app, your backend server must generate a checkout URL.
note
The iOS SDK does not call the WePay API directly. All API calls (authentication, contract creation, checkout) must be made server-side. The app only receives the final checkout URL from your backend.
What Your Backend Must Do​
Your server should perform these steps (see the Integration API docs for full details):
- Authenticate — Obtain an access token via
POST /oauth/token(Step 1 - Authentication). - Create a Contract —
POST /apps/api/contracts(Step 2 - Create Contract). - Start Checkout —
POST /apps/api/contracts/checkoutto obtain the checkout URL (Step 3 & 4 - Checkout). - Return the checkout URL to the iOS app.
Example Backend Response​
Your API endpoint should return something like:
{
"checkoutUrl": "https://pay.wepay.com/checkout?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}
Example iOS API Call​
Fetch the checkout URL from your backend before launching the SDK:
import Foundation
struct CheckoutResponse: Decodable {
let checkoutUrl: String
}
func fetchCheckoutUrl(orderId: String) async throws -> String {
let url = URL(string: "https://your-backend.com/payment/checkout-url?orderId=\(orderId)")!
let (data, _) = try await URLSession.shared.data(from: url)
let response = try JSONDecoder().decode(CheckoutResponse.self, from: data)
return response.checkoutUrl
}
// In your ViewController
Task {
let checkoutUrl = try await fetchCheckoutUrl(orderId: "ORDER_123")
await MainActor.run {
openWePayCheckout(checkoutUrl: checkoutUrl)
}
}
Next Step​
Proceed to Step 2 — Open Checkout to launch the checkout WebView in your iOS app.