Passed
Push — feature/billing-plans ( ede562 )
by Darío
07:23
created

StorePlanRequest::getBillingCycleSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
namespace PaymentGateway\PayPalSdk\Requests;
4
5
use PaymentGateway\PayPalSdk\Requests\Concerns\HasDescription;
6
use PaymentGateway\PayPalSdk\Requests\Concerns\HasPlanStatus;
7
use PaymentGateway\PayPalSdk\Subscriptions\BillingCycles\BillingCycleSet;
8
use PaymentGateway\PayPalSdk\Subscriptions\Constants\CurrencyCode;
9
use PaymentGateway\PayPalSdk\Subscriptions\Money;
10
use PaymentGateway\PayPalSdk\Subscriptions\PaymentPreferences;
11
12
class StorePlanRequest
13
{
14
    use HasDescription;
15
    use HasPlanStatus;
16
17
    protected string $productId;
18
    protected string $name;
19
20
    protected BillingCycleSet $billingCycleSet;
21
22
    protected PaymentPreferences $paymentPreferences;
23
24 3
    public function __construct(string $productId, string $name, BillingCycleSet $billingCycleSet)
25
    {
26 3
        $this->productId = $productId;
27 3
        $this->name = $name;
28 3
        $this->billingCycleSet = $billingCycleSet;
29 3
    }
30
31
    /**
32
     * @return string
33
     */
34
    public function getProductId(): string
35
    {
36
        return $this->productId;
37
    }
38
39
    public function setProductId(string $productId): self
40
    {
41
        $this->productId = $productId;
42
43
        return $this;
44
    }
45
46
    public function getName(): string
47
    {
48
        return $this->name;
49
    }
50
51
    public function setName(string $name): self
52
    {
53
        $this->name = $name;
54
55
        return $this;
56
    }
57
58
    public function getBillingCycleSet(): BillingCycleSet
59
    {
60
        return $this->billingCycleSet;
61
    }
62
63
    public function setBillingCycleSet(BillingCycleSet $billingCycleSet): self
64
    {
65
        $this->billingCycleSet = $billingCycleSet;
66
67
        return $this;
68
    }
69
70
    public function getPaymentPreferences(): PaymentPreferences
71
    {
72
        return $this->paymentPreferences;
73
    }
74
75
    public function setPaymentPreferences(PaymentPreferences $paymentPreferences): self
76
    {
77
        $this->paymentPreferences = $paymentPreferences;
78
79
        return $this;
80
    }
81
82 3
    public function toArray(): array
83
    {
84
        $request = [
85 3
            'product_id' => $this->productId,
86 3
            'name' => $this->name,
87 3
            'billing_cycles' => $this->billingCycleSet->toArray()
88
        ];
89
90 3
        if ($this->description ?? null) {
91
            $request['description'] = $this->description;
92
        }
93
94 3
        if ($this->planStatus ?? null) {
95
            $request['status'] = $this->planStatus;
96
        }
97
98 3
        if (!($this->paymentPreferences ?? null)) {
99 3
            $money = new Money(CurrencyCode::UNITED_STATES_DOLLAR, '0');
100 3
            $this->paymentPreferences = new PaymentPreferences($money);
101
        }
102
103 3
        $request['payment_preferences'] = $this->paymentPreferences->toArray();
104
105 3
        return $request;
106
    }
107
}
108