Skip to content

Crossmint/crossmint-swift-checkout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Crossmint Swift Checkout Example

Example iOS app demonstrating the CrossmintEmbeddedCheckout component from the Crossmint Swift SDK.

Installation

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")
]

Integration Flow

1. Create Order (Server-side)

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 order
  • clientSecret - Token scoped to this order for client-side operations

2. Use the Component (Client-side)

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
)

3. Track Order Status (Server-side)

Monitor the order as it progresses through payment and delivery. Use webhooks for real-time updates or polling as a fallback.

Option A: Webhooks (Recommended)

Set up webhooks to receive real-time updates as the order progresses through payment and delivery.

Setup:

  1. Create a POST endpoint on your server (e.g., /webhooks/crossmint)
  2. Configure webhook in Crossmint Console
  3. 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 created
  • orders.payment.succeeded - Payment confirmed
  • orders.delivery.completed - Tokens delivered (includes txId)
  • orders.payment.failed - Payment failed

Important: Always respond with HTTP 200 status to acknowledge receipt.

See full documentation: Webhooks Guide

Option B: Polling (Fallback)

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 payment
  • payment - Processing payment
  • delivery - Payment complete, delivering tokens
  • completed - Tokens delivered successfully

Polling Guidelines:

  • Check order.phase === "completed" for success
  • Check order.payment.failureReason for payment errors
  • Transaction ID available at order.lineItems[0].delivery.txId when completed

See full documentation: Get Order API

Available Properties

Currently Supported

  • orderId - Order identifier from create order API
  • clientSecret - Client secret from create order API
  • payment - Payment method configuration
  • appearance - UI customization options
  • environment - .staging or .production

Work in Progress

The following properties are defined but not yet implemented:

  • lineItems - Line items configuration
  • recipient - Recipient information
  • apiKey - Crossmint Client API Key

Note: More fields will be added in future releases.

Example

See ContentView.swift for a complete working example.

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages