# Payment automation

This section describes how to use automated payments processing. We also provide links to information on Mews PCI compliance, including current certification. For connecting to Mews Payment Terminals to take payments from customers, please refer to [Mews Payment Terminals](/connector-api/use-cases/mews-terminals.md).

> #### PCI Compliance
>
> * [Mews PCI compliance](https://help.mews.com/s/article/pci-compliance?language=en_US)
> * [Mews PCI certificate](https://www.mews.com/en/platform-documentation)

## Using tokenized credit cards

If the user interface of your solution involves the collection and storage of credit card details in a secure manner against the customer's profile in Mews, you can use [Add tokenized credit card](/connector-api/operations/creditcards.md#add-tokenized-credit-card) and then [Charge credit card](/connector-api/operations/creditcards.md#charge-credit-card) to securely take and post a payment into Mews. The workflow mimics the result of a user manually [adding a new payment card](https://mews.force.com/s/article/add-a-new-payment-card?language=en_US) in Mews Operations and then [charging the card via the Mews payment gateway](https://help.mews.com/s/article/take-a-payment?language=en_US).

| 'How to' use case                                     | API Operations                                                                                  |
| ----------------------------------------------------- | ----------------------------------------------------------------------------------------------- |
| How to add a credit card to the guest profile         | [Add tokenized credit card](/connector-api/operations/creditcards.md#add-tokenized-credit-card) |
| How to charge a guest credit card using Mews Payments | [Charge credit card](/connector-api/operations/creditcards.md#charge-credit-card)               |

## Retrieving tokenized credit cards

To check if a user's credit card is already attached to their customer profile, call [Get all credit cards](/connector-api/operations/creditcards.md#get-all-credit-cards) to search for credit cards by the `CreditCardId` or `CustomerId`. The credit cards tokenized via the Mews Payment Gateway (PCI Proxy) can be identified by the [`Credit card kind`](/connector-api/operations/creditcards.md#credit-card-kind) property, with the corresponding value being "Gateway".

| 'How to' use case                                               | API Operations                                                                        |
| --------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| How to check if a credit card is stored against a guest profile | [Get all credit cards](/connector-api/operations/creditcards.md#get-all-credit-cards) |

## Adding a tokenized credit card

### 1. Retrieve PublicKey

As an integration partner, you will not need to set up your own Payment Gateway account. Rather, when automating payments via the **Mews Connector API**, you should work with Mews' own account. To do so, call [Get configuration](/connector-api/operations/configuration.md#get-configuration) to obtain the `PublicKey` value, found within the [payment card storage](/connector-api/operations/configuration.md#payment-card-storage) object. This value will be used as the `merchantId` with the Mews Payment Gateway (PCI Proxy).

| 'How to' use case                                       | API Operations                                                                    |
| ------------------------------------------------------- | --------------------------------------------------------------------------------- |
| How to get the merchant ID for the Mews Payment Gateway | [Get configuration](/connector-api/operations/configuration.md#get-configuration) |

### 2. Set up the Secure Fields payment form to collect card data

Refer to the [PCI Proxy documentation on Secure Fields](https://docs.pci-proxy.com/docs/secure-fields) for collecting card number, CVV and expiration date\* through the Secure Fields payment form. Implement Quick Start Step 1 [Set up your Payment Form](https://docs.pci-proxy.com/docs/secure-fields-quick-start) and follow the **Secure Fields Form** recipe. As part of this process, you will use the Mews `PublicKey` (obtained in the step above) as the `merchantId`. Take note of `data.transactionId` in the response, which looks like a series of numbers (e.g. `201028230732590232`). For further assistance, see [Integration Examples](https://docs.pci-proxy.com/docs/secure-fields-examples). Note you do *not* need to follow Step 2 [Obtain the tokens](https://docs.pci-proxy.com/docs/secure-fields-quick-start), this step is performed instead by the Mews back-end.

> **Expiration date:** Though not required by PCI Proxy, credit card expiration date is listed as a mandatory parameter on the [Add tokenized credit card](/connector-api/operations/creditcards.md#add-tokenized-credit-card) endpoint so that it can be displayed within the customer profile in Mews. This can also be used as an additional validation method for the property to know if there is an expired card on file. To handle this, we recommend that the payment form includes a field for users to input their credit card expiration date, which need not be sent to PCI Proxy, but should be cached, so that the information can be included in the [Add tokenized credit card](/connector-api/operations/creditcards.md#add-tokenized-credit-card) API request.

### 3. Add the tokenized credit card to a customer profile in Mews

Add the tokenized credit card to a customer profile in Mews by calling [Add tokenized credit card](/connector-api/operations/creditcards.md#add-tokenized-credit-card). Enter the `transactionId` and obfuscated credit card details in the [credit card data](/connector-api/operations/creditcards.md#credit-card-data) object. Take note of the `CreditCardId` in the API response.

> **Obfuscated number:** `ObfuscatedNumber` should only contain at most the first six digits and last four digits of a credit card. Alternatively replacing the entire string value with 16 asterisks `*` is also acceptable.

The credit card will now be visible in the customer profile in Mews, under the **Payments > Credit cards** section. Note that while customer profiles are shared across all properties in a chain, credit card details are not.

## Charging the tokenized credit card

Now that you have the `CreditCardid`, you can use the [Charge credit card](/connector-api/operations/creditcards.md#charge-credit-card) endpoint to charge the customer.

> **Charge credit card:** Note the [Charge credit card](/connector-api/operations/creditcards.md#charge-credit-card) operation actually charges the customer's credit card, whereas the [Add credit card payment](/connector-api/operations/payments.md#add-credit-card-payment) operation does NOT. The latter simply records a credit card payment in Mews and does not trigger any additional action beyond Mews - suitable for when the customer's credit card has already been charged from your solution.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.mews.com/connector-api/use-cases/payment-automation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
