Order::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 3
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
crap 1
1
<?php namespace Arcanedev\Stripe\Resources;
2
3
use Arcanedev\Stripe\Contracts\Resources\Order as OrderContract;
4
use Arcanedev\Stripe\StripeResource;
5
use Arcanedev\Stripe\Utilities\Util;
6
7
/**
8
 * Class     Order
9
 *
10
 * @package  Arcanedev\Stripe\Resources
11
 * @author   ARCANEDEV <[email protected]>
12
 * @link     https://stripe.com/docs/api/php#order_object
13
 *
14
 * @property  string                                   id
15
 * @property  string                                   object                    // 'order'
16
 * @property  int                                      amount
17
 * @property  string                                   application
18
 * @property  int                                      application_fee
19
 * @property  string                                   charge
20
 * @property  int                                      created                   // timestamp
21
 * @property  string                                   currency
22
 * @property  string                                   customer
23
 * @property  string                                   email
24
 * @property  string                                   external_coupon_code
25
 * @property  \Arcanedev\Stripe\Resources\OrderItem[]  items
26
 * @property  bool                                     livemode
27
 * @property  \Arcanedev\Stripe\AttachedObject         metadata
28
 * @property  string                                   selected_shipping_method
29
 * @property  array                                    shipping
30
 * @property  \Arcanedev\Stripe\Collection             shipping_methods
31
 * @property  string                                   status                    // 'paid', 'fulfilled', or 'refunded'.
32
 * @property  mixed                                    status_transitions
33
 * @property  int                                      updated                   // timestamp
34
 */
35
class Order extends StripeResource implements OrderContract
36
{
37
    /* ------------------------------------------------------------------------------------------------
38
     |  Main Functions
39
     | ------------------------------------------------------------------------------------------------
40
     */
41
    /**
42
     * List all Orders.
43
     * @link   https://stripe.com/docs/api/php#list_orders
44
     *
45
     * @param  array|null         $params
46
     * @param  array|string|null  $options
47
     *
48
     * @return \Arcanedev\Stripe\Collection|array
49
     */
50 2
    public static function all($params = [], $options = null)
51
    {
52 2
        return self::scopedAll($params, $options);
53
    }
54
55
    /**
56
     * Retrieves the details of an existing Order.
57
     * @link   https://stripe.com/docs/api/php#retrieve_order
58
     *
59
     * @param  string             $id
60
     * @param  array|string|null  $options
61
     *
62
     * @return self
63
     */
64 4
    public static function retrieve($id, $options = null)
65
    {
66 4
        return self::scopedRetrieve($id, $options);
67
    }
68
69
    /**
70
     * Create a new Order.
71
     * @link   https://stripe.com/docs/api/php#create_order
72
     *
73
     * @param  array|null         $params
74
     * @param  array|string|null  $options
75
     *
76
     * @return self
77
     */
78 12
    public static function create($params = [], $options = null)
79
    {
80 12
        return self::scopedCreate($params, $options);
81
    }
82
83
    /**
84
     * Update an Order.
85
     * @link   https://stripe.com/docs/api/php#update_order
86
     *
87
     * @param  string             $id
88
     * @param  array|null         $params
89
     * @param  array|string|null  $options
90
     *
91
     * @return self
92
     */
93 2
    public static function update($id, $params = [], $options = null)
94
    {
95 2
        return self::scopedUpdate($id, $params, $options);
96
    }
97
98
    /**
99
     * Update/Save an Order.
100
     * @link   https://stripe.com/docs/api/php#update_order
101
     *
102
     * @param  array|string|null  $options
103
     *
104
     * @return self
105
     */
106 4
    public function save($options = null)
107
    {
108 4
        return $this->scopedSave($options);
109
    }
110
111
    /**
112
     * Pay an Order.
113
     * @link   https://stripe.com/docs/api/php#pay_order
114
     *
115
     * @param  array|null         $params
116
     * @param  array|string|null  $options
117
     *
118
     * @return self
119
     */
120 4
    public function pay($params = [], $options = null)
121
    {
122 4
        list($response, $options) = $this->request(
123 4
            'post', $this->instanceUrl().'/pay', $params, $options
124
        );
125 4
        $this->refreshFrom($response, $options);
126
127 4
        return $this;
128
    }
129
130
    /**
131
     * Return an order.
132
     * @link   https://stripe.com/docs/api/php#return_order
133
     *
134
     * @param  array|null         $params
135
     * @param  array|string|null  $options
136
     *
137
     * @return \Arcanedev\Stripe\Resources\OrderReturn|array
138
     */
139 4
    public function returnOrder($params = [], $options = null)
140
    {
141 4
        list($response, $options) = $this->request(
142 4
            'post', $this->instanceUrl().'/returns', $params, $options
143
        );
144
145 4
        return Util::convertToStripeObject($response, $options);
146
    }
147
}
148