How to use the @reactioncommerce/api-utils/getRateObjectForRate.js function in @reactioncommerce/api-utils

To help you get started, we’ve selected a few @reactioncommerce/api-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github reactioncommerce / reaction / imports / plugins / core / graphql / server / no-meteor / xforms / cart.js View on Github external
fulfillmentTotalMoneyObject = {
      amount: fulfillmentTotal,
      currencyCode: cart.currencyCode
    };
  }

  let taxTotalMoneyObject = null;
  let effectiveTaxRateObject = null;
  if (taxTotal !== null) {
    taxTotalMoneyObject = {
      amount: taxTotal,
      currencyCode: cart.currencyCode
    };
    if (taxSummary) {
      const effectiveTaxRate = taxSummary.tax / taxSummary.taxableAmount;
      effectiveTaxRateObject = getRateObjectForRate(effectiveTaxRate);
    }
  }

  fulfillmentGroups = fulfillmentGroups.map((fulfillmentGroup) => xformCartFulfillmentGroup(fulfillmentGroup, cart));
  fulfillmentGroups = fulfillmentGroups.filter((group) => !!group); // filter out nulls

  return {
    fulfillmentGroups,
    summary: {
      discountTotal: {
        amount: discountTotal,
        currencyCode: cart.currencyCode
      },
      effectiveTaxRate: effectiveTaxRateObject,
      fulfillmentTotal: fulfillmentTotalMoneyObject,
      itemTotal: {
github reactioncommerce / reaction / src / core-services / cart / xforms / xformCartCheckout.js View on Github external
fulfillmentTotalMoneyObject = {
      amount: fulfillmentTotal,
      currencyCode: cart.currencyCode
    };
  }

  let taxTotalMoneyObject = null;
  let effectiveTaxRateObject = null;
  if (taxTotal !== null) {
    taxTotalMoneyObject = {
      amount: taxTotal,
      currencyCode: cart.currencyCode
    };
    if (taxSummary) {
      const effectiveTaxRate = taxSummary.tax / taxSummary.taxableAmount;
      effectiveTaxRateObject = getRateObjectForRate(effectiveTaxRate);
    }
  }

  fulfillmentGroups = fulfillmentGroups.map((fulfillmentGroup) => xformCartFulfillmentGroup(fulfillmentGroup, cart));
  fulfillmentGroups = fulfillmentGroups.filter((group) => !!group); // filter out nulls

  return {
    fulfillmentGroups,
    summary: {
      discountTotal: {
        amount: discountTotal,
        currencyCode: cart.currencyCode
      },
      effectiveTaxRate: effectiveTaxRateObject,
      fulfillmentTotal: fulfillmentTotalMoneyObject,
      itemTotal: {
github reactioncommerce / reaction / imports / plugins / core / orders / server / no-meteor / resolvers / Order / orderSummary.js View on Github external
const totalShippingAmount = totalShipping.reduce((acc, value) => acc + value, 0);
  const totalSubtotalAmount = totalSubtotal.reduce((acc, value) => acc + value, 0);
  const totalSurchargesAmount = totalSurcharges.reduce((acc, value) => acc + value, 0);
  const totalTaxableAmountAmount = totalTaxableAmount.reduce((acc, value) => acc + value, 0);
  const totalTaxesAmount = totalTaxes.reduce((acc, value) => acc + value, 0);
  const totalTotalAmount = totalTotal.reduce((acc, value) => acc + value, 0);

  // Calculate effective tax rate of combined fulfillmentGroups
  const effectiveTaxRate = totalTaxableAmountAmount > 0 ? totalTaxesAmount / totalTaxableAmountAmount : 0;

  return {
    discountTotal: {
      amount: totalDiscountsAmount,
      currencyCode
    },
    effectiveTaxRate: getRateObjectForRate(effectiveTaxRate),
    fulfillmentTotal: {
      amount: totalShippingAmount,
      currencyCode
    },
    itemTotal: {
      amount: totalSubtotalAmount,
      currencyCode
    },
    surchargeTotal: {
      amount: totalSurchargesAmount,
      currencyCode
    },
    taxableAmount: {
      amount: totalTaxableAmountAmount,
      currencyCode
    },
github reactioncommerce / reaction / imports / node-app / core-services / taxes / util / graphqlGroupXform.js View on Github external
taxes: taxSummary.taxes.map((calculatedTax) => ({
        ...calculatedTax,
        tax: {
          currencyCode,
          amount: calculatedTax.tax
        },
        taxableAmount: {
          currencyCode,
          amount: calculatedTax.taxableAmount
        },
        taxRate: getRateObjectForRate(calculatedTax.taxRate)
      }))
    };
github reactioncommerce / reaction / imports / node-app / core-services / taxes / util / graphqlItemXform.js View on Github external
return orderItem.taxes.map((calculatedTax) => ({
      ...calculatedTax,
      tax: {
        currencyCode,
        amount: calculatedTax.tax
      },
      taxableAmount: {
        currencyCode,
        amount: calculatedTax.taxableAmount
      },
      taxRate: getRateObjectForRate(calculatedTax.taxRate)
    }));
  }