CatalogProducts   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 83
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 15
c 1
b 0
f 0
dl 0
loc 83
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A createProduct() 0 9 1
A updateProduct() 0 9 1
A listProducts() 0 7 1
A showProductDetails() 0 7 1
1
<?php
2
3
namespace Srmklive\PayPal\Traits\PayPalAPI;
4
5
trait CatalogProducts
6
{
7
    /**
8
     * Create a product.
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/catalog-products/v1/#products_create
17
     */
18
    public function createProduct(array $data)
19
    {
20
        $this->apiEndPoint = 'v1/catalogs/products';
21
22
        $this->options['json'] = $data;
23
24
        $this->verb = 'post';
25
26
        return $this->doPayPalRequest();
27
    }
28
29
    /**
30
     * List products.
31
     *
32
     * @throws \Throwable
33
     *
34
     * @return array|\Psr\Http\Message\StreamInterface|string
35
     *
36
     * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_list
37
     */
38
    public function listProducts()
39
    {
40
        $this->apiEndPoint = "v1/catalogs/products?page={$this->current_page}&page_size={$this->page_size}&total_required={$this->show_totals}";
41
42
        $this->verb = 'get';
43
44
        return $this->doPayPalRequest();
45
    }
46
47
    /**
48
     * Update a product.
49
     *
50
     * @param string $product_id
51
     * @param array  $data
52
     *
53
     * @throws \Throwable
54
     *
55
     * @return array|\Psr\Http\Message\StreamInterface|string
56
     *
57
     * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_patch
58
     */
59
    public function updateProduct(string $product_id, array $data)
60
    {
61
        $this->apiEndPoint = "v1/catalogs/products/{$product_id}";
62
63
        $this->options['json'] = $data;
64
65
        $this->verb = 'patch';
66
67
        return $this->doPayPalRequest(false);
68
    }
69
70
    /**
71
     * Get product details.
72
     *
73
     * @param string $product_id
74
     *
75
     * @throws \Throwable
76
     *
77
     * @return array|\Psr\Http\Message\StreamInterface|string
78
     *
79
     * @see https://developer.paypal.com/docs/api/catalog-products/v1/#products_get
80
     */
81
    public function showProductDetails(string $product_id)
82
    {
83
        $this->apiEndPoint = "v1/catalogs/products/{$product_id}";
84
85
        $this->verb = 'get';
86
87
        return $this->doPayPalRequest();
88
    }
89
}
90