@@ -95,7 +95,11 @@ class Invoice extends AbstractEntity
9595 'webhooks_delivered_at ' => null ,
9696 ];
9797
98- protected static array $ expandableProps = ['payment_intent ' ];
98+ protected static array $ expandableProps = [
99+ 'customer ' ,
100+ 'payment_intent ' ,
101+ 'subscription ' ,
102+ ];
99103
100104 protected static array $ subActions = [
101105 'finalize ' => 'finalize ' ,
@@ -121,22 +125,49 @@ public static function create(string $id, array $props = []): ResponseInterface
121125 $ props ['payment_intent ' ] = $ paymentIntent ->id ;
122126 }
123127
124- $ lines = new Collection ();
128+ if (array_key_exists ('default_tax_rates ' , $ props )) {
129+ $ props ['default_tax_rates ' ] = array_map (
130+ fn ($ defaultTaxRate ) =>
131+ is_array ($ defaultTaxRate )
132+ ? $ defaultTaxRate
133+ : EntityManager::retrieveEntity ('tax_rate ' , $ defaultTaxRate )->toArray (),
134+ $ props ['default_tax_rates ' ]
135+ );
136+ }
125137
126- /** @noinspection SpellCheckingInspection */
127- $ pendingInvoiceItems = EntityManager:: listEntity ( ' invoiceitem ' , [ ' customer ' => $ props [ ' customer ' ]])-> data ;
138+ if (! array_key_exists ( ' lines ' , $ props )) {
139+ $ lines = new Collection () ;
128140
129- if (!empty ($ pendingInvoiceItems )) {
130- foreach ($ pendingInvoiceItems as $ pendingInvoiceItem ) {
131- $ lines ->add (LineItem::createFromInvoiceItem ($ pendingInvoiceItem ));
141+ /** @noinspection SpellCheckingInspection */
142+ $ pendingInvoiceItems = EntityManager::listEntity ('invoiceitem ' , ['customer ' => $ props ['customer ' ]])->data ;
143+
144+ if (!empty ($ pendingInvoiceItems )) {
145+ foreach ($ pendingInvoiceItems as $ pendingInvoiceItem ) {
146+ $ lines ->add (LineItem::createFromInvoiceItem ($ pendingInvoiceItem ));
147+ }
132148 }
133- }
134149
135- $ props ['lines ' ] = $ lines ->toArray ();
150+ $ props ['lines ' ] = $ lines ->toArray ();
151+ }
136152
137153 return parent ::create ($ id , $ props );
138154 }
139155
156+ public function update (array $ props ): ResponseInterface
157+ {
158+ if (array_key_exists ('default_tax_rates ' , $ props )) {
159+ $ props ['default_tax_rates ' ] = array_map (
160+ fn ($ defaultTaxRate ) =>
161+ is_array ($ defaultTaxRate )
162+ ? $ defaultTaxRate
163+ : EntityManager::retrieveEntity ('tax_rate ' , $ defaultTaxRate )->toArray (),
164+ $ props ['default_tax_rates ' ]
165+ );
166+ }
167+
168+ return parent ::update ($ props );
169+ }
170+
140171 public static function parseUrlTail (string $ tail ): array
141172 {
142173 $ parsedTail = parent ::parseUrlTail ($ tail );
0 commit comments