Subversion-Projekte lars-tiefland.laravel_shop

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 Orders
6
{
7
    /**
8
     * Creates an order.
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/orders/v2/#orders_create
17
     */
18
    public function createOrder(array $data)
19
    {
20
        $this->apiEndPoint = 'v2/checkout/orders';
21
 
22
        $this->options['json'] = (object) $data;
23
 
24
        $this->verb = 'post';
25
 
26
        return $this->doPayPalRequest();
27
    }
28
 
29
    public function updateOrder(string $order_id, array $data)
30
    {
31
        $this->apiEndPoint = "v2/checkout/orders/{$order_id}";
32
 
33
        $this->options['json'] = $data;
34
 
35
        $this->verb = 'patch';
36
 
37
        return $this->doPayPalRequest(false);
38
    }
39
 
40
    /**
41
     * Shows details for an order.
42
     *
43
     * @param string $order_id
44
     *
45
     * @throws \Throwable
46
     *
47
     * @return array|\Psr\Http\Message\StreamInterface|string
48
     *
49
     * @see https://developer.paypal.com/docs/api/orders/v2/#orders_get
50
     */
51
    public function showOrderDetails(string $order_id)
52
    {
53
        $this->apiEndPoint = "v2/checkout/orders/{$order_id}";
54
 
55
        $this->verb = 'get';
56
 
57
        return $this->doPayPalRequest();
58
    }
59
 
60
    /**
61
     * Authorizes payment for an order.
62
     *
63
     * @param string $order_id
64
     * @param array  $data
65
     *
66
     * @throws \Throwable
67
     *
68
     * @return array|\Psr\Http\Message\StreamInterface|string
69
     *
70
     * @see https://developer.paypal.com/docs/api/orders/v2/#orders_authorize
71
     */
72
    public function authorizePaymentOrder(string $order_id, array $data = [])
73
    {
74
        $this->apiEndPoint = "v2/checkout/orders/{$order_id}/authorize";
75
 
76
        $this->options['json'] = (object) $data;
77
 
78
        $this->verb = 'post';
79
 
80
        return $this->doPayPalRequest();
81
    }
82
 
83
    /**
84
     * Captures payment for an order.
85
     *
86
     * @param string $order_id
87
     * @param array  $data
88
     *
89
     * @throws \Throwable
90
     *
91
     * @return array|\Psr\Http\Message\StreamInterface|string
92
     *
93
     * @see https://developer.paypal.com/docs/api/orders/v2/#orders_capture
94
     */
95
    public function capturePaymentOrder(string $order_id, array $data = [])
96
    {
97
        $this->apiEndPoint = "v2/checkout/orders/{$order_id}/capture";
98
 
99
        $this->options['json'] = (object) $data;
100
 
101
        $this->verb = 'post';
102
 
103
        return $this->doPayPalRequest();
104
    }
105
}