Integration for iOS
Prerequisites
Before implementing Mercado Pago Wallet payments, ensure you have:
- Enabled Mercado Pago in the DEUNA Admin Panel.
- A generated order token.
- Integrated the DEUNA iOS SDK in your project.
- 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
- SafariViewController Requirement:
- Mercado Pago mandates the use of SafariViewController for payment processing.
- This ensures secure handling of payment credentials.
- 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:
- The user manually dismisses the SafariViewController (as required by Mercado Pago)
- 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 }
Updated about 6 hours ago