bubb/installments

分期付款助手

dev-master 2017-03-22 19:48 UTC

This package is auto-updated.

Last update: 2024-09-09 13:44:50 UTC


README

installment 是由 BUBB.STORE 平台的开发者创建的一个官方库,用于处理分期付款的计算。

系统要求

它需要以下组件才能正确工作。

Composer 设置

在你的 composer.json 文件中,包含以下内容

{
    "require": {
        "bubb/installments": "master"
    }
}

使用方法

示例 #1

要计算订单可能的分期付款,例如

订单总价:200 BRL订单最大分期数:3

$installment = new Installment;
// Required.
$installment->setAmount(200);
// Required.
$installment->setTaxes([
    // installment 1: no tax, no discount.
    ['installment' => 1, 'percent_discount' => 0, 'tax' => 0],
    // installment 2: no tax, no discount.
    ['installment' => 2, 'percent_discount' => 0, 'tax' => 0],
    // installment 3: no tax, no discount.
    ['installment' => 3, 'percent_discount' => 0, 'tax' => 0],
]);
exit(var_dump($installment->get()));

其输出将是

{  
   "max_installment":3,
   "max_installment_value":66.67,
   "amount":200,
   "text":"3x de R$ 66,67 sem juros",
   "text_with_tax":"3x de R$ 66,67",
   "text_discount_percent":null,
   "text_discount":null,
   "installments":[  
      {  
         "amount":200,
         "amount_formated":"R$ 200,00",
         "base_value":200,
         "tax":0,
         "tax_value":0,
         "discount_percent":0,
         "discount_value":0,
         "discount_value_formated":"R$ 0,00",
         "installment":1,
         "installment_value":200,
         "installment_value_formated":"R$ 200,00",
         "text":"1x de R$ 200,00 sem juros",
         "text_with_tax":"1x de R$ 200,00",
         "text_discount_percent":null,
         "text_discount":null
      },
      {  
         "amount":200,
         "amount_formated":"R$ 200,00",
         "base_value":200,
         "tax":0,
         "tax_value":0,
         "discount_percent":0,
         "discount_value":0,
         "discount_value_formated":"R$ 0,00",
         "installment":2,
         "installment_value":100,
         "installment_value_formated":"R$ 100,00",
         "text":"2x de R$ 100,00 sem juros",
         "text_with_tax":"2x de R$ 100,00",
         "text_discount_percent":null,
         "text_discount":null
      },
      {  
         "amount":200,
         "amount_formated":"R$ 200,00",
         "base_value":200,
         "tax":0,
         "tax_value":0,
         "discount_percent":0,
         "discount_value":0,
         "discount_value_formated":"R$ 0,00",
         "installment":3,
         "installment_value":66.67,
         "installment_value_formated":"R$ 66,67",
         "text":"3x de R$ 66,67 sem juros",
         "text_with_tax":"3x de R$ 66,67",
         "text_discount_percent":null,
         "text_discount":null
      }
   ]
}
示例 #2

要计算订单可能的分期付款,例如

订单总价:677 BRL订单最大分期数:12(最多6期,不含税) 订单最小分期金额:20 BRL

