1.0.1 • Published 4 months ago

promotion-engine v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
4 months ago

Promotion Engine SDK

The promotion-engine SDK is a headless product designed to enable brands and presales to seamlessly create and manage campaigns. This SDK provides a set of APIs for both brands and presales, allowing them to work independently on our platform.

Installation

To install the promotion-engine SDK, use the following npm command:

npm install promotion-engine

Usage

Initialization

import PE from "promotion-engine";

// Initialize the SDK with your API key and hostname
const pe = new PE({ apiKey: "", baseUrl: "http://localhost:8080" });

Endpoints

Brand External API Management

1. Redeem Promo Code

Method: POST

Endpoint: /promo_code/redeem-promo-code

Description: Redeem Promo Code at Brands Platform end.

Request Object

ParametersTypeDescription
promocodestringThe promo code to redeem.
brandstringBrand identifier.
pre_sales_idstringPresales ID.
customerobjectCustomer details.
agenumberCustomer's age.
genderstringCustomer's gender.
countrystringCustomer's country.
statestringCustomer's state.
citystringCustomer's city.
orderobjectOrder details.
amountnumberOrder amount.
paymentMethodstringPayment method.
shippingChargenumberShipping charge.
skuarrayArray of SKU details.
skustringSKU identifier.
pricenumberPrice per item.
itemQuantitynumberQuantity of items.
user_mobilestringUser's mobile number.
user_emailstringUser's email address.
user_idstringUser ID.

Example:

const redeemPromoCode = async () => {
  const { data, error } = await pe.redeemPromoCode({
    user_mobile: "xxxxxxxxxx",
    promocode: "christmas2023",
    // other parameters
  });

  console.log(data, error);
};

redeemPromoCode();

Response:

{
  "status": {
    "code": 200,
    "error": false
  },
  "message": "Promo Code is valid.",
  "result": {
    "discount": 200,
    "promoCodeValue": 1500,
    "message": "You got a cashback of 20% of your order.",
    "skuData": [
      {
        "sku": "SKU1",
        "price": 1000,
        "itemQuantity": 1
      }
    ],
    "usageId": "6bf21948-ec82-41ec-8aa7-942705db68be"
  }
}

NOTES:

  • The usageId in the response represents a unique identifier for the redeemed promo code, and it can be used to place an order.

  • The usageId is valid for 10 minutes. After this period, a new call to the "Redeem Promo Code" endpoint is required to obtain a new usageId for placing orders.

2. Place Order

Method: POST

Endpoint: /usage/{id}/place-order

Description: Place an order at Brands Platform end.

Request Object

ParametersTypeDescription
idstringThe ID associated with the order.
user_mobilestringUser's mobile number.
user_emailstringUser's email address.
order_idstringOrder ID.
return_periodnumberReturn period in days.
isRedeemedbooleanWhether the order is redeemed or not.
promocode_idstringPromo code identifier.
pre_sales_idstringPresales ID.
usage_time_stampstringTimestamp of usage.
user_idstringUser ID.
order_dataanyOrder data (structure may vary).
totalAmountnumberTotal order amount.
discountedAmountnumberDiscounted amount.
use_withinstringTimeframe within which the promo code can be used.
isExpiredbooleanWhether the promo code is expired or not.
discountValuenumberThe discount value applied.
commissionnumberCommission amount.
processing_feenumberProcessing fee amount.
payoutstringPayout details.

3. Return Order

Method: POST

Endpoint: /usage/return-order

Description: Return an order at Brands Platform end.

Request Object

PropertyTypeDescription
order_idstringOrder ID to initiate the return process.

4. Attach with User

Method: POST

Endpoint: /promo_code/attach-with-user

Description: Attach a Promo Code with a user.

Request Object

PropertyTypeDescription
promocodestringPromo Code to attach with the user.
brandstringBrand identifier (optional).
user_mobilestringUser's mobile number.
user_emailstringUser's email address.

Presales External API Management

1. List Affiliate Campaigns

Method: GET

Endpoint: /promotions/get-all-aff-dynamic/{id}

Description: Get all dynamic affiliate campaigns for a presale.

Parameters:

PropertyTypeDescription
idstringPresale ID to retrieve affiliate campaigns for.

Response:

{
  "status": {
    "code": 200,
    "error": false
  },
  "message": "Affiliate campaigns retrieved successfully.",
  "result": [
    {
      "promotionId": "unique_promotion_id_1",   // Promotion identifier
      "campaignId": "unique_campaign_id_1",     // Campaign identifier
      "campaignName": "Campaign 1",             // Campaign name
      "brandName": "Brand 1"                    // Brand name associated with the campaign
    },
    {
      "promotionId": "unique_promotion_id_2",
      "campaignId": "unique_campaign_id_2",
      "campaignName": "Campaign 2",
      "brandName": "Brand 2"
    }
    // ... Additional campaigns
  ]
}

2. Generate Promo Code

Method: POST

Endpoint: /promo_code/generate-promo-code

Description: Generate a dynamic promo code for presales at the Brands Platform end.

Request Object

ParametersTypeDescription
promotion_idstringPromotion ID for which the promo code is generated.
user_mobilestringUser's mobile number for associating with the generated promo code.
user_emailstringUser's email address (optional).

NOTE:

  • The promotion_id and user_mobile parameters are required for generating the promo code.

Response:

{
  "status": {
    "code": 200,
    "error": false
  },
  "message": "Promo Code is valid.",
  "result": {
    "promocodeDetails": {
      "id": "unique_promocode_id",
      "code": "YOUR_GENERATED_PROMO_CODE",
      "promotion_id": "your_promotion_id",
      "description": "Promocode Description",
      "type": "dynamic",
      "number_of_uses": 0,
      "minPurchaseAmount": 1000,
      "maxRedemptions": 1,
      "start_date": "2023-01-01T00:00:00.000Z",
      "end_date": "2023-01-01T00:00:00.000Z",
      "number_of_use_per_customer": 1,
      "is_exclusive": true,
      "is_custom_usage": false,
      "duration": "null",
      "interval": "null",
      "user_id": "user_id",
      "tnc": "Terms and Conditions",
      "redemptionProcess": "Redemption Process",
      "logo": "Logo",
      "creatives": "Creatives",
      "name": "Name"
    },
    "brandUrl": "https://www.example.com"
  }
}

3. Attach with User

Method: POST

Endpoint: /promo_code/attach-with-user

Description: Attach a Promo Code with a user.

Request Object

PropertyTypeDescription
promocodestringPromo Code to attach with the user.
brandstringBrand identifier (optional).
user_mobilestringUser's mobile number.
user_emailstringUser's email address.
1.0.1

4 months ago

1.0.0

5 months ago

1.1.4

5 months ago