Skip to content

Commit faaf880

Browse files
wip
1 parent f9f9890 commit faaf880

2 files changed

Lines changed: 115 additions & 5 deletions

File tree

src/Models/Orders/Order.php

Lines changed: 95 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class Order
5555
/**
5656
* @var string
5757
*/
58-
protected $formattedTotalAmount;
58+
protected $formattedTotalOrderAmount;
5959

6060
/**
6161
* @var int|null
@@ -82,8 +82,8 @@ class Order
8282
*/
8383
protected $paidAt;
8484

85-
// TODO: Add Line items
86-
// TODO: Add Applied discounts
85+
// TODO: Add Line Items
86+
// TODO: Add Applied Discounts
8787
// TODO: Add Charges
8888

8989
/**
@@ -104,11 +104,37 @@ class Order
104104
public function __construct(
105105
string $uuid,
106106
string $externalIdentifier,
107-
Contact $contact
107+
Contact $contact,
108+
Shop $shop,
109+
string $currency,
110+
?string $reference,
111+
string $status,
112+
string $paymentStatus,
113+
string $formattedTotalOrderAmount,
114+
?int $orderAmount,
115+
int $totalChargesAmount,
116+
int $totalDiscountAmount,
117+
int $totalOrderAmount,
118+
?string $paidAt,
119+
string $createdAt,
120+
string $updatedAt
108121
) {
109122
$this->uuid = $uuid;
110123
$this->externalIdentifier = $externalIdentifier;
111124
$this->contact = $contact;
125+
$this->shop = $shop;
126+
$this->currency = $currency;
127+
$this->reference = $reference;
128+
$this->status = $status;
129+
$this->paymentStatus = $paymentStatus;
130+
$this->formattedTotalOrderAmount = $formattedTotalOrderAmount;
131+
$this->orderAmount = $orderAmount;
132+
$this->totalChargesAmount = $totalChargesAmount;
133+
$this->totalDiscountAmount = $totalDiscountAmount;
134+
$this->totalOrderAmount = $totalOrderAmount;
135+
$this->paidAt = $paidAt;
136+
$this->createdAt = $createdAt;
137+
$this->updatedAt = $updatedAt;
112138
}
113139

114140
public function getUuid(): string
@@ -126,6 +152,71 @@ public function getContact(): Contact
126152
return $this->contact;
127153
}
128154

155+
public function getShop(): Shop
156+
{
157+
return $this->shop;
158+
}
159+
160+
public function getCurrency(): string
161+
{
162+
return $this->currency;
163+
}
164+
165+
public function getReference(): ?string
166+
{
167+
return $this->reference;
168+
}
169+
170+
public function getStatus(): string
171+
{
172+
return $this->status;
173+
}
174+
175+
public function getPaymentStatus(): string
176+
{
177+
return $this->paymentStatus;
178+
}
179+
180+
public function getFormattedTotalOrderAmount(): string
181+
{
182+
return $this->formattedTotalOrderAmount;
183+
}
184+
185+
public function getOrderAmount(): ?int
186+
{
187+
return $this->orderAmount;
188+
}
189+
190+
public function getTotalChargesAmount(): int
191+
{
192+
return $this->totalChargesAmount;
193+
}
194+
195+
public function getTotalDiscountAmount(): int
196+
{
197+
return $this->totalDiscountAmount;
198+
}
199+
200+
public function getTotalOrderAmount(): int
201+
{
202+
return $this->totalOrderAmount;
203+
}
204+
205+
public function getPaidAt(): ?string
206+
{
207+
return $this->paidAt;
208+
}
209+
210+
public function getCreatedAt(): string
211+
{
212+
return $this->createdAt;
213+
}
214+
215+
public function getUpdatedAt(): string
216+
{
217+
return $this->updatedAt;
218+
}
219+
129220
/**
130221
* @param array<string, mixed> $params
131222
*

src/StaticMappers/Orders/OrderMapper.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Piggy\Api\Models\Orders\Order;
66
use Piggy\Api\StaticMappers\Contacts\ContactMapper;
7+
use Piggy\Api\StaticMappers\Shops\ShopMapper;
78
use stdClass;
89

910
class OrderMapper
@@ -15,10 +16,28 @@ public static function map(stdClass $data): Order
1516
$contact = ContactMapper::map($data->contact);
1617
}
1718

19+
$shop = null;
20+
if (isset($data->business_profile)) {
21+
$shop = ShopMapper::map($data->business_profile);
22+
}
23+
1824
return new Order(
1925
$data->uuid,
2026
$data->external_identifier,
21-
$contact
27+
$contact,
28+
$shop,
29+
$data->currency,
30+
$data->reference ?? null,
31+
$data->status,
32+
$data->payment_status,
33+
$data->formatted_total_order_amount,
34+
isset($data->order_amount) ? (int) $data->order_amount : null,
35+
(int) $data->total_charges_amount,
36+
(int) $data->total_discount_amount,
37+
(int) $data->total_order_amount,
38+
$data->paid_at ?? null,
39+
$data->created_at,
40+
$data->updated_at
2241
);
2342
}
2443
}

0 commit comments

Comments
 (0)