Skip to main content

Prerequisites

Before integrating Dodo Payments into your mobile app, ensure you have:
  • Dodo Payments Account: Active merchant account with API access
  • API Credentials: API key and webhook secret key from your dashboard
  • Mobile App Project: Android, iOS, React Native, or Flutter application
  • Backend Server: To securely handle checkout session creation

Integration Workflow

The mobile integration follows a secure 4-step process where your backend handles API calls and your mobile app manages the user experience.
1

Backend: Create Checkout Session

Checkout Session API Docs

Learn how to create a checkout session in your backend using Node.js, Python, and more. See complete examples and parameter references in the dedicated Checkout Sessions API documentation.
Security: Checkout sessions must be created on your backend server, never in the mobile app. This protects your API keys and ensures proper validation.
2

Mobile: Get Checkout URL

Your mobile app calls your backend to get the checkout URL:
  • iOS (Swift)
  • Android (Kotlin)
  • React Native (JavaScript)
func getCheckoutURL(productId: String, customerEmail: String, customerName: String) async throws -> String {
    let url = URL(string: "https://your-backend.com/api/create-checkout-session")!
    var request = URLRequest(url: url)
    request.httpMethod = "POST"
    request.setValue("application/json", forHTTPHeaderField: "Content-Type")
    
    let requestData: [String: Any] = [
        "productId": productId,
        "customerEmail": customerEmail,
        "customerName": customerName
    ]
    request.httpBody = try JSONSerialization.data(withJSONObject: requestData)
    
    let (data, _) = try await URLSession.shared.data(for: request)
    let response = try JSONDecoder().decode(CheckoutResponse.self, from: data)
    return response.checkout_url
}
Security: Mobile apps only communicate with your backend, never directly with Dodo Payments API.
3

Mobile: Open Checkout in Browser

4

Backend: Handle Payment Completion

Process payment completion via webhooks and redirect URLs to confirm payment status.

Platform-Specific Integration

Choose your mobile platform below for complete implementation examples:
  • Android
  • iOS
  • React Native
  • Flutter

Android Integration

Chrome Custom Tabs Implementation

// Add Chrome Custom Tabs dependency to build.gradle
implementation 'androidx.browser:browser:1.5.0'

// In your Activity
class PaymentActivity : AppCompatActivity() {
    private var customTabsSession: CustomTabsSession? = null
    private var customTabsClient: CustomTabsClient? = null
    private var customTabsServiceConnection: CustomTabsServiceConnection? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        // Initialize Custom Tabs
        customTabsServiceConnection = object : CustomTabsServiceConnection() {
            override fun onCustomTabsServiceConnected(name: ComponentName, client: CustomTabsClient) {
                customTabsClient = client
                customTabsClient?.warmup(0L)
                customTabsSession = customTabsClient?.newSession(object : CustomTabsCallback() {
                    override fun onNavigationEvent(navigationEvent: Int, extras: Bundle?) {
                        // Handle navigation events
                    }
                })
            }
            override fun onServiceDisconnected(name: ComponentName) {
                customTabsClient = null
            }
        }
        CustomTabsClient.bindCustomTabsService(
            this,
            "com.android.chrome",
            customTabsServiceConnection!!
        )
        // Get checkout URL from backend and launch
        lifecycleScope.launch {
            try {
                val checkoutURL = getCheckoutURL("prod_123", "customer@example.com", "Customer Name")
                val customTabsIntent = CustomTabsIntent.Builder(customTabsSession)
                    .build()
                customTabsIntent.launchUrl(this@PaymentActivity, Uri.parse(checkoutURL))
            } catch (e: Exception) {
                // Handle error
                Log.e("PaymentActivity", "Failed to get checkout URL", e)
            }
        }
    }
}

Best Practices

  • Security: Never store API keys in your app code. Use secure storage and SSL pinning.
  • User Experience: Show loading indicators, handle errors gracefully, and provide clear messages.
  • Testing: Use test cards, simulate network errors, and test on various devices.

Troubleshooting

Common Issues

  • WebView not opening payment link: Ensure the payment link is valid and uses HTTPS.
  • Callback not received: Check your return URL and webhook configuration.
  • API key errors: Verify that your API key is correct and has the necessary permissions.

Additional Resources

For questions or support, contact support@dodopayments.com.
I