Mobile quickstart
Your server decides the amount; the app shows the sheet and pays it.
1. Create a checkout session on your server
typescript
// Your server: an endpoint your app calls when the customer taps Pay.
app.post('/checkout-session', async (req, res) => {
const session = await watenga.checkoutSessions.create({
amount: '25.00', // decided by your server, never by the app
currency: 'USD',
reference: req.body.orderId,
});
res.json({ client_secret: session.client_secret, amount: 25, currency: 'USD', reference: req.body.orderId });
});2. Show the sheet in your app
plain
import SwiftUI
import Watenga
struct PayButton: View {
@State private var config: WatengaSheetConfig?
@State private var show = false
private let watenga = WatengaCheckout(publicKey: "pk_test_your_key")
var body: some View {
Button("Pay") {
Task {
let session = try await MyAPI.createCheckoutSession(orderId: "ORD-1001") // your server
config = WatengaSheetConfig(amount: 25, currency: "USD", reference: "ORD-1001", clientSecret: session.clientSecret)
show = true
}
}
.sheet(isPresented: $show) {
if let config {
watenga.sheet(config: config) { result in
show = false
if result.isCompleted { print("Paid", result.transactionId ?? "") }
}
}
}
}
}
3. Confirm on your server
Fulfil the order when your server receives payment.capture.completed for the transaction (its data.object.id is the transactionId the sheet returned).
Never put a secret key in an app
Anyone can read an app's contents. Apps use the publishable key and a client secret; only your server holds
sk_… keys.