Example iOS app demonstrating the CrossmintEmbeddedCheckout component from the Crossmint Swift SDK.
This example always uses the latest version from the main branch of the Crossmint Swift SDK.
To use a specific version in production, we recommend:
dependencies: [
.package(url: "https://github.com/Crossmint/crossmint-swift-sdk", branch: "main")
]First, create an order on your server using the Crossmint API:
Important: Order creation must be done server-side to keep your API key secure.
# Production
curl --location 'https://www.crossmint.com/api/2022-06-09/orders' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{
"recipient": {
"walletAddress": "WALLET_ADDRESS"
},
"payment": {
"receiptEmail": "[email protected]",
"method": "card"
},
"lineItems": {
"tokenLocator": "chain:token",
"executionParameters": {
"mode": "exact-in",
"amount": "1"
}
}
}'
# Staging
curl --location 'https://staging.crossmint.com/api/2022-06-09/orders' \
--header 'x-api-key: YOUR_API_KEY' \
--header 'Content-Type: application/json' \
--data-raw '{...}'See full documentation: Create Order API and Payment Methods
The response will include:
orderId- Unique identifier for the orderclientSecret- Token scoped to this order for client-side operations
Pass the orderId, clientSecret, and optional configuration to the component:
import SwiftUI
import Checkout
CrossmintEmbeddedCheckout(
orderId: "your-order-id",
clientSecret: "your-client-secret",
payment: CheckoutPayment(
crypto: CheckoutCryptoPayment(enabled: false),
fiat: CheckoutFiatPayment(
enabled: true,
allowedMethods: CheckoutAllowedMethods(
googlePay: false,
applePay: true,
card: false
)
)
),
appearance: CheckoutAppearance(
rules: CheckoutAppearanceRules(
destinationInput: CheckoutDestinationInputRule(display: "hidden"),
receiptEmailInput: CheckoutReceiptEmailInputRule(display: "hidden")
)
),
environment: .production // or .staging
)Monitor the order as it progresses through payment and delivery. Use webhooks for real-time updates or polling as a fallback.
Set up webhooks to receive real-time updates as the order progresses through payment and delivery.
Setup:
- Create a
POSTendpoint on your server (e.g.,/webhooks/crossmint) - Configure webhook in Crossmint Console
- Save the signing secret for verification
Your endpoint will receive:
{
"type": "orders.payment.succeeded",
"payload": {
"orderId": "...",
"payment": {
"status": "completed",
"received": {
"amount": "100.00",
"currency": "usd"
}
}
// ... full order object
}
}Key Events:
orders.quote.created- Order createdorders.payment.succeeded- Payment confirmedorders.delivery.completed- Tokens delivered (includestxId)orders.payment.failed- Payment failed
Important: Always respond with HTTP 200 status to acknowledge receipt.
See full documentation: Webhooks Guide
Poll the order status if webhooks aren't feasible. Be mindful of rate limits.
# Production
curl --location 'https://www.crossmint.com/api/2022-06-09/orders/{orderId}' \
--header 'x-api-key: YOUR_API_KEY'
# Staging
curl --location 'https://staging.crossmint.com/api/2022-06-09/orders/{orderId}' \
--header 'x-api-key: YOUR_API_KEY'Response includes order phase:
quote- Order created, awaiting paymentpayment- Processing paymentdelivery- Payment complete, delivering tokenscompleted- Tokens delivered successfully
Polling Guidelines:
- Check
order.phase === "completed"for success - Check
order.payment.failureReasonfor payment errors - Transaction ID available at
order.lineItems[0].delivery.txIdwhen completed
See full documentation: Get Order API
orderId- Order identifier from create order APIclientSecret- Client secret from create order APIpayment- Payment method configurationappearance- UI customization optionsenvironment-.stagingor.production
The following properties are defined but not yet implemented:
lineItems- Line items configurationrecipient- Recipient informationapiKey- Crossmint Client API Key
Note: More fields will be added in future releases.
See ContentView.swift for a complete working example.