1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Srmklive\PayPal\Traits\PayPalAPI; |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
trait CatalogProducts |
7
|
|
|
{ |
8
|
|
|
/** |
9
|
|
|
* Create a product. |
10
|
|
|
* |
11
|
|
|
* @param array $data |
12
|
|
|
* @param string $request_id |
13
|
|
|
* |
14
|
|
|
* @throws \Throwable |
15
|
|
|
* |
16
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
17
|
|
|
* |
18
|
|
|
* @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_create |
19
|
|
|
*/ |
20
|
|
|
public function createProduct(array $data, $request_id) |
21
|
|
|
{ |
22
|
|
|
$this->apiEndPoint = "v1/catalogs/products"; |
|
|
|
|
23
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
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 products. |
35
|
|
|
* |
36
|
|
|
* @throws \Throwable |
37
|
|
|
* |
38
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
39
|
|
|
* |
40
|
|
|
* @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_list |
41
|
|
|
*/ |
42
|
|
|
public function listProducts() |
43
|
|
|
{ |
44
|
|
|
$this->apiEndPoint = "v1/catalogs/products"; |
|
|
|
|
45
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
46
|
|
|
|
47
|
|
|
$this->verb = 'get'; |
|
|
|
|
48
|
|
|
|
49
|
|
|
return $this->doPayPalRequest(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Update a product. |
54
|
|
|
* |
55
|
|
|
* @param array $data |
56
|
|
|
* @param string $product_id |
57
|
|
|
* |
58
|
|
|
* @throws \Throwable |
59
|
|
|
* |
60
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
61
|
|
|
* |
62
|
|
|
* @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_patch |
63
|
|
|
*/ |
64
|
|
|
public function updateProduct(array $data, $product_id) |
65
|
|
|
{ |
66
|
|
|
$this->apiEndPoint = "v1/catalogs/products/{$product_id}"; |
|
|
|
|
67
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
68
|
|
|
|
69
|
|
|
$this->options['json'] = $data; |
|
|
|
|
70
|
|
|
|
71
|
|
|
$this->verb = 'patch'; |
|
|
|
|
72
|
|
|
|
73
|
|
|
return $this->doPayPalRequest(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* Get product details. |
78
|
|
|
* |
79
|
|
|
* @param string $product_id |
80
|
|
|
* |
81
|
|
|
* @throws \Throwable |
82
|
|
|
* |
83
|
|
|
* @return array|\Psr\Http\Message\StreamInterface|string |
84
|
|
|
* |
85
|
|
|
* @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_get |
86
|
|
|
*/ |
87
|
|
|
public function showProductDetails($product_id) |
88
|
|
|
{ |
89
|
|
|
$this->apiEndPoint = "v1/catalogs/products/{$product_id}"; |
|
|
|
|
90
|
|
|
$this->apiUrl = collect([$this->apiUrl, $this->apiEndPoint])->implode('/'); |
|
|
|
|
91
|
|
|
|
92
|
|
|
$this->verb = 'get'; |
|
|
|
|
93
|
|
|
|
94
|
|
|
return $this->doPayPalRequest(); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|