> For the complete documentation index, see [llms.txt](https://docs.commercelayer.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.commercelayer.io/rules-engine/use-cases/promotions/get-percentage-discount-credit-card.md).

# Get a discount when paying by credit card

This rule applies a discount to an order based on the payment method. The order's payment source type is checked and a percentage discount is applied to the order's total amount if the conditions are met.

The example below is based on the following reference JSONs. Once the rules are evaluated against the resource payload, the outcomes show if and how the conditions are matched and the related actions applied.

{% tabs %}
{% tab title="Rules" %}

```json
{
  "rules": [
    {
      "name": "Discount 3% if paid by credit card",
      "conditions": [
        {
          "field": "order.payment_method.payment_source_type",
          "matcher": "eq",
          "value": "credit_cards"
        }
      ],
      "actions": [
        {
          "type": "percentage",
          "selector": "order",
          "value": 0.03
        }
      ]
    }
  ]
} 
```

{% endtab %}

{% tab title="Order" %}

```json
{
  "order": {
    "id": "oKkhYLlzgE",
    "payment_method": {
      "id": "gnYtPpKLeG",
      "payment_source_type": "credit_cards"
    }
  }
}
```

{% endtab %}

{% tab title="Outcomes" %}

```json
[
  {
    "id": "b569f656-8bc2-4253-a19b-56062e7653ab",
    "name": "Discount 3% if paid by credit card",
    "priority": 0,
    "match": true,
    "conditions_logic": "and",
    "conditions": [
      {
        "field": "order.payment_method.payment_source_type",
        "matcher": "eq",
        "value": "credit_cards",
        "scope": "any",
        "group": "1ff9ec3e-c46c-4a2e-ace3-670ef5ddc5b3",
        "match": true,
        "matches": [
          {
            "order": "oKkhYLlzgE",
            "payment_method": "gnYtPpKLeG",
            "group": "1ff9ec3e-c46c-4a2e-ace3-670ef5ddc5b3"
          }
        ]
      }
    ],
    "actions": [
      {
        "resources": [
          {
            "resource_type": "orders",
            "id": "oKkhYLlzgE",
            "group": "1ff9ec3e-c46c-4a2e-ace3-670ef5ddc5b3",
            "quantity": null,
            "value": 0.03,
            "action_type": "percentage"
          }
        ]
      }
    ]
  }
]
```

{% endtab %}
{% endtabs %}

## Rules breakdown

The desired results can be achieved with a single rule.

#### Conditions

The only condition in the rule checks if the payment source type associated with the order is `credit_card`.

#### Actions

The only action in the rule applies a 3% discount to the whole order amount if the condition is met.

## Resource payload analysis

The provided payload contains an order with an associated payment source type that is `credit_card`, thus qualifying for the discount.

## Outcomes check

The outcomes reflect the evaluation of the rules against the resource payload. Since the order's payment source satisfies the condition, the rule matches successfully (`match` is `true`). The order line items to which the discount is applied and the related payment methods are listed within the `matches` array. The action is applied to the order with the decimal value of `0.03` corresponding to the specified percentage discount.

## Conclusion

The rule matches the provided order payload. Consequently, a 3% discount is applied to the order's total amount due to the payment method being a credit card.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://docs.commercelayer.io/rules-engine/use-cases/promotions/get-percentage-discount-credit-card.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
