Completed
Push — master ( 8bbda0...ede634 )
by ARCANEDEV
8s
created

Order   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 1
dl 0
loc 85
ccs 0
cts 23
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A retrieve() 0 4 1
A create() 0 4 1
A save() 0 4 1
A all() 0 4 1
A pay() 0 9 1
1
<?php namespace Arcanedev\Stripe\Resources;
2
3
use Arcanedev\Stripe\Contracts\Resources\OrderInterface;
4
use Arcanedev\Stripe\StripeResource;
5
6
/**
7
 * Class     Order
8
 *
9
 * @package  Arcanedev\Stripe\Resources
10
 * @author   ARCANEDEV <[email protected]>
11
 * @link     https://stripe.com/docs/api#orders
12
 *
13
 * @property  string                            object                    // 'order'
14
 * @property  bool                              livemode
15
 * @property  int                               amount
16
 * @property  int                               created
17
 * @property  int                               updated
18
 * @property  string                            currency
19
 * @property  array                             items // todo: convert it to order_items (https://stripe.com/docs/api#order_items)
20
 * @property  \Arcanedev\Stripe\AttachedObject  metadata
21
 * @property  string                            status                    // 'paid', 'fulfilled', or 'refunded'.
22
 * @property  string                            customer
23
 * @property  string                            email
24
 * @property  string                            selected_shipping_method
25
 * @property  \Arcanedev\Stripe\Collection      shipping_methods
26
 * @property  array                             shipping
27
 */
28
class Order extends StripeResource implements OrderInterface
29
{
30
    /* ------------------------------------------------------------------------------------------------
31
     |  Main Functions
32
     | ------------------------------------------------------------------------------------------------
33
     */
34
    /**
35
     * Retrieves the details of an existing order.
36
     *
37
     * @link   https://stripe.com/docs/api#retrieve_order
38
     *
39
     * @param  string             $id
40
     * @param  array|string|null  $options
41
     *
42
     * @return self
43
     */
44
    public static function retrieve($id, $options = null)
45
    {
46
        return self::scopedRetrieve($id, $options);
47
    }
48
49
    /**
50
     * Creates a new order object.
51
     *
52
     * @link   https://stripe.com/docs/api#create_order
53
     *
54
     * @param  array|null         $params
55
     * @param  array|string|null  $options
56
     *
57
     * @return self
58
     */
59
    public static function create($params = null, $options = null)
60
    {
61
        return self::scopedCreate($params, $options);
62
    }
63
64
    /**
65
     * Update an order.
66
     *
67
     * @link   https://stripe.com/docs/api#update_order
68
     *
69
     * @param  array|string|null  $options
70
     *
71
     * @return self
72
     */
73
    public function save($options = null)
74
    {
75
        return $this->scopedSave($options);
76
    }
77
78
    /**
79
     * List all orders.
80
     *
81
     * @link   https://stripe.com/docs/api#list_orders
82
     *
83
     * @param  array|null         $params
84
     * @param  array|string|null  $options
85
     *
86
     * @return \Arcanedev\Stripe\Collection|array
87
     */
88
    public static function all($params = null, $options = null)
89
    {
90
        return self::scopedAll($params, $options);
91
    }
92
93
    /**
94
     * Pay an order.
95
     *
96
     * @link   https://stripe.com/docs/api#pay_order
97
     *
98
     * @param  array|null         $params
99
     * @param  array|string|null  $options
100
     *
101
     * @return self
102
     */
103
    public function pay($params = null, $options = null)
104
    {
105
        $url = $this->instanceUrl() . '/pay';
106
107
        list($response, $options) = $this->request('post', $url, $params, $options);
108
        $this->refreshFrom($response, $options);
109
110
        return $this;
111
    }
112
}
113