1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Srmklive\PayPal\Traits\PayPalAPI; |
4
|
|
|
|
5
|
|
|
trait Trackers |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* Adds tracking information, with or without tracking numbers, for multiple PayPal transactions. |
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/tracking/v1/#trackers-batch_post |
17
|
|
|
*/ |
18
|
|
|
public function addBatchTracking(array $data) |
19
|
|
|
{ |
20
|
|
|
$this->apiEndPoint = 'v1/shipping/trackers-batch'; |
21
|
|
|
|
22
|
|
|
$this->options['json'] = $data; |
23
|
|
|
|
24
|
|
|
$this->verb = 'post'; |
25
|
|
|
|
26
|
|
|
return $this->doPayPalRequest(); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Adds tracking information for a PayPal transaction. |
31
|
|
|
* |
32
|
|
|
* @param array $data |
33
|
|
|
* |
34
|
|
|
* @throws \Throwable |
35
|
|
|
* |
36
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
37
|
|
|
* |
38
|
|
|
* @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_post |
39
|
|
|
*/ |
40
|
|
|
public function addTracking(array $data) |
41
|
|
|
{ |
42
|
|
|
$this->apiEndPoint = 'v1/shipping/trackers'; |
43
|
|
|
|
44
|
|
|
$this->options['json'] = $data; |
45
|
|
|
|
46
|
|
|
$this->verb = 'post'; |
47
|
|
|
|
48
|
|
|
return $this->doPayPalRequest(); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* List tracking information based on Transaction ID or tracking number. |
53
|
|
|
* |
54
|
|
|
* @param string $transaction_id |
55
|
|
|
* @param string $tracking_number |
56
|
|
|
* |
57
|
|
|
* @throws \Throwable |
58
|
|
|
* |
59
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
60
|
|
|
* |
61
|
|
|
* @see https://developer.paypal.com/docs/api/tracking/v1/#trackers-batch_get |
62
|
|
|
*/ |
63
|
|
|
public function listTrackingDetails(string $transaction_id, string $tracking_number=null) |
64
|
|
|
{ |
65
|
|
|
$this->apiEndPoint = "v1/shipping/trackers?transaction_id={$transaction_id}" . !empty($tracking_number) ? "&tracking_number={$tracking_number}" : ""; |
66
|
|
|
|
67
|
|
|
$this->verb = 'get'; |
68
|
|
|
|
69
|
|
|
return $this->doPayPalRequest(); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Update tracking information. |
74
|
|
|
* |
75
|
|
|
* @param string $tracking_id |
76
|
|
|
* @param array $data |
77
|
|
|
* |
78
|
|
|
* @throws \Throwable |
79
|
|
|
* |
80
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
81
|
|
|
* |
82
|
|
|
* @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_put |
83
|
|
|
*/ |
84
|
|
|
public function updateTrackingDetails(string $tracking_id, array $data) |
85
|
|
|
{ |
86
|
|
|
$this->apiEndPoint = "v1/shipping/trackers/{$tracking_id}"; |
87
|
|
|
|
88
|
|
|
$this->options['json'] = $data; |
89
|
|
|
|
90
|
|
|
$this->verb = 'put'; |
91
|
|
|
|
92
|
|
|
return $this->doPayPalRequest(false); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Show tracking information. |
97
|
|
|
* |
98
|
|
|
* @param string $tracking_id |
99
|
|
|
* |
100
|
|
|
* @throws \Throwable |
101
|
|
|
* |
102
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
103
|
|
|
* |
104
|
|
|
* @see https://developer.paypal.com/docs/api/tracking/v1/#trackers_get |
105
|
|
|
*/ |
106
|
|
|
public function showTrackingDetails(string $tracking_id) |
107
|
|
|
{ |
108
|
|
|
$this->apiEndPoint = "v1/shipping/trackers/{$tracking_id}"; |
109
|
|
|
|
110
|
|
|
$this->verb = 'get'; |
111
|
|
|
|
112
|
|
|
return $this->doPayPalRequest(); |
113
|
|
|
} |
114
|
|
|
} |
115
|
|
|
|