Completed
Pull Request — master (#15)
by ARCANEDEV
11:13
created

Order::create()   A

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 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 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/php#order_object
12
 *
13
 * @property  string                                   id
14
 * @property  string                                   object                    // 'order'
15
 * @property  int                                      amount
16
 * @property  string                                   application
17
 * @property  int                                      application_fee
18
 * @property  string                                   charge
19
 * @property  int                                      created                   // timestamp
20
 * @property  string                                   currency
21
 * @property  string                                   customer
22
 * @property  string                                   email
23
 * @property  string                                   external_coupon_code
24
 * @property  \Arcanedev\Stripe\Resources\OrderItem[]  items
25
 * @property  bool                                     livemode
26
 * @property  \Arcanedev\Stripe\AttachedObject         metadata
27
 * @property  string                                   selected_shipping_method
28
 * @property  array                                    shipping
29
 * @property  \Arcanedev\Stripe\Collection             shipping_methods
30
 * @property  string                                   status                    // 'paid', 'fulfilled', or 'refunded'.
31
 * @property  mixed                                    status_transitions
32
 * @property  int                                      updated                   // timestamp
33
 */
34
class Order extends StripeResource implements OrderInterface
35
{
36
    /* ------------------------------------------------------------------------------------------------
37
     |  Main Functions
38
     | ------------------------------------------------------------------------------------------------
39
     */
40
    /**
41
     * Retrieves the details of an existing Order.
42
     * @link   https://stripe.com/docs/api/php#retrieve_order
43
     *
44
     * @param  string             $id
45
     * @param  array|string|null  $options
46
     *
47
     * @return self
48
     */
49 5
    public static function retrieve($id, $options = null)
50
    {
51 5
        return self::scopedRetrieve($id, $options);
52
    }
53
54
    /**
55
     * Create a new Order.
56
     * @link   https://stripe.com/docs/api/php#create_order
57
     *
58
     * @param  array|null         $params
59
     * @param  array|string|null  $options
60
     *
61
     * @return self
62
     */
63 20
    public static function create($params = null, $options = null)
64
    {
65 20
        return self::scopedCreate($params, $options);
66
    }
67
68
    /**
69
     * Update an Order.
70
     * @link   https://stripe.com/docs/api/php#update_order
71
     *
72
     * @param  array|string|null  $options
73
     *
74
     * @return self
75
     */
76 5
    public function save($options = null)
77
    {
78 5
        return $this->scopedSave($options);
79
    }
80
81
    /**
82
     * List all Orders.
83
     * @link   https://stripe.com/docs/api/php#list_orders
84
     *
85
     * @param  array|null         $params
86
     * @param  array|string|null  $options
87
     *
88
     * @return \Arcanedev\Stripe\Collection|array
89
     */
90
    public static function all($params = null, $options = null)
91
    {
92
        return self::scopedAll($params, $options);
93
    }
94
95
    /**
96
     * Pay an Order.
97
     * @link   https://stripe.com/docs/api/php#pay_order
98
     *
99
     * @param  array|null         $params
100
     * @param  array|string|null  $options
101
     *
102
     * @return self
103
     */
104 5
    public function pay($params = null, $options = null)
105
    {
106 5
        list($response, $options) = $this->request(
107 5
            'post', $this->instanceUrl() . '/pay', $params, $options
108 4
        );
109 5
        $this->refreshFrom($response, $options);
110
111 5
        return $this;
112
    }
113
}
114