Skip to content

Instantly share code, notes, and snippets.

@leomp12
Created February 9, 2023 22:00
Show Gist options
  • Save leomp12/0931eb5d08445410b344266eacaa1bf6 to your computer and use it in GitHub Desktop.
Save leomp12/0931eb5d08445410b344266eacaa1bf6 to your computer and use it in GitHub Desktop.
E-Com Plus - Manipulando cupons no aplicativo de descontos padrão

E-Com Plus - Manipulando cupons no aplicativo de descontos padrão

1. Busque o ID do aplicativo de descontos instalado na loja:

GET https://api.e-com.plus/v1/applications/app_id:1252.json
  -H "X-Store-ID: <store_id>"

O ID estará na resposta em _id:

{
  "_id": "<discounts_app_id>"
}

2. Adicionar um cupom UMPORCLIENTE:

PATCH https://api.e-com.plus/v1/applications/<discounts_app_id>/hidden_data.json
  -H "X-Store-ID: <store_id>"
  -H "X-My-ID: <authentication_id>"
  -H "X-Access-Token: <access_token>"
  -d '{
    "UMPORCLIENTE": {
      "discount": {
        "apply_at": "subtotal",
        "type": "percentage",
        "value": 10
      },
      "cumulative_discount": true,
      "usage_limit": 1
    }
  }'

3. Removendo o mesmo cupom:

PATCH https://api.e-com.plus/v1/applications/<discounts_app_id>/hidden_data.json
  -H "X-Store-ID: <store_id>"
  -H "X-My-ID: <authentication_id>"
  -H "X-Access-Token: <access_token>"
  -d '{
    "UMPORCLIENTE": null
  }'

Outros exemplos de cupons

{
  "ATE100NOFRETE": {
    "discount": {
      "apply_at": "freight",
      "type": "fixed",
      "value": 50
    },
    "cumulative_discount": true,
    "total_usage_limit": 100
  }
}
{
  "PRAUMCLIENTE": {
    "discount": {
      "apply_at": "total",
      "type": "fixed",
      "value": 100
    },
    "customer_ids": ["abc122202020202"],
    "case_insensitive": true,
    "cumulative_discount": true
  }
}
{
  "ANONOVO": {
    "date_range": {
      "start": "2023-01-01T03:00:00.000Z",
      "end": "2023-02-01T03:00:00.000Z"
    },
    "discount": {
      "apply_at": "subtotal",
      "type": "percentage",
      "value": 5
    },
    "case_insensitive": true,
    "cumulative_discount": true
  }
}

JSON schema do objeto de cupom para referência completa e opções adicionais:

{
  "type": "object",
  "title": "Regra de desconto",
  "required": [
    "discount"
  ],
  "additionalProperties": false,
  "properties": {
    "date_range": {
      "type": "object",
      "title": "Período de validade",
      "description": "Preencha para programar a oferta a datas de início e/ou fim",
      "additionalProperties": false,
      "properties": {
        "start": {
          "type": "string",
          "format": "date-time",
          "title": "Início"
        },
        "end": {
          "type": "string",
          "format": "date-time",
          "title": "Encerramento"
        }
      }
    },
    "case_insensitive": {
      "type": "boolean",
      "title": "Case insensitive",
      "description": "Ative para não diferenciar letras maiúsculas e minúsculas no cupom ou campanha"
    },
    "usage_limit": {
      "type": "integer",
      "minimum": 1,
      "maximum": 1000,
      "title": "Limite de uso por cliente",
      "description": "Limite opcional de aplicação do desconto para cada cliente"
    },
    "total_usage_limit": {
      "type": "integer",
      "minimum": 1,
      "maximum": 1000,
      "title": "Limite de uso total",
      "description": "Limite opcional de aplicação do desconto até desativá-lo"
    },
    "customer_ids": {
      "title": "Lista de clientes selecionados",
      "description": "Se preenchido, o desconto será disponibilizado apenas para estes clientes",
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[a-f0-9]{24}$",
        "title": "ID do cliente"
      }
    },
    "discount": {
      "title": "Desconto concedido",
      "type": "object",
      "required": [
        "value"
      ],
      "additionalProperties": false,
      "properties": {
        "apply_at": {
          "type": "string",
          "enum": [
            "total",
            "subtotal",
            "freight"
          ],
          "default": "total",
          "title": "Aplicar desconto em",
          "description": "Em qual valor o desconto deverá ser aplicado no checkout"
        },
        "min_amount": {
          "type": "integer",
          "minimum": 1,
          "maximum": 999999999,
          "title": "Valor mínimo",
          "description": "Montante mínimo para aplicar o desconto"
        },
        "amount_field": {
          "type": "string",
          "enum": [
            "total",
            "subtotal"
          ],
          "default": "total",
          "title": "Montante a validar",
          "description": "Checar valor mínimo no total ou subtotal do carrinho"
        },
        "type": {
          "type": "string",
          "enum": [
            "percentage",
            "fixed"
          ],
          "default": "fixed",
          "title": "Tipo de desconto",
          "description": "Desconto com valor percentual ou fixo"
        },
        "value": {
          "type": "number",
          "minimum": -99999999,
          "maximum": 99999999,
          "title": "Valor do desconto",
          "description": "Valor percentual ou fixo a ser descontado, dependendo to tipo configurado"
        }
      }
    },
    "product_ids": {
      "title": "Lista de produtos da campanha",
      "description": "Se preenchido, o desconto só será válido se um dos produtos estiver no carrinho",
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[a-f0-9]{24}$",
        "title": "ID do produto"
      }
    },
    "excluded_product_ids": {
      "title": "Produtos excluídos",
      "description": "Se preenchido, o desconto será inválido se um dos produtos estiver no carrinho",
      "type": "array",
      "items": {
        "type": "string",
        "pattern": "^[a-f0-9]{24}$",
        "title": "ID do produto"
      }
    },
    "cumulative_discount": {
      "type": "boolean",
      "default": true,
      "title": "Desconto cumulativo",
      "description": "Se a promoção poderá ser aplicada junto a descontos de pagamento/entrega"
    }
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment