Subversion-Projekte lars-tiefland.laravel_shop

Revision

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