# Apple Pay Automation on Real Devices

> For the full site index for AI agents, see [llms.txt](https://www.testmuai.com/support/docs/llms.txt).

(); shippingDetails.put(\"firstName\", \"John\"); shippingDetails.put(\"lastName\", \"Doe\"); shippingDetails.put(\"street\", \"221B Baker Street\"); shippingDetails.put(\"city\", \"London\"); shippingDetails.put(\"postalCode\", \"NW1 6XE\"); shippingDetails.put(\"state\", \"London\"); shippingDetails.put(\"country\", \"UK\"); Map billingDetails = new HashMap<>(); billingDetails.put(\"firstName\", \"John\"); billingDetails.put(\"lastName\", \"Doe\"); billingDetails.put(\"street\", \"221B Baker Street\"); billingDetails.put(\"city\", \"London\"); billingDetails.put(\"postalCode\", \"NW1 6XE\"); billingDetails.put(\"state\", \"London\"); billingDetails.put(\"country\", \"UK\"); Map contact = new HashMap<>(); contact.put(\"email\", \"john.doe@example.com\");...",
          "url": "https://www.testmuai.com/support/docs/apple-pay-auto/#step-3-update-shipping-billing-and-contact-details-optional"
        },
        {
          "@type": "HowToStep",
          "position": 4,
          "name": "Step 4: Confirm Apple Pay Payment",
          "text": "To confirm Apple Pay payment at the payment step, add a hook to confirm and complete the payment. This can be done using TestMu AI hooks. A sample script is provided below to trigger confirmation of the Apple Pay payment step:",
          "url": "https://www.testmuai.com/support/docs/apple-pay-auto/#step-4-confirm-apple-pay-payment"
        },
        {
          "@type": "HowToStep",
          "position": 5,
          "name": "Step 5: Enter Passcode to Complete Payment",
          "text": "After confirming the Apple Pay payment, the device will prompt for the passcode to securely authorize the transaction. Your automation script must handle this prompt by entering the passcode using Appium's keyboard input methods to simulate the user securely confirming the payment. The default passcode is 123456 unless configured differently on the device. This step is essential to simulate secure confirmation and complete the Apple Pay transaction during automation.",
          "url": "https://www.testmuai.com/support/docs/apple-pay-auto/#step-5-enter-passcode-to-complete-payment"
        }
      ]
    }
  ]) }}
/>

# Apple Pay Automation on Real Devices

**Apple Pay** is Apple’s secure digital wallet and payment system that enables purchases, one-click checkouts, and adds an extra layer of protection for financial transactions. In real-world apps and websites, Apple Pay is widely used for simplifying checkout experiences, reducing friction, and improving user trust.

For **testing payment flows**, validating Apple Pay becomes critical. Automation of Apple Pay ensures you can reliably test end-to-end purchase scenarios, confirm that payment sheets open correctly, details are pre-filled, and transactions are processed securely, without relying on production cards.

With TestMu AI, you can automate Apple Pay flows on **real iOS devices**. From provisioning Wallet with sandboxed test cards, to injecting payment details, confirming payments, and entering the passcode, TestMu AI provides a seamless way to run and validate Apple Pay scenarios as part of your automation suite.

**Plus Plan Feature**
This feature is available exclusively with the **Real Device Plus Automation Cloud** Plan.

