Subversion-Projekte lars-tiefland.laravel_shop

Revision

Zur aktuellen Revision | Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
676 lars 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
     * @param string $request_id
12
     *
13
     * @throws \Throwable
14
     *
15
     * @return array|\Psr\Http\Message\StreamInterface|string
16
     *
17
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_create
18
     */
19
    public function createPlan(array $data, string $request_id)
20
    {
21
        $this->apiEndPoint = 'v1/billing/plans';
22
 
23
        $this->options['headers']['PayPal-Request-Id'] = $request_id;
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
     * @param int  $page
35
     * @param int  $size
36
     * @param bool $totals
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(int $page = 1, int $size = 20, bool $totals = true)
45
    {
46
        $totals = ($totals) ? 'true' : 'false';
47
 
48
        $this->apiEndPoint = "v1/billing/plans?page={$page}&page_size={$size}&total_required={$totals}";
49
 
50
        $this->verb = 'get';
51
 
52
        return $this->doPayPalRequest();
53
    }
54
 
55
    /**
56
     * Update an existing billing plan.
57
     *
58
     * @param string $plan_id
59
     * @param array  $data
60
     *
61
     * @throws \Throwable
62
     *
63
     * @return array|\Psr\Http\Message\StreamInterface|string
64
     *
65
     * @see https://developer.paypal.com/docs/api/invoicing/v2/#invoices_update
66
     */
67
    public function updatePlan(string $plan_id, array $data)
68
    {
69
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}";
70
 
71
        $this->options['json'] = $data;
72
 
73
        $this->verb = 'patch';
74
 
75
        return $this->doPayPalRequest(false);
76
    }
77
 
78
    /**
79
     * Show details for an existing billing plan.
80
     *
81
     * @param string $plan_id
82
     *
83
     * @throws \Throwable
84
     *
85
     * @return array|\Psr\Http\Message\StreamInterface|string
86
     *
87
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_get
88
     */
89
    public function showPlanDetails(string $plan_id)
90
    {
91
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}";
92
 
93
        $this->verb = 'get';
94
 
95
        return $this->doPayPalRequest();
96
    }
97
 
98
    /**
99
     * Activate an existing billing plan.
100
     *
101
     * @param string $plan_id
102
     *
103
     * @throws \Throwable
104
     *
105
     * @return array|\Psr\Http\Message\StreamInterface|string
106
     *
107
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_activate
108
     */
109
    public function activatePlan(string $plan_id)
110
    {
111
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}/activate";
112
 
113
        $this->verb = 'post';
114
 
115
        return $this->doPayPalRequest(false);
116
    }
117
 
118
    /**
119
     * Deactivate an existing billing plan.
120
     *
121
     * @param string $plan_id
122
     *
123
     * @throws \Throwable
124
     *
125
     * @return array|\Psr\Http\Message\StreamInterface|string
126
     *
127
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_deactivate
128
     */
129
    public function deactivatePlan(string $plan_id)
130
    {
131
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}/deactivate";
132
 
133
        $this->verb = 'post';
134
 
135
        return $this->doPayPalRequest(false);
136
    }
137
 
138
    /**
139
     * Update pricing for an existing billing plan.
140
     *
141
     * @param string $plan_id
142
     * @param array  $pricing
143
     *
144
     * @throws \Throwable
145
     *
146
     * @return array|\Psr\Http\Message\StreamInterface|string
147
     *
148
     * @see https://developer.paypal.com/docs/api/subscriptions/v1/#plans_update-pricing-schemes
149
     */
150
    public function updatePlanPricing(string $plan_id, array $pricing)
151
    {
152
        $this->apiEndPoint = "v1/billing/plans/{$plan_id}/update-pricing-schemes";
153
 
154
        $this->options['json'] = [
155
            'pricing_schemes' => $pricing,
156
        ];
157
 
158
        $this->verb = 'post';
159
 
160
        return $this->doPayPalRequest(false);
161
    }
162
}