$installment = new Installment;
// Required.
$installment->setAmount(200);
// Required.
$installment->setTaxes([
    // installment 1: no tax, 10% discount.
    ['installment' => 1, 'percent_discount' => 10, 'tax' => 0],
    // Installment 2: no tax, no discount.
    ['installment' => 2, 'percent_discount' => 0, 'tax' => 0],
    // Installment 3: no tax, no discount.
    ['installment' => 3, 'percent_discount' => 0, 'tax' => 0],
    // Installment 4: no tax, no discount.
    ['installment' => 4, 'percent_discount' => 0, 'tax' => 0],
    // Installment 5: no tax, no discount.
    ['installment' => 5, 'percent_discount' => 0, 'tax' => 0],
    // Installment 6: no tax, no discount.
    ['installment' => 6, 'percent_discount' => 0, 'tax' => 0],
    // Installment 7: tax 1.99% month, no discount.
    ['installment' => 7, 'percent_discount' => 0, 'tax' => 1.99],
    // Installment 8: tax 1.99% month, no discount.
    ['installment' => 8, 'percent_discount' => 0, 'tax' => 1.99],
    // Installment 9: tax 1.99% month, no discount.
    ['installment' => 9, 'percent_discount' => 0, 'tax' => 1.99],
    // Installment 10: tax 1.99% month, no discount.
    ['installment' => 10, 'percent_discount' => 0, 'tax' => 1.99],
    // Installment 11: no tax, no discount.
    ['installment' => 11, 'percent_discount' => 0, 'tax' => 1.99],
    // Installment 12: tax 1.99% month, no discount.
    ['installment' => 12, 'percent_discount' => 0, 'tax' => 1.99]
]);
$installment->setMinInstallmentValue(20);
$installment->setMaxInstallmentsWithoutTax(6);
exit(var_dump($installment->get()));

其输出将是

