BillingPlans   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 150
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 7
eloc 27
c 2
b 1
f 0
dl 0
loc 150
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A createPlan() 0 9 1
A updatePlanPricing() 0 11 1
A listPlans() 0 7 1
A updatePlan() 0 9 1
A showPlanDetails() 0 7 1
A activatePlan() 0 7 1
A deactivatePlan() 0 7 1
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
trait BillingPlans
6
{
7
    use BillingPlans\PricingSchemes;
8
9
    /**
10
     * Create a new billing plan.
11
     *
12
     * @param array $data
13
     *
14
     * @throws \Throwable
15
     *
16
     * @return array|\Psr\Http\Message\StreamInterface|string
17
     *
18
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_create
19
     */
20
    public function createPlan(array $data)
21
    {
22
        $this->apiEndPoint = 'v1/billing/plans';
23
24
        $this->options['json'] = $data;
25
26
        $this->verb = 'post';
27
28
        return $this->doPayPalRequest();
29
    }
30
31
    /**
32
     * List all billing plans.
33
     *
34
     * @throws \Throwable
35
     *
36
     * @return array|\Psr\Http\Message\StreamInterface|string
37
     *
38
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_list
39
     */
40
    public function listPlans()
41
    {
42
        $this->apiEndPoint = "v1/billing/plans?page={$this->current_page}&page_size={$this->page_size}&total_required={$this->show_totals}";
43
44
        $this->verb = 'get';
45
46
        return $this->doPayPalRequest();
47
    }
48
49
    /**
50
     * Update an existing billing plan.
51
     *
52
     * @param string $plan_id
53
     * @param array  $data
54
     *
55
     * @throws \Throwable
56
     *
57
     * @return array|\Psr\Http\Message\StreamInterface|string
58
     *
59
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update
60
     */
61
    public function updatePlan(string $plan_id, array $data)
62
    {
63
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}";
64
65
        $this->options['json'] = $data;
66
67
        $this->verb = 'patch';
68
69
        return $this->doPayPalRequest(false);
70
    }
71
72
    /**
73
     * Show details for an existing billing plan.
74
     *
75
     * @param string $plan_id
76
     *
77
     * @throws \Throwable
78
     *
79
     * @return array|\Psr\Http\Message\StreamInterface|string
80
     *
81
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_get
82
     */
83
    public function showPlanDetails(string $plan_id)
84
    {
85
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}";
86
87
        $this->verb = 'get';
88
89
        return $this->doPayPalRequest();
90
    }
91
92
    /**
93
     * Activate an existing billing plan.
94
     *
95
     * @param string $plan_id
96
     *
97
     * @throws \Throwable
98
     *
99
     * @return array|\Psr\Http\Message\StreamInterface|string
100
     *
101
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_activate
102
     */
103
    public function activatePlan(string $plan_id)
104
    {
105
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}/activate";
106
107
        $this->verb = 'post';
108
109
        return $this->doPayPalRequest(false);
110
    }
111
112
    /**
113
     * Deactivate an existing billing plan.
114
     *
115
     * @param string $plan_id
116
     *
117
     * @throws \Throwable
118
     *
119
     * @return array|\Psr\Http\Message\StreamInterface|string
120
     *
121
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_deactivate
122
     */
123
    public function deactivatePlan(string $plan_id)
124
    {
125
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}/deactivate";
126
127
        $this->verb = 'post';
128
129
        return $this->doPayPalRequest(false);
130
    }
131
132
    /**
133
     * Update pricing for an existing billing plan.
134
     *
135
     * @param string $plan_id
136
     * @param array  $pricing
137
     *
138
     * @throws \Throwable
139
     *
140
     * @return array|\Psr\Http\Message\StreamInterface|string
141
     *
142
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_update-pricing-schemes
143
     */
144
    public function updatePlanPricing(string $plan_id, array $pricing)
145
    {
146
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}/update-pricing-schemes";
147
148
        $this->options['json'] = [
149
            'pricing_schemes' => $pricing,
150
        ];
151
152
        $this->verb = 'post';
153
154
        return $this->doPayPalRequest(false);
155
    }
156
}
157