Mercado Pago integration for mobile applications
This model lets you offer Apple Pay in your mobile application without managing payment certificates or decrypting tokens on your server. You can integrate via SDK, using the Mercado Pago native SDK for iOS in your app to display the Apple Pay button, or via API, implementing the flow in your backend and sending from the app the data that Apple returns. In both cases, Mercado Pago handles validation with Apple and returns a token ready to create the payment.
sequenceDiagram
participant C as Buyer
participant A as App (iOS)
participant Apple as Apple
participant MP as Mercado Pago
A->>A: Check availability (Apple Pay + cards)
C->>A: Tap Apple Pay button
A->>Apple: Payment request (Touch ID/Face ID)
Apple-->>A: Apple payment token
A->>MP: Create token (SDK or API)
MP-->>A: Mercado Pago token
A->>A: Send token to backend
A->>MP: Create payment (token + data)
MP-->>A: Payment response
In this integration you use the Mercado Pago native SDK for iOS in your app. The SDK converts the Apple token into a Mercado Pago card token; your backend receives that token and creates the payment. Follow the steps below to integrate.
Having obtained and configured the required Apple Developer certificates, use the Mercado Pago native SDK to integrate payment methods in iOS applications. Below we show how to install and initialize the SDK.
Install the SDK
Follow the step-by-step to install the SDK in your Swift project.
- In Swift Package Manager, click File > Add Package Dependencies.
- Paste the repository URL:
https://github.com/mercadopago/sdk-ios. - Select the desired SDK version.
- Click Add Package to complete the installation.
Add dependencies
Import the SDK dependencies in your project by running the following code:
plain
import CoreMethods
Initialize the SDK
After installing the SDK and adding the dependencies to your project, initialize the SDK at the start of the application lifecycle. This ensures that all essential configuration is defined before any payment operation.
To ensure correct operation, make a call to initialize() before using any other SDK functionality. To initialize the Mercado Pago library, you need to use your credentialsUnique access keys we use to identify an integration in your account, linked to your application. For more information, see the link below.Credentials, linked to the applicationEntity registered in Mercado Pago that acts as an identifier to manage your integrations. For more information, see the link below.Application details you created.
At this stage, you must use your test Public KeyPublic key of the application created in Mercado Pago, used in the frontend. You can access it in Your integrations > Application details > Test > Test credentials..

