v1.7 beta.4

This commit is contained in:
carodej
2020-07-17 08:34:28 +02:00
parent 59b6dfb841
commit caa586ceb4
8 changed files with 175 additions and 38 deletions

View File

@@ -16,32 +16,49 @@ class InvoiceResource extends JsonResource
public function toArray($request)
{
$user = User::where('stripe_id', $this->customer)->first();
$subscription = $this->subscriptions()[0];
$invoice_items = [];
$invoice_subscriptions = [];
// Format bag
foreach ($this->invoiceItems() as $item) {
array_push($invoice_items, [
'amount' => $item->total(),
'description' => $item->description,
'currency' => $item->currency,
'type' => $item->type,
]);
}
// Format bag
foreach ($this->subscriptions() as $item) {
array_push($invoice_subscriptions, [
'amount' => $item->total(),
'description' => $item->description,
'currency' => $item->currency,
'type' => $item->type,
]);
}
return [
'data' => [
'id' => $this->id,
'type' => 'invoices',
'attributes' => [
'customer' => $this->customer,
'total' => $this->total(),
'currency' => $this->currency,
'created_at_formatted' => format_date($this->date(), '%d. %B. %Y'),
'created_at' => $this->created,
'order' => $this->number,
'user_id' => $user ? $user->id : null,
'client' => [
'customer' => $this->customer,
'total' => $this->total(),
'currency' => $this->currency,
'created_at_formatted' => format_date($this->date(), '%d. %B. %Y'),
'created_at' => $this->created,
'order' => $this->number,
'user_id' => $user ? $user->id : null,
'client' => [
'billing_address' => $this->customer_address,
'billing_name' => $this->customer_name,
'billing_phone_number' => $this->customer_phone,
],
'bag' => [
'amount' => $subscription->amount,
'currency' => $subscription->currency,
'type' => $subscription->type,
'description' => $subscription->description,
],
'seller' => null,
'seller' => null,
'invoice_items' => $invoice_items,
'invoice_subscriptions' => $invoice_subscriptions,
]
],
$this->mergeWhen($user, [