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

Invoice   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 107
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 10.53%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 6
c 4
b 0
f 0
lcom 1
cbo 3
dl 0
loc 107
ccs 2
cts 19
cp 0.1053
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 1
A create() 0 4 1
A retrieve() 0 4 1
A save() 0 4 1
A upcoming() 0 12 1
A pay() 0 9 1
1
<?php namespace Arcanedev\Stripe\Resources;
2
3
use Arcanedev\Stripe\Contracts\Resources\InvoiceInterface;
4
use Arcanedev\Stripe\StripeResource;
5
use Arcanedev\Stripe\Utilities\Util;
6
7
/**
8
 * Class     Invoice
9
 *
10
 * @package  Arcanedev\Stripe\Resources
11
 * @author   ARCANEDEV <[email protected]>
12
 *
13
 * @link https://stripe.com/docs/api/php#invoices
14
 *
15
 * @property  string                            id
16
 * @property  string                            object // "invoice"
17
 * @property  bool                              livemode
18
 * @property  int                               amount_due
19
 * @property  int                               attempt_count
20
 * @property  bool                              attempted
21
 * @property  bool                              closed
22
 * @property  string                            currency
23
 * @property  string                            customer
24
 * @property  int                               date
25
 * @property  bool                              forgiven
26
 * @property  \Arcanedev\Stripe\Collection      lines
27
 * @property  bool                              paid
28
 * @property  int                               period_end
29
 * @property  int                               period_start
30
 * @property  int                               starting_balance
31
 * @property  int                               subtotal
32
 * @property  int                               total
33
 * @property  int                               application_fee
34
 * @property  string                            charge
35
 * @property  string                            description
36
 * @property  \Arcanedev\Stripe\StripeObject    discount              // Discount Object
37
 * @property  int                               ending_balance
38
 * @property  int                               next_payment_attempt
39
 * @property  string                            receipt_number
40
 * @property  string                            statement_descriptor
41
 * @property  string                            subscription
42
 * @property  int                               webhooks_delivered_at
43
 * @property  \Arcanedev\Stripe\AttachedObject  metadata
44
 * @property  int                               tax
45
 * @property  float                             tax_percent
46
 *
47
 * @todo:     Update the properties.
48
 */
49
class Invoice extends StripeResource implements InvoiceInterface
50
{
51
    /* ------------------------------------------------------------------------------------------------
52
     |  CRUD Functions
53
     | ------------------------------------------------------------------------------------------------
54
     */
55
    /**
56
     * Create an invoice.
57
     *
58
     * @link   https://stripe.com/docs/api/php#create_invoice
59
     *
60
     * @param  array|null         $params
61
     * @param  array|string|null  $options
62
     *
63
     * @return self|array
64
     */
65
    public static function create($params = [], $options = null)
66
    {
67
        return self::scopedCreate($params, $options);
68
    }
69
70
    /**
71
     * Retrieving an Invoice
72
     *
73
     * @link   https://stripe.com/docs/api/php#retrieve_invoice
74
     *
75
     * @param  string             $id
76
     * @param  array|string|null  $options
77
     *
78
     * @return self
79
     */
80
    public static function retrieve($id, $options = null)
81
    {
82
        return self::scopedRetrieve($id, $options);
83
    }
84
85
    /**
86
     * List of all Invoices.
87
     *
88
     * @link   https://stripe.com/docs/api/php#list_customer_invoices
89
     *
90
     * @param  array|null         $params
91
     * @param  array|string|null  $options
92
     *
93
     * @return \Arcanedev\Stripe\Collection|array
94
     */
95 5
    public static function all($params = [], $options = null)
96
    {
97 5
        return self::scopedAll($params, $options);
98
    }
99
100
    /**
101
     * Update/Save an invoice.
102
     *
103
     * @link   https://stripe.com/docs/api/php#update_invoice
104
     *
105
     * @param  array|string|null  $options
106
     *
107
     * @return self
108
     */
109
    public function save($options = null)
110
    {
111
        return self::scopedSave($options);
112
    }
113
114
    /**
115
     * Retrieve Upcoming Invoice.
116
     *
117
     * @link   https://stripe.com/docs/api/php#retrieve_customer_invoice
118
     *
119
     * @param  array|null         $params
120
     * @param  array|string|null  $options
121
     *
122
     * @return self|array
123
     */
124
    public static function upcoming($params = [], $options = null)
125
    {
126
        $url  = self::classUrl(get_class()) . '/upcoming';
127
128
        /** @var \Arcanedev\Stripe\Http\Response $response */
129
        list($response, $opts) = self::staticRequest('get', $url, $params, $options);
130
131
        $object = Util::convertToStripeObject($response->getJson(), $opts);
0 ignored issues
show
Bug Compatibility introduced by
The expression \Arcanedev\Stripe\Utilit...nse->getJson(), $opts); of type array|Arcanedev\Stripe\StripeObject adds the type Arcanedev\Stripe\StripeObject to the return on line 134 which is incompatible with the return type declared by the interface Arcanedev\Stripe\Contrac...oiceInterface::upcoming of type Arcanedev\Stripe\Contrac...\InvoiceInterface|array.
Loading history...
132
        $object->setLastResponse($response);
133
134
        return $object;
135
    }
136
137
    /**
138
     * Pay an invoice.
139
     *
140
     * @link   https://stripe.com/docs/api/php#pay_invoice
141
     *
142
     * @param  array|string|null  $options
143
     *
144
     * @return self
145
     */
146
    public function pay($options = null)
147
    {
148
        $url = $this->instanceUrl() . '/pay';
149
150
        list($response, $opts) = $this->request('post', $url, [], $options);
151
        $this->refreshFrom($response, $opts);
152
153
        return $this;
154
    }
155
}
156