Module commercetools.pricingdiscount

ballerinax/commercetools.pricingdiscount Ballerina library

2.0.0

Overview

commercetools is a composable commerce platform that provides API-first building blocks for online storefronts, carts, orders, customers and catalogs. Its pricing and discount features let merchants run promotions on carts and products, issue discount codes, and manage the tax categories and rates used to price orders.

The commercetools Pricing and Discount connector lets Ballerina applications manage cart discounts, discount codes, product discounts and tax categories in a commercetools Project. It supports version 1 of the commercetools HTTP API.

Key features

  • Create, query, update and delete cart discounts, by ID or by key
  • Create, query, update and delete discount codes that apply cart discounts at checkout
  • Manage product discounts and look up the discount that matches a product price
  • Maintain tax categories and their tax rates with versioned update actions that protect against concurrent modification
  • Authenticate with the OAuth 2.0 client credentials grant using a commercetools API client

Setup guide

To use the commercetools Pricing and Discount connector, you need a commercetools Project and an API client that can access its discounts and tax categories. If you do not have a commercetools account, you can sign up for a trial here.

Step 1: Create an API client

  1. Open the Merchant Center and select your Project.

  2. Go to Settings → Developer settings and select Create new API client.

  3. Give the client a name and select the scopes for the resources you use: view_cart_discounts and manage_cart_discounts, view_discount_codes and manage_discount_codes, view_product_discounts and manage_product_discounts, and view_tax_categories and manage_tax_categories.

Step 2: Note down the credentials

After the client is created, copy the following values. The client secret is shown only once.

  • Project key
  • Client ID
  • Client secret
  • Auth URL, for example https://auth.europe-west1.gcp.commercetools.com
  • API URL, for example https://api.europe-west1.gcp.commercetools.com

The token URL is the auth URL followed by /oauth/token.

Quickstart

To use the commercetools Pricing and Discount connector in your Ballerina application, update the .bal file as follows:

Step 1: Import the module

Import the commercetools.pricingdiscount module.

Copy
import ballerinax/commercetools.pricingdiscount;

Step 2: Instantiate a new connector

  1. Create a Config.toml file and configure the credentials obtained in the steps above:
Copy
clientId = "<Client ID>"
clientSecret = "<Client Secret>"
tokenUrl = "<Auth URL>/oauth/token"
apiUrl = "<API URL>"
projectKey = "<Project key>"
  1. Create a pricingdiscount:ConnectionConfig with the OAuth 2.0 client credentials and initialize the connector with it.
Copy
configurable string clientId = ?;
configurable string clientSecret = ?;
configurable string tokenUrl = ?;
configurable string apiUrl = ?;
configurable string projectKey = ?;

final pricingdiscount:Client commercetools = check new ({
    auth: {
        tokenUrl,
        clientId,
        clientSecret
    }
}, apiUrl);

Step 3: Invoke the connector operation

Now, utilize the available connector operations.

List the cart discounts

Copy
public function main() returns error? {
    pricingdiscount:CartDiscountPagedQueryResponse _ = check commercetools->listCartDiscounts(projectKey);
}

Step 4: Run the Ballerina application

Copy
bal run

Examples

The commercetools Pricing and Discount connector provides practical examples illustrating usage in various scenarios. Explore these examples, covering the following use cases:

  1. Discount catalog review - List the cart discounts, product discounts and discount codes of a Project, and fail when an active discount code refers to a cart discount that is missing or inactive.

  2. Tax category setup - Create a tax category with a German rate, add a French rate with a versioned update action, verify both rates and optionally delete the category.

Import

import ballerinax/commercetools.pricingdiscount;Copy

Other versions

See more...

Metadata

Released date: about 18 hours ago

Version: 2.0.0

License: Apache-2.0


Security

Direct vulnerabilities: No known direct vulnerabilities

Indirect vulnerabilities: 

Checked on 2026-11-20 via OSV.dev


Compatibility

Platform: any

Ballerina version: 2201.12.0

GraalVM compatible: Yes


Pull count

Total: 51

Current verison: 1


Weekly downloads


Source repository


Keywords

Vendor/Commercetools

Area/E-Commerce

Type/Connector


Contributors