Passed
Push — v3.0 ( bac5d5...2d99c7 )
by Raza
01:59
created

Orders   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 134
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 6
eloc 25
c 2
b 1
f 0
dl 0
loc 134
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A createOrder() 0 9 1
A confirmOrder() 0 9 1
A capturePaymentOrder() 0 9 1
A authorizePaymentOrder() 0 9 1
A updateOrder() 0 9 1
A showOrderDetails() 0 7 1
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
trait Orders
6
{
7
    use Orders\Helpers;
8
9
    /**
10
     * Creates an order.
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/orders/v2/#orders_create
19
     */
20
    public function createOrder(array $data)
21
    {
22
        $this->apiEndPoint = 'v2/checkout/orders';
23
24
        $this->options['json'] = (object) $data;
25
26
        $this->verb = 'post';
27
28
        return $this->doPayPalRequest();
29
    }
30
31
    /**
32
     * Shows details for an order.
33
     *
34
     * @param string $order_id
35
     *
36
     * @throws \Throwable
37
     *
38
     * @return array|\Psr\Http\Message\StreamInterface|string
39
     *
40
     * @see https://developer.paypal.com/docs/api/orders/v2/#orders_get
41
     */
42
    public function showOrderDetails(string $order_id)
43
    {
44
        $this->apiEndPoint = "v2/checkout/orders/{$order_id}";
45
46
        $this->verb = 'get';
47
48
        return $this->doPayPalRequest();
49
    }
50
51
    /**
52
     * Update order details.
53
     *
54
     * @param string $order_id
55
     * @param array  $data
56
     *
57
     * @throws \Throwable
58
     *
59
     * @return array|\Psr\Http\Message\StreamInterface|string
60
     *
61
     * @see https://developer.paypal.com/docs/api/orders/v2/#orders_patch
62
     */
63
    public function updateOrder(string $order_id, array $data)
64
    {
65
        $this->apiEndPoint = "v2/checkout/orders/{$order_id}";
66
67
        $this->options['json'] = $data;
68
69
        $this->verb = 'patch';
70
71
        return $this->doPayPalRequest(false);
72
    }
73
74
    /**
75
     * Confirm the order.
76
     *
77
     * @param string $order_id
78
     * @param array  $data
79
     *
80
     * @throws \Throwable
81
     *
82
     * @return array|\Psr\Http\Message\StreamInterface|string
83
     */
84
    public function confirmOrder(string $order_id, array $data)
85
    {
86
        $this->apiEndPoint = "v2/checkout/orders/{$order_id}/confirm-payment-source";
87
88
        $this->options['json'] = (object) $data;
89
90
        $this->verb = 'post';
91
92
        return $this->doPayPalRequest();
93
    }
94
95
    /**
96
     * Authorizes payment for an order.
97
     *
98
     * @param string $order_id
99
     * @param array  $data
100
     *
101
     * @throws \Throwable
102
     *
103
     * @return array|\Psr\Http\Message\StreamInterface|string
104
     *
105
     * @see https://developer.paypal.com/docs/api/orders/v2/#orders_authorize
106
     */
107
    public function authorizePaymentOrder(string $order_id, array $data = [])
108
    {
109
        $this->apiEndPoint = "v2/checkout/orders/{$order_id}/authorize";
110
111
        $this->options['json'] = (object) $data;
112
113
        $this->verb = 'post';
114
115
        return $this->doPayPalRequest();
116
    }
117
118
    /**
119
     * Captures payment for an order.
120
     *
121
     * @param string $order_id
122
     * @param array  $data
123
     *
124
     * @throws \Throwable
125
     *
126
     * @return array|\Psr\Http\Message\StreamInterface|string
127
     *
128
     * @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
129
     */
130
    public function capturePaymentOrder(string $order_id, array $data = [])
131
    {
132
        $this->apiEndPoint = "v2/checkout/orders/{$order_id}/capture";
133
134
        $this->options['json'] = (object) $data;
135
136
        $this->verb = 'post';
137
138
        return $this->doPayPalRequest();
139
    }
140
}
141