{
   // Max installments is 11 because the library popped the last installment for it had a value lower than the min. installment value (20 BRL).
   "max_installment":11,
   "max_installment_value":20.06,
   "amount":220.71,
   "text":"11x de R$ 20,06 com juros",
   "text_with_tax":"11x de R$ 20,06",
   "text_discount_percent":"10% de desconto \u00e0 vista no cart\u00e3o",
   "text_discount":"R$ 180,00 \u00e0 vista no cart\u00e3o",
   "installments":[  
      {
         // Discounted amount for the first installment.  
         "amount":180,
         "amount_formated":"R$ 180,00",
         "base_value":200,
         "tax":0,
         "tax_value":-20,
         "discount_percent":10,
         "discount_value":20,
         "discount_value_formated":"R$ 20,00",
         "installment":1,
         "installment_value":180,
         "installment_value_formated":"R$ 180,00",
         "text":"1x de R$ 180,00 sem juros",
         "text_with_tax":"1x de R$ 180,00",
         "text_discount_percent":"10% de desconto \u00e0 vista no cart\u00e3o",
         "text_discount":"R$ 180,00 \u00e0 vista no cart\u00e3o"
      },
      {  
         "amount":200,
         "amount_formated":"R$ 200,00",
         "base_value":200,
         "tax":0,
         "tax_value":0,
         "discount_percent":0,
         "discount_value":0,
         "discount_value_formated":"R$ 0,00",
         "installment":2,
         "installment_value":100,
         "installment_value_formated":"R$ 100,00",
         "text":"2x de R$ 100,00 sem juros",
         "text_with_tax":"2x de R$ 100,00",
         "text_discount_percent":null,
         "text_discount":null
      },
      {  
         "amount":200,
         "amount_formated":"R$ 200,00",
         "base_value":200,
         "tax":0,
         "tax_value":0,
         "discount_percent":0,
         "discount_value":0,
         "discount_value_formated":"R$ 0,00",
         "installment":3,
         "installment_value":66.67,
         "installment_value_formated":"R$ 66,67",
         "text":"3x de R$ 66,67 sem juros",
         "text_with_tax":"3x de R$ 66,67",
         "text_discount_percent":null,
         "text_discount":null
      },
      {  
         "amount":200,
         "amount_formated":"R$ 200,00",
         "base_value":200,
         "tax":0,
         "tax_value":0,
         "discount_percent":0,
         "discount_value":0,
         "discount_value_formated":"R$ 0,00",
         "installment":4,
         "installment_value":50,
         "installment_value_formated":"R$ 50,00",
         "text":"4x de R$ 50,00 sem juros",
         "text_with_tax":"4x de R$ 50,00",
         "text_discount_percent":null,
         "text_discount":null
      },
      {  
         "amount":200,
         "amount_formated":"R$ 200,00",
         "base_value":200,
         "tax":0,
         "tax_value":0,
         "discount_percent":0,
         "discount_value":0,
         "discount_value_formated":"R$ 0,00",
         "installment":5,
         "installment_value":40,
         "installment_value_formated":"R$ 40,00",
         "text":"5x de R$ 40,00 sem juros",
         "text_with_tax":"5x de R$ 40,00",
         "text_discount_percent":null,
         "text_discount":null
      },
      {  
         "amount":200,
         "amount_formated":"R$ 200,00",
         "base_value":200,
         "tax":0,
         "tax_value":0,
         "discount_percent":0,
         "discount_value":0,
         "discount_value_formated":"R$ 0,00",
         "installment":6,
         "installment_value":33.33,
         "installment_value_formated":"R$ 33,33",
         "text":"6x de R$ 33,33 sem juros",
         "text_with_tax":"6x de R$ 33,33",
         "text_discount_percent":null,
         "text_discount":null
      },
      {
         // Amount with taxes.  
         "amount":203.98,
         "amount_formated":"R$ 203,98",
         "base_value":200,
         "tax":1.99,
         "tax_value":3.98,
         "discount_percent":0,
         "discount_value":-3.98,
         "discount_value_formated":"R$ -3,98",
         "installment":7,
         "installment_value":29.14,
         "installment_value_formated":"R$ 29,14",
         "text":"7x de R$ 29,14 com juros",
         "text_with_tax":"7x de R$ 29,14",
         "text_discount_percent":null,
         "text_discount":null
      },
      {  
         // Amount with taxes.
         "amount":208.04,
         "amount_formated":"R$ 208,04",
         "base_value":200,
         "tax":1.99,
         "tax_value":8.039202,
         "discount_percent":0,
         "discount_value":-8.04,
         "discount_value_formated":"R$ -8,04",
         "installment":8,
         "installment_value":26,
         "installment_value_formated":"R$ 26,00",
         "text":"8x de R$ 26,00 com juros",
         "text_with_tax":"8x de R$ 26,00",
         "text_discount_percent":null,
         "text_discount":null
      },
      {
         // Amount with taxes. 
         "amount":212.18,
         "amount_formated":"R$ 212,18",
         "base_value":200,
         "tax":1.99,
         "tax_value":12.1791821198,
         "discount_percent":0,
         "discount_value":-12.18,
         "discount_value_formated":"R$ -12,18",
         "installment":9,
         "installment_value":23.58,
         "installment_value_formated":"R$ 23,58",
         "text":"9x de R$ 23,58 com juros",
         "text_with_tax":"9x de R$ 23,58",
         "text_discount_percent":null,
         "text_discount":null
      },
      {
         // Amount with taxes. 
         "amount":216.4,
         "amount_formated":"R$ 216,40",
         "base_value":200,
         "tax":1.99,
         "tax_value":16.401547844,
         "discount_percent":0,
         "discount_value":-16.4,
         "discount_value_formated":"R$ -16,40",
         "installment":10,
         "installment_value":21.64,
         "installment_value_formated":"R$ 21,64",
         "text":"10x de R$ 21,64 com juros",
         "text_with_tax":"10x de R$ 21,64",
         "text_discount_percent":null,
         "text_discount":null
      },
      {
         // Amount with taxes.   
         "amount":220.71,
         "amount_formated":"R$ 220,71",
         "base_value":200,
         "tax":1.99,
         "tax_value":20.7079386461,
         "discount_percent":0,
         "discount_value":-20.71,
         "discount_value_formated":"R$ -20,71",
         "installment":11,
         "installment_value":20.06,
         "installment_value_formated":"R$ 20,06",
         "text":"11x de R$ 20,06 com juros",
         "text_with_tax":"11x de R$ 20,06",
         "text_discount_percent":null,
         "text_discount":null
      }
   ]
}