Completed
Push — master ( 3d5bef...f3346b )
by Marcel
21:54 queued 11:55
created

BillableWithinTheEU::taxPercentage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Mpociot\VatCalculator\Traits;
4
5
use Mpociot\VatCalculator\Facades\VatCalculator;
6
7
trait BillableWithinTheEU
8
{
9
    /**
10
     * @var int
11
     */
12
    protected $stripeTaxPercent = 0;
13
14
    /**
15
     * @var
16
     */
17
    protected $userCountryCode;
18
19
    /**
20
     * @var bool
21
     */
22
    protected $userIsCompany = false;
23
24
    /**
25
     * @param string     $countryCode
26
     * @param bool|false $company
27
     *
28
     * @return $this
29
     */
30
    public function setTaxForCountry($countryCode, $company = false)
31
    {
32
        $this->userCountryCode = $countryCode;
33
        $this->userIsCompany = $company;
34
35
        return $this;
36
    }
37
38
    /**
39
     * @param $countryCode
40
     *
41
     * @return $this
42
     */
43
    public function useTaxFrom($countryCode)
44
    {
45
        $this->userCountryCode = $countryCode;
46
47
        return $this;
48
    }
49
50
    /**
51
     * @return $this
52
     */
53
    public function asBusiness()
54
    {
55
        $this->userIsCompany = true;
56
57
        return $this;
58
    }
59
60
    /**
61
     * @return $this
62
     */
63
    public function asIndividual()
64
    {
65
        $this->userIsCompany = false;
66
67
        return $this;
68
    }
69
70
    /**
71
     * Get the tax percentage to apply to the subscription.
72
     *
73
     * @return int
74
     */
75
    public function getTaxPercent()
76
    {
77
        return VatCalculator::getTaxRateForCountry($this->userCountryCode, $this->userIsCompany) * 100;
78
    }
79
80
    /**
81
     * Get the tax percentage to apply to the subscription for Cashier > 6.0.
82
     *
83
     * @return int
84
     */
85
    public function taxPercentage()
86
    {
87
        return $this->getTaxPercent();
88
    }
89
}
90