|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace PaymentGateway\PayPalSdk\Plans\Requests; |
|
4
|
|
|
|
|
5
|
|
|
use PaymentGateway\PayPalSdk\Plans\Concerns\HasPlanDescription; |
|
6
|
|
|
use PaymentGateway\PayPalSdk\Plans\Concerns\HasPlanStatus; |
|
7
|
|
|
use PaymentGateway\PayPalSdk\Subscriptions\BillingCycles\BillingCycleSet; |
|
8
|
|
|
use PaymentGateway\PayPalSdk\Subscriptions\Concerns\HasPaymentPreferences; |
|
9
|
|
|
use PaymentGateway\PayPalSdk\Subscriptions\Constants\CurrencyCode; |
|
10
|
|
|
use PaymentGateway\PayPalSdk\Subscriptions\Money; |
|
11
|
|
|
use PaymentGateway\PayPalSdk\Subscriptions\PaymentPreferences; |
|
12
|
|
|
|
|
13
|
|
|
class StorePlanRequest |
|
14
|
|
|
{ |
|
15
|
|
|
use HasPlanDescription; |
|
16
|
|
|
use HasPlanStatus; |
|
17
|
|
|
use HasPaymentPreferences; |
|
18
|
|
|
|
|
19
|
|
|
protected string $productId; |
|
20
|
|
|
protected string $planName; |
|
21
|
|
|
protected string $planStatus; |
|
22
|
|
|
|
|
23
|
|
|
protected BillingCycleSet $billingCycleSet; |
|
24
|
|
|
|
|
25
|
4 |
|
public function __construct(string $productId, string $planName, BillingCycleSet $billingCycleSet) |
|
26
|
|
|
{ |
|
27
|
4 |
|
$this->productId = $productId; |
|
28
|
4 |
|
$this->planName = $planName; |
|
29
|
4 |
|
$this->billingCycleSet = $billingCycleSet; |
|
30
|
4 |
|
} |
|
31
|
|
|
|
|
32
|
1 |
|
public function getProductId(): string |
|
33
|
|
|
{ |
|
34
|
1 |
|
return $this->productId; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
1 |
|
public function setProductId(string $productId): self |
|
38
|
|
|
{ |
|
39
|
1 |
|
$this->productId = $productId; |
|
40
|
|
|
|
|
41
|
1 |
|
return $this; |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
1 |
|
public function getPlanName(): string |
|
45
|
|
|
{ |
|
46
|
1 |
|
return $this->planName; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
1 |
|
public function setPlanName(string $planName): self |
|
50
|
|
|
{ |
|
51
|
1 |
|
$this->planName = $planName; |
|
52
|
|
|
|
|
53
|
1 |
|
return $this; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function getBillingCycleSet(): BillingCycleSet |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->billingCycleSet; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
1 |
|
public function setBillingCycleSet(BillingCycleSet $billingCycleSet): self |
|
62
|
|
|
{ |
|
63
|
1 |
|
$this->billingCycleSet = $billingCycleSet; |
|
64
|
|
|
|
|
65
|
1 |
|
return $this; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
4 |
|
public function toArray(): array |
|
69
|
|
|
{ |
|
70
|
|
|
$request = [ |
|
71
|
4 |
|
'product_id' => $this->productId, |
|
72
|
4 |
|
'name' => $this->planName, |
|
73
|
|
|
]; |
|
74
|
|
|
|
|
75
|
4 |
|
if ($this->planDescription ?? null) { |
|
76
|
2 |
|
$request['description'] = $this->planDescription; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
4 |
|
if ($this->planStatus ?? null) { |
|
80
|
2 |
|
$request['status'] = $this->planStatus; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
4 |
|
$request['billing_cycles'] = $this->billingCycleSet->toArray(); |
|
84
|
|
|
|
|
85
|
4 |
|
if (!($this->paymentPreferences ?? null)) { |
|
86
|
3 |
|
$money = new Money(CurrencyCode::UNITED_STATES_DOLLAR, '0'); |
|
87
|
3 |
|
$this->paymentPreferences = new PaymentPreferences($money); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
4 |
|
$request['payment_preferences'] = $this->paymentPreferences->toArray(); |
|
91
|
|
|
|
|
92
|
4 |
|
return $request; |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|