Integration for iOS

Prerequisites

Before implementing Mercado Pago Wallet payments, ensure you have:

  1. Enabled Mercado Pago in the DEUNA Admin Panel.
  2. A generated order token.
  3. Integrated the DEUNA iOS SDK in your project.
  4. Reviewed the Payment Widget documentation for iOS.

Payment Widget Implementation

Modal Implementation (Page Sheet)

Display the payment widget by passing the Mercado Pago configuration in the paymentMethods parameter:

deunaSDK.initPaymentWidget(
    orderToken: "<DEUNA_ORDER_TOKEN>",
    callbacks: PaymentWidgetCallbacks(
        onSuccess: { order in
            // Close the DEUNA widget
            self.deunaSDK.close {
                // Handle successful payment:
                // - Navigate to confirmation screen
                // - Show success message
                // - Update order status
            }
        },
        onError: { error in                
            if error.type == .paymentError {
                // Handle payment errors:
                // - Show error message
                // - Allow retry
                // - Log analytics
            }
        }
    ),
    paymentMethods: [
        [
            "paymentMethod": "wallet",
            "processors": ["mercadopago_wallet"]
        ]
    ]
)

Embedded Implementation (SwiftUI)

For SwiftUI implementations:

import DeunaSDK
import SwiftUI

struct PaymentView: View {
    let deunaSDK: DeunaSDK
    
    var body: some View {
        VStack {
            DeunaWidget(
                deunaSDK: deunaSDK,
                configuration: PaymentWidgetConfiguration(
                    orderToken: "YOUR_ORDER_TOKEN",
                    callbacks: PaymentWidgetCallbacks(
                        onSuccess: { order in
                            deunaSDK.dispose {
                                // Handle post-payment flow
                            }
                        },
                        onError: { error in
                            if error.type == .paymentError {
                                // Implement error handling
                            }        
                        }
                    ),
                    paymentMethods: [
                        [
                            "paymentMethod": "wallet",
                            "processors": ["mercadopago_wallet"]
                        ]
                    ]
                )
            )
        }
    }
}

📘

iOS-Specific Considerations

⚠️ Mercado Pago Security Requirements

  1. SafariViewController Requirement:
    • Mercado Pago mandates the use of SafariViewController for payment processing.
    • This ensures secure handling of payment credentials.
  2. ViewController Dismissal:
    • The SafariViewController must be manually dismissed by the user.
    • The SDK's close() function won't automatically dismiss it.

✅ Best Practices

Always provide a completion handler to the close() function to ensure your code executes only after both:

  1. The user manually dismisses the SafariViewController (as required by Mercado Pago)
  2. The payment modal completes its dismissal animation
self.deunaSDK.close {
    // This executes sequentially after:
    // 1. User closes SafariViewController
    // 2. Payment modal fully disappears

    // Recommended actions:
    // 1. Navigate to order confirmation
    // 2. Display transaction success UI
    // 3. Update application state
}

✅ Memory Management

For embedded implementations, always call dispose() when the widget is no longer needed to prevent memory leaks:

deunaSDK.dispose {
    // Cleanup resources
}