Completed
Push — v2.0 ( 6a6c92...092e88 )
by Raza
13:05
created

BillingPlans::updatePlan()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
trait BillingPlans
6
{
7
    /**
8
     * Create a new billing plan.
9
     *
10
     * @param array  $data
11
     *
12
     * @throws \Throwable
13
     *
14
     * @return array|\Psr\Http\Message\StreamInterface|string
15
     *
16
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_create
17
     */
18
    public function createPlan(array $data)
19
    {
20
        $this->apiEndPoint = 'v1/billing/plans';
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
21
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
22
23
        $this->options['json'] = $data;
1 ignored issue
show
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
24
25
        $this->verb = 'post';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
26
27
        return $this->doPayPalRequest();
1 ignored issue
show
Bug introduced by
It seems like doPayPalRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        return $this->/** @scrutinizer ignore-call */ doPayPalRequest();
Loading history...
28
    }
29
30
    /**
31
     * List all billing plans.
32
     *
33
     * @param int   $page
34
     * @param int   $size
35
     * @param bool  $totals
36
     * @param array $fields
37
     *
38
     * @throws \Throwable
39
     *
40
     * @return array|\Psr\Http\Message\StreamInterface|string
41
     *
42
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list
43
     */
44
    public function listPlans($page = 1, $size = 20, $totals = true, array $fields = [])
45
    {
46
        $fields_list = collect($fields);
47
48
        $fields = '';
49
        if ($fields_list->count() > 0) {
50
            $fields = "&fields={$fields_list->implode(',')}";
51
        }
52
53
        $this->apiEndPoint = "v1/billing/plans?page={$page}&page_size={$size}&total_required={$totals}{$fields}";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
54
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
55
56
        $this->verb = 'get';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
57
58
        return $this->doPayPalRequest();
59
    }
60
61
    /**
62
     * Update an existing billing plan.
63
     *
64
     * @param string $plan_id
65
     * @param array  $data
66
     *
67
     * @throws \Throwable
68
     *
69
     * @return array|\Psr\Http\Message\StreamInterface|string
70
     *
71
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update
72
     */
73
    public function updatePlan($plan_id, array $data)
74
    {
75
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
76
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
77
78
        $this->options['json'] = $data;
1 ignored issue
show
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
79
80
        $this->verb = 'patch';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
81
82
        return $this->doPayPalRequest();
83
    }
84
85
    /**
86
     * Show details for an existing billing plan.
87
     *
88
     * @param string $plan_id
89
     *
90
     * @throws \Throwable
91
     *
92
     * @return array|\Psr\Http\Message\StreamInterface|string
93
     *
94
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_get
95
     */
96
    public function showPlanDetails($plan_id)
97
    {
98
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
99
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
100
101
        $this->verb = 'get';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
102
103
        return $this->doPayPalRequest();
104
    }
105
106
    /**
107
     * Activate an existing billing plan.
108
     *
109
     * @param string $plan_id
110
     *
111
     * @throws \Throwable
112
     *
113
     * @return array|\Psr\Http\Message\StreamInterface|string
114
     *
115
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_activate
116
     */
117
    public function activatePlan($plan_id)
118
    {
119
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}/activate";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
120
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
121
122
        $this->verb = 'post';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
123
124
        return $this->doPayPalRequest();
125
    }
126
127
    /**
128
     * Deactivate an existing billing plan.
129
     *
130
     * @param string $plan_id
131
     *
132
     * @throws \Throwable
133
     *
134
     * @return array|\Psr\Http\Message\StreamInterface|string
135
     *
136
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_deactivate
137
     */
138
    public function deactivatePlan($plan_id)
139
    {
140
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}/deactivate";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
141
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
142
143
        $this->verb = 'post';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
144
145
        return $this->doPayPalRequest();
146
    }
147
148
    /**
149
     * Update pricing for an existing billing plan.
150
     *
151
     * @param string $plan_id
152
     * @param array  $pricing
153
     *
154
     * @throws \Throwable
155
     *
156
     * @return array|\Psr\Http\Message\StreamInterface|string
157
     *
158
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_update-pricing-schemes
159
     */
160
    public function updatePlanPricing($plan_id, array $pricing)
161
    {
162
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}/update-pricing-schemes";
1 ignored issue
show
Bug Best Practice introduced by
The property apiEndPoint does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
163
        $this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/');
1 ignored issue
show
Bug Best Practice introduced by
The property apiUrl does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
164
165
        $this->options['json'] = [
1 ignored issue
show
Bug Best Practice introduced by
The property options does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
166
            "pricing_schemes" => $pricing
167
        ];
168
169
        $this->verb = 'post';
1 ignored issue
show
Bug Best Practice introduced by
The property verb does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
170
171
        return $this->doPayPalRequest();
172
    }
173
}
174