Need to create rules based on bundles?
Learn more
LogoLogo
APIsChangelog
  • Getting started
  • Rules
  • Conditions
    • Scope
    • Aggregations
    • Nested
    • Dynamic values
  • Actions
    • Types
      • Percentage
      • Fixed amount
      • Fixed price
      • Buy X pay Y
      • Every X discount Y
    • Bundle
      • Balanced
      • Every
    • Aggregation
    • Limit
  • Matchers
  • Operators
  • Check and validation
  • Core API integration
    • Order rules
    • Price rules
    • Virtual relationships
  • Resources
    • Promotions
    • Price lists
  • Use cases
    • Promotions
      • Discount line items based on item's price
      • Get a discount when paying by credit card
      • Discount an order based on promo item and total number of items
      • Offer a specific shipping method for free in a specific country
      • Discount items with large stock availability
      • Discount all the SKU in an order based on the shipping country
      • Discount all the SKU in an order based on the customer email domain
    • Price lists
      • Discount all prices greater than or equal to a specific value
      • Discount specific SKUs for new clients
      • Change strike-through price based on customer email domain
On this page
  • Rules breakdown
  • Resource payload analysis
  • Outcomes check
  • Conclusion
  1. Use cases
  2. Promotions

Get a discount when paying by credit card

Rule breakdown, resource payload analysis, and outcomes explanation

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.

{
  "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
        }
      ]
    }
  ]
} 
{
  "order": {
    "id": "oKkhYLlzgE",
    "payment_method": {
      "id": "gnYtPpKLeG",
      "payment_source_type": "credit_cards"
    }
  }
}
[
  {
    "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"
          }
        ]
      }
    ]
  }
]

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.

PreviousDiscount line items based on item's priceNextDiscount an order based on promo item and total number of items

Last updated 2 months ago