import UIKit
import CoreMethods
@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
let configuration = MercadoPagoSDK.Configuration(
publicKey: "YOUR-PUBLIC-KEY",
country: // Enter the country of your public key
)
MercadoPagoSDK.shared.initialize(configuration)
return true
}
}
import SwiftUI
import CoreMethods
@main
struct YourApp: App {
init() {
let configuration = MercadoPagoSDK.Configuration(
publicKey: "<YOUR-PUBLIC-KEY>",
country: "<Enter the country of your public key>",
locale: "en-US"
)
MercadoPagoSDK.shared.initialize(configuration)
}
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
The initialization parameters are listed in the table below.
| Parameter | Type | Description | Required |
public_key | String | test Public KeyPublic key of the application created in Mercado Pago, used in the frontend. You can access it in Your integrations > Application details > Test > Test credentials.: used in the frontend to access information. | Required |
locale | String | Locale identifier (language and country). By default, the system locale is used. | Optional |
country | Country | Enum that identifies the country in which Core Methods will be processed. Use the country code corresponding to your test Public KeyPublic key of the application created in Mercado Pago. You can access it in Your integrations > Application details > Test > Test credentials.. See the documentation to verify the code for your country. | Required |
To enable Apple Pay in your app, configure the required capabilities in XcodeApple's integrated development environment (IDE) for creating applications for iOS, iPadOS, macOS, watchOS and tvOS.:
- In Xcode, select the project file in the Project Navigator and the app's main Target.
- Go to the Signing & Capabilities tab and click + Capability.
- In the search box, type "Apple Pay" and add the capability.
- In the Apple Pay section, select the Merchant ID you created in the Apple Developer Portal. If it does not appear, refresh the list using the circular arrow icon.

Before displaying the Apple Pay button, you need to check that the user's device is compatible and has at least one card configured in the Wallet app. To do this, run the following code.
import MPApplePay
import PassKit
import UIKit
class YourCheckoutViewController: UIViewController {
let applePayButton: PKPaymentButton = PKPaymentButton(paymentButtonType: .plain, paymentButtonStyle: .black)
let mpApplePay: MPApplePay = .init()
override func viewDidLoad() {
super.viewDidLoad()
applePayButton.isHidden = !MPApplePay.canMakePayments()
applePayButton.addTarget(self, action: #selector(handleApplePayButton), for: .touchUpInside)
}
}
Button customization
You can change the button type and style in the PKPaymentButton(paymentButtonType:paymentButtonStyle:) initializer. For more appearance and Apple Pay interface options, see the official Apple documentation.
In the method that runs when the user taps the Apple Pay button, create the payment request with the transaction data, configure the summary items, and present the Apple Pay sheetModal screen that Apple shows the buyer with the payment summary, selected card, and authorization request with Touch ID or Face ID.. See the elements to complete in the table below.
@objc
func handleApplePayButton() {
let request = MPApplePay.paymentRequest(
withMerchantIdentifier: "merchant.your-identifier",
currency: "BRL"
)
let item = PKPaymentSummaryItem(
label: "Product name",
amount: NSDecimalNumber(value: 10),
type: .final
)
let totalItem = PKPaymentSummaryItem(
label: "YOUR STORE",
amount: NSDecimalNumber(value: 10),
type: .final
)
request.paymentSummaryItems = [item, totalItem]
let paymentController = PKPaymentAuthorizationController(paymentRequest: request)
paymentController.delegate = self
paymentController.present()
}
| Element | Type | Description | Required |
withMerchantIdentifier | String | Merchant ID you configured in the Apple Developer Portal. It must match the one in your app. | Required |
currency | String | Transaction currency code, for example BRL or ARS. | Required |
PKPaymentSummaryItem | Object | Each summary item the buyer sees: label (product or merchant name), amount (amount) and type (e.g. .final). | Required |
paymentSummaryItems | Array | List of summary items. The last one must be the purchase total; its label is usually your store name. | Required |
PKPaymentAuthorizationController | Object | Apple controller that displays the payment sheet. It is created with the request, the delegate is set to receive the result, and it is presented with present(). | Required |
Implement the PKPaymentAuthorizationControllerDelegate method to receive the Apple token, convert it to a card token with the SDK, and send it to your backend.
extension YourCheckoutViewController: PKPaymentAuthorizationControllerDelegate {
func paymentAuthorizationController(
_ controller: PKPaymentAuthorizationController,
didAuthorizePayment payment: PKPayment,
handler completion: @escaping (PKPaymentAuthorizationResult) -> Void
) {
Task {
do {
let response = try await mpApplePay.createToken(
payment.token
)
// send the token to your backend to process the payment
await sendYourBackend(response.token)
completion(
PKPaymentAuthorizationResult(
status: .success,
errors: nil
)
)
} catch {
completion(
PKPaymentAuthorizationResult(
status: .failure,
errors: [error]
)
)
}
}
}
func paymentAuthorizationControllerDidFinish(
_ controller: PKPaymentAuthorizationController
) {
controller.dismiss()
}
}
| Element | Type | Description | Required |
paymentAuthorizationController(_:didAuthorizePayment:handler:) | Method | Delegate method that Apple calls when the buyer authorizes the payment. You receive controller, payment (with the Apple token) and completion to report the result. | Required |
payment.token | Object | Payment token that Apple provides in payment. It is sent to mpApplePay.createToken(payment.token). | Required |
mpApplePay.createToken(payment.token) | Method | Converts the Apple token into a Mercado Pago card token. Returns an object with response.token. | Required |
response.token | String | Mercado Pago card token. Send it to your backend with sendToBackend(response.token) to create the payment. | Required |
completion(PKPaymentAuthorizationResult(status:errors:)) | Callback | Completion parameter that Apple gives you in the delegate: it is the callback you must call with .success and errors: nil on success, or with .failure and errors: [error] on error. This allows Apple to close the sheet with the correct status. | Required |
paymentAuthorizationControllerDidFinish(_:) | Method | Method that Apple calls when the sheet is closed. Dismisses the controller with controller.dismiss(). | Required |
You can simulate different payment outcomes in development by passing the status parameter when creating the token:
let response = try await mpApplePay.createToken(
payment.token,
status: "APRO"
)
status value | Payment scenario |
APRO | Payment approved |
OTHE | Rejected due to general error |
CONT | Pending payment |
CALL | Rejected with validation to authorize |
FUND | Rejected due to insufficient funds |
SECU | Rejected due to invalid security code |
EXPI | Rejected due to expiration date |
FORM | Rejected due to form error |
CARD | Rejected due to missing card_number |
INST | Rejected due to invalid installments |
DUPL | Rejected due to duplicate payment |
LOCK | Rejected due to disabled card |
CTNA | Rejected due to card type not allowed |
ATTE | Rejected due to PIN attempts exceeded |
BLAC | Rejected due to blacklist |
UNSU | Not supported |
TEST | Used to apply amount rule |
