0.4.4 • Published 8 months ago

@aptly-as/sdk-algorithm v0.4.4

Weekly downloads
-
License
-
Repository
github
Last release
8 months ago

Aptly Ecommerce SDK

Example

import { AptlyAlgorithm, AptlyOption } from '@aptly-as/types';
import { AlgorithmCalculation } from '@aptly-as/sdk-algorithm';

const option: AptlyOption = { ... };
const optionAlgorithm: AptlyAlgorithm = { ..., vat: 25, fee: 10 };
// Setup algorithm with algorithm and amount.
// option.algorithm must be populated
const algorithm = new AlgorithmCalculation(optionAlgorithm)

// Add amount calculate algorithm pipeline and fee.
algorithm.amount(option.amount)

// Check if option is on sale.
if (option.allowace) {
  algorithm.priceAllowance(option.allowance);
}
// Add 1 quantity
option.quantity(1, /* can add baseQuantity here */);

// Adds the allowance and charges if set
if (option.allowanceCharge) {
  algorithm.allowanceCharge(option.allowanceCharge);
}

// We can now finalize it and use data we want
const { 
  extensionAmount,
  extensionVatAmount,
  invoicedQuantity,
  item,
  price,
} = algorithm.finalize();

// if we want to se how these calculations are done, we can fetch the pipeline.
// This is done in reverse order so we may have a floating error.
const pipeline = algorithm.pipeline(); // VAT 25% -> FEE 10% -> NETTO ..
;
0.4.4

8 months ago

0.4.2

8 months ago

0.4.1

8 months ago

0.4.0

8 months ago

0.3.7

8 months ago

0.3.6

8 months ago

0.3.5

9 months ago

0.3.4

10 months ago

0.3.3

10 months ago

0.3.2

10 months ago

0.3.1

10 months ago

0.3.0

10 months ago