npm package: @prestashopcorp/builtfor-generator-vanilla
Description: Built for PS generator with customization option
Author: Squad Billing Platform
Latest version: 1.6.1

<div align="center">
  <br>
  <a href="https://prestashop.com">
    <img src="https://prestashop.com/sites/default/files/email/logo_x2_rebrand.png" alt="Logo" width="293" height="33">
  </a>
  <br>
  <br>
</div>

# Built for PS Generator

This CLI allow you to generate a Built For PS with different parameters: PrestaShop version, Billing i sandbox or not, Billing environment, Product ID (which allow to use different pricing model)

### Requirements

First of all you need to install composer, please refer to the [Linux / Unix / MacOS instruction](https://getcomposer.org/doc/00-intro.md#installation-linux-unix-macos) or [Windows instructions](https://getcomposer.org/doc/00-intro.md#installation-windows).

## Installation

```bash
npm i -g @prestashopcorp/builtfor-generator-vanilla
```

or

```bash
yarn global add @prestashopcorp/builtfor-generator-vanilla
```

## Usage

### Classic

Launch in a terminal this command

```bash
builtforGen -id <productId> [...other options]
```

#### Options for classic usage

```man
Generate Built for PS for PrestaShop

Options:
  -id, --productId <productId>                Technical id of the Built for PS. This id will be used to generate the Built for PS with the proper value. Ths value should match the product family item configured
                                              in Chargebee, otherwise you must create it.
  --psVersion <version>                       Description of the Built for PS (choices: "1.7", "8", "9", default: "9")
  -s --sandbox                                Use this flag to generate a Built for PS in sandbox mode
  -e, --environment <environment>             Specify an environment when you don't want to use the production (choices: "prestabulle1", "prestabulle2", "prestabulle3", "prestabulle4", "prestabulle5",
                                              "prestabulle6", "preprod")
  -t, --template <template>                   Specify a template when you want to handling display of yours plans  (choices: "standard", "handle",
                                              default: "standard")
  -wd, --workingDir <path>                    Directory where the Built for PS will be created. You can specify a relative or an absolute path. (default: "tmp")
  -d, --description <description>             Description of the Built for PS (default: "Built for PS in Vanilla JS for PrestaShop")
  -name, --displayName <name>                 Display name of the Built for PS
  -c, --context <context>                     This option allow you to inject some information within the context. Please give a stringified json: '{"foo": "bar"}' (default: {})
  --customCancellation                        Use this flag to activate custom cancellation modal
  -l, --module-lib-billing-version <version>  This option allow you set the version of module-lib-billing. If you want to set it to a branch, you should add `dev` in front of it
                                              (i.g. `dev-feat/my-feature` (default: "^4.0.0")
  -h, --help                       display help for command
```

#### Focus on --context

You need to use this when the [Built For PS documentation about billing](https://docs.cloud.prestashop.com/5-prestashop-billing/), mention to add info within the context from your Javascript (in configure.tpl).

In this case please refer to the documentation to known which JSON structure should be used.

Example:

```json
// JSON which allow you to specify the unit when using a stairstep pricing model, in order to display
// the proper information in the plan page into the funnel
{
  "product": {
    "components": [
      {
        "id": "builtfor_example_stairstep", // this is the pricing id in chargebee
        "unitDescription": "Users"
      }
    ]
  }
}
```

### Registered configuration

This script provide some registered configuration to save time. In this case the module generated is compatible with PS version 1.7, and all config are in sandbox.

```bash
builtforRegistered -c <config>
```

#### Options for registered configuration

```man
Generate Built for PS for PrestaShop with registered whole configuration

Options:
  -c, --config <config>  Select your registered configuration (choices: "flat_bulle1", "flat_bulle2", "flat_bulle3", "flat_bulle4", "flat_bulle5", "flat_bulle6", "flat_preprod", "flat", "flat_handle_bulle1",
                         "flat_handle_bulle2", "flat_handle_bulle3", "flat_handle_bulle4", "flat_handle_bulle5", "flat_handle_bulle6", "flat_handle_preprod", "flat_handle", "stairstep_bulle1", "stairstep_bulle2",
                         "stairstep_bulle3", "stairstep_bulle4", "stairstep_bulle5", "stairstep_bulle6", "stairstep_preprod", "stairstep")
  -h, --help             display help for command
```

### Examples

The product id is the key that makes this module either flat fee or stairstep

#### PS 9, Live, Production

##### Generate a flat fee module

```bash
builtforGen -id builtfor_example -d "PS 9 | Built for PS with a flat fee pricing"
```

##### Generate a flat fee module with the offer already selected

```bash
builtforGen \
  -id builtfor_example \
  -s \
  -e prestabulle2 \
  -d "PS 9 | Built for PS with a flat fee pricing in sandbox for prestabulle2. Selection automatic of the plan." \
  -c '{"offerSelection": {"offerPricingId": "builtfor_example-ultimate-EUR-Monthly"}}'
```

##### Generate a stairstep module

```bash
builtforGen \
  -id builtfor_example_stairstep \
  -d "PS 9 | Built for PS with a stairstep pricing" \
  -c '{"product": {"components": [{"id": "builtfor_example_stairstep", "unitDescription": "Users" }]}}'
```

##### Generate a stairstep module with preselected step

```bash
builtforGen \
  -id builtfor_example_stairstep \
  -s \
  -e prestabulle2 \
  -d "PS 9 | Built for PS with a stairstep pricing in sandbox for prestabulle2" \
  -c '{"product": {"components": [{"id": "builtfor_example_stairstep", "unitDescription": "Users" }]}, "offerSelection": {"offerPricingId": "builtfor_example_stairstep", "offerQuantity": 255}}'
```

##### Generate a stairstep module with a frequency switcher

```bash
builtforGen \
  -id builtfor_example_stairstep \
  -name 'Builtfor Stairstep Example' \
  -e prestabulle2 \
  --template frequency \
  -c '{"offerSelection": {"offerPricingId": "builtfor_stairstep-EUR-Monthly","offerQuantity": 1 }}'
```

#### PS 1.7, Sandbox, Prestabulle 2

##### Generate a flat fee module for PS 1.7

```bash
# With builtforGen
$ builtforGen -id builtfor_example -s -e prestabulle2 -d "PS 1.7 | Built for PS with a flat fee pricing in sandbox for prestabulle2" --psVersion "1.7"  -l 3.3.0
# Or with builtforRegistered
$ builtforRegistered -c flat_bulle2
```

##### Generate a flat fee with handle plan module for PS1.7

```bash
# With builtforGen
builtforGen -id builtfor_example -s -e prestabulle2 -d "PS 1.7 | Built for PS with a flat fee pricing in sandbox for prestabulle2" --psVersion "1.7" -t "handle" -l 3.3.0
# Or with builtforRegistered
builtforRegistered -c flat_handle_bulle2
```

##### Generate a stairstep module for PS1.7

```bash
builtforGen \
  -id builtfor_example_stairstep \
  -s \
  -e prestabulle2 \
  -d "PS 1.7 | Built for PS with a stairstep pricing in sandbox for prestabulle2" \
  --psVersion "1.7" \
  -c '{"product": {"components": [{"id": "builtfor_example_stairstep", "unitDescription": "Users" }]}}' \
   -l 3.3.0
```

### Change PHP version

#### With Homebrew

```bash
$ brew install php@{version}
$ brew link --force --overwrite php@{version}
# You should install shivammathur before https://github.com/shivammathur/homebrew-php
$ brew services start shivammathur/php/php@{version}
```

## Contribute

### Installation

```bash
yarn install
```

### Launch

```bash
# Built for classic generator
yarn start

# Built for classic generator in watch mode
yarn start:dev

# Built for registered configuration
yarn start_reg

# Built for registered configuration in watch mode
yarn start_reg:dev
```

### Build

```bash
yarn build
```