To unlock this feature, purchase or upgrade to the required [plan](https://www.testmuai.com/pricing/). If you need assistance, please contact your TestMu AI support representative, reach out to our **[24×7 Chat Support]**, or email us at **support@testmuai.com**.

**Automating with Playwright?**
This guide covers the **Appium** flow. Apple Pay is also supported for **Playwright** tests on real iOS devices (Safari, Node.js) over the CDP endpoint. See [Apple Pay Automation in the Playwright iOS guide](/support/docs/playwright-ios-device/#apple-pay-automation).

## Use Cases

- **Checkout Validation**: Ensure your in-app or web checkout flow works seamlessly with Apple Pay as a payment method.
- **End-to-End Payment Testing**: Validate that Apple Pay sheets open correctly, test cards are provisioned, and transactions are processed end-to-end.
- **CI/CD Integration**: Run Apple Pay scenarios as part of continuous integration pipelines to catch payment flow issues early.
- **Cross-Network Stability**: Test across Visa, MasterCard, and other networks to ensure consistent user experiences.
- **Security & Compliance**: Confirm that sensitive flows like passcode entry and secure card handling behave as expected during automation.

## Supported Devices
Currently, the Device Passcode feature in App Automation is enabled on the following iOS real devices:

| iOS Device  | iOS Version |
|-------------|-------------|
| iPhone 17   | 26          |
| iPhone 16   | 18          |
| iPhone 15   | 17          |
| iPhone 14   | 16          |
| iPhone 13   | 15          |

> We are actively working on expanding coverage to **all supported iOS devices** on TestMu AI Real Device Cloud.

## Capabilities

| Capability                  | Type       | Default | Required / Optional | Description                                                                                 |
|----------------------------|------------|---------|---------------------|---------------------------------------------------------------------------------------------|
| **applePay**                | Boolean    | true    | Mandatory           | Enables Apple Pay provisioning including Wallet, Sandbox card, AssistiveTouch, and Passcode on supported real iOS devices. |
| **applePayCardType**        | Array      | None    | Optional           | Specify preferred payment networks. Currently, you can choose from four supported cards: `["amex", "visa", "master", "discover"]`.|

The `applePayCardType` array follows a **priority order**. The order you provide determines which card type is used first. For example, `["visa", "master"]` will prioritize Visa over MasterCard.

## Apple Pay Workflow in Automation Test

### Step 1: Upload Your App to TestMu AI

1. **Uploading Your App** – Follow the detailed steps in our [Upload Your Application](/support/docs/application-setup-via-api/) guide.
2. Once uploaded, **note the App ID** returned by the API or dashboard.
3. Use this **App ID** in the `"app"` capability in your automation script.

### Step 2: Add Desired Capabilities

To enable Apple Pay automation, include the following capability in your automation session as highlighted in the Capabilities:

{`desired_caps = {
    "deviceName": "iPhone 16",
    "platformName": "iOS",
    "platformVersion": "18",
    "isRealMobile": True,
    "app": "YOUR_APP_ID",
    "build": "Sample Build",
    "name": "Sample Test",
    // highlight-next-line
    "applePay": true,
    // highlight-next-line
    "applePayCardType": ["visa", "master"]
}`}

- You must add the generated **APP_URL** to the `app` capability in the config file.
- You can generate capabilities for your test requirements with the help of our inbuilt [**Capabilities Generator tool**](https://www.testmuai.com/capabilities-generator/). For more details, please refer to our guide on [**Desired Capabilities in Appium**](/support/docs/desired-capabilities-in-appium/).

### Step 3: Update Shipping, Billing, and Contact Details (Optional)

Before confirming the Apple Pay payment, you can optionally update the shipping details, billing details, and contact information using the `applePayDetails` hook. This allows you to customize the payment information dynamically during your automation test.

**Note:** The `applePayDetails` hook is not currently supported on iOS 26 devices. Support is under active development and will be available in a future release.

{`driver.execute_script("applePayDetails", {
    "shippingDetails": {
        "firstName": "John",
        "lastName": "Doe",
        "street": "221B Baker Street",
        "city": "London",
        "postalCode": "NW1 6XE",
        "state": "London",
        "country": "UK"
    },
    "billingDetails": {
        "firstName": "John",
        "lastName": "Doe",
        "street": "221B Baker Street",
        "city": "London",
        "postalCode": "NW1 6XE",
        "state": "London",
        "country": "UK"
    },
    "contact": {
        "email": "john.doe@example.com",
        "phone": "+441234567890"
    }
})`}

{`Map shippingDetails = new HashMap<>();
shippingDetails.put("firstName", "John");
shippingDetails.put("lastName", "Doe");
shippingDetails.put("street", "221B Baker Street");
shippingDetails.put("city", "London");
shippingDetails.put("postalCode", "NW1 6XE");
shippingDetails.put("state", "London");
shippingDetails.put("country", "UK");

Map billingDetails = new HashMap<>();
billingDetails.put("firstName", "John");
billingDetails.put("lastName", "Doe");
billingDetails.put("street", "221B Baker Street");
billingDetails.put("city", "London");
billingDetails.put("postalCode", "NW1 6XE");
billingDetails.put("state", "London");
billingDetails.put("country", "UK");

Map contact = new HashMap<>();
contact.put("email", "john.doe@example.com");
contact.put("phone", "+441234567890");

Map applePayDetailsUpdate = new HashMap<>();
applePayDetailsUpdate.put("shippingDetails", shippingDetails);
applePayDetailsUpdate.put("billingDetails", billingDetails);
applePayDetailsUpdate.put("contact", contact);

driver.executeScript("applePayDetails", applePayDetailsUpdate);`}

{`await driver.executeScript("applePayDetails", {
    shippingDetails: {
        firstName: "John",
        lastName: "Doe",
        street: "221B Baker Street",
        city: "London",
        postalCode: "NW1 6XE",
        state: "London",
        country: "UK"
    },
    billingDetails: {
        firstName: "John",
        lastName: "Doe",
        street: "221B Baker Street",
        city: "London",
        postalCode: "NW1 6XE",
        state: "London",
        country: "UK"
    },
    contact: {
        email: "john.doe@example.com",
        phone: "+441234567890"
    }
});`}

#### Hook Parameters

| Parameter | Type | Description |
|-----------|------|-------------|
| **shippingDetails** | Object | Shipping address information including firstName, lastName, street, city, postalCode, state, and country. |
| **billingDetails** | Object | Billing address information with the same fields as shippingDetails. |
| **contact** | Object | Contact information including email and phone number. |

All parameters are optional. You can provide only the details you need to update. For example, you can update only the billing details without providing shipping or contact information.

### Step 4: Confirm Apple Pay Payment

- To confirm Apple Pay payment at the payment step, add a hook to confirm and complete the payment.
- This can be done using TestMu AI hooks. A sample script is provided below to trigger confirmation of the Apple Pay payment step:

```python
driver.execute_script(
'lambda_executor: {"action": "lambda-applepay", "arguments": {"confirmPayment": "true"}}'
)
```

### Step 5: Enter Passcode to Complete Payment

- After confirming the Apple Pay payment, the device will prompt for the passcode to securely authorize the transaction. Your automation script must handle this prompt by entering the passcode using Appium's keyboard input methods to simulate the user securely confirming the payment.

```Python
driver.find_element(By.XPATH,"//*[@name=\"Passcode field\"]").send_keys("123456")
```

 The default passcode is `123456` unless configured differently on the device. This step is essential to simulate secure confirmation and complete the Apple Pay transaction during automation.
