Better Payment 0.11.1 API
    Preparing search index...

    Function buildBasket

    • Builds a basket whose item prices add up to the payment total to the kuruş, which iyzico requires. Spreads the discount over the items in proportion to their totals, giving rounding leftovers to the items with the largest remainders (ties go to the larger item, then the earlier one), and adds shipping as an item. All arithmetic is done in minor units.

      Throws ValidationError for non-positive prices, an invalid quantity or percent, a discount that is not smaller than the item total, or a discount that would bring an item down to zero.

      Parameters

      Returns BuiltBasket

      const { basketItems, price } = buildBasket({
      items: [{ id: 'A', name: 'T-shirt', category1: 'Clothing', itemType: 'PHYSICAL', price: '49.90', quantity: 2 }],
      discount: { percent: 10 },
      shipping: { price: '29.90' },
      });