Skip to content

Commit 8a940a0

Browse files
committed
Small validation fixes
1 parent 010d47d commit 8a940a0

6 files changed

Lines changed: 32 additions & 14 deletions

File tree

src/Domain/Address/ShippingAddress.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public function __construct(
4141

4242
protected function assertValidShippingCost(): void
4343
{
44-
DomainException::assert(is_null($this->shipping_cost) || $this->shipping_cost >= 0, "Shipping cost can be null or greater than 0.");
44+
DomainException::assert(is_null($this->shipping_cost) || $this->shipping_cost >= 0, "Shipping cost can be null or greater or equal to 0.");
4545
}
4646
}

src/Domain/Order/Card.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function __construct(
2525
$this->expiry_month = substr(trim($expiry_month), 0, 2);
2626
$this->expiry_year = substr(trim($expiry_year), 0, 4);
2727

28-
$this->assertValidHolder();
28+
// $this->assertValidHolder();
2929
$this->assertValidNumber();
3030
$this->assertValidExpiryMonth();
3131
$this->assertValidExpiryYear();
@@ -38,8 +38,8 @@ protected function assertValidHolder(): void
3838

3939
protected function assertValidNumber(): void
4040
{
41-
DomainException::assert(preg_match('/^[0-9]{13,19}$/', $this->number), "Card number should only contain digits with length between 13 and 19 characters.");
42-
DomainException::assert(Luhn::check($this->number), "Number is not a valid credit card number.");
41+
DomainException::assert(preg_match('/^[0-9\\*]{13,19}$/', $this->number), "Card number should only contain digits with length between 13 and 19 characters.");
42+
// DomainException::assert(Luhn::check($this->number), "Number is not a valid credit card number.");
4343
}
4444

4545
protected function assertValidExpiryMonth(): void

src/Domain/Order/Customer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Customer implements JsonSerializable
1919
protected Document $document;
2020
protected ?Gender $gender;
2121
protected ?DateTime $birth_date;
22-
protected Email $email;
22+
protected ?Email $email;
2323
protected ?MobilePhone $mobile_phone;
2424
protected ?FixedLinePhone $phone;
2525

@@ -29,7 +29,7 @@ public function __construct(
2929
Document $document,
3030
?Gender $gender,
3131
?DateTime $birth_date,
32-
Email $email,
32+
?Email $email,
3333
?MobilePhone $mobile_phone,
3434
?FixedLinePhone $phone
3535
) {
@@ -80,7 +80,7 @@ public function jsonSerialize()
8080
'document' => $this->document->jsonSerialize(),
8181
'gender' => $this->gender ? (string)$this->gender : null,
8282
'birth_date' => $this->birth_date ? $this->birth_date->format('Y-m-d') : null,
83-
'email' => (string)$this->email,
83+
'email' => $this->email ? (string)$this->email : null,
8484
'mobile_phone' => $this->mobile_phone ? (string)$this->mobile_phone : null,
8585
'phone' => $this->phone ? (string)$this->phone : null,
8686
];

src/Domain/Order/Item.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@ class Item implements JsonSerializable
1111
protected string $name;
1212
protected float $unit_price;
1313
protected int $quantity;
14-
protected string $sku;
14+
protected ?string $sku;
1515
protected ?string $description;
1616

1717
public function __construct(
1818
?string $merchant_item_id,
1919
string $name,
2020
float $unit_price,
2121
int $quantity,
22-
string $sku,
22+
?string $sku,
2323
?string $description
2424
) {
2525
$this->merchant_item_id = $merchant_item_id ? substr(trim($merchant_item_id), 0, 255) : $merchant_item_id;
2626
$this->name = substr(trim($name), 0, 64);
2727
$this->unit_price = $unit_price;
2828
$this->quantity = $quantity;
29-
$this->sku = substr(trim($sku), 0, 12);
29+
$this->sku = $sku ? substr(trim($sku), 0, 12) : $sku;
3030
$this->description = $description ? substr(trim($description), 0, 128) : $description;
3131

3232
$this->assertValidMerchantItemId();
3333
$this->assertValidName();
3434
$this->assertValidUnitPrice();
3535
$this->assertValidQuantity();
36-
$this->assertValidSku();
37-
$this->assertValidDescription();
36+
// $this->assertValidSku();
37+
// $this->assertValidDescription();
3838
}
3939

4040
protected function assertValidMerchantItemId(): void

src/Domain/Order/Order.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Order implements JsonSerializable
1313
protected string $merchant_order_id;
1414
protected float $amount;
1515
protected int $installments;
16+
protected bool $is_recurring;
1617
protected CurrencyCode $currency;
1718
protected Customer $customer;
1819
protected BillingAddress $billing_address;
@@ -34,11 +35,13 @@ public function __construct(
3435
Factor $factors,
3536
array $items = [],
3637
array $payments = [],
37-
array $metadata = []
38+
array $metadata = [],
39+
bool $is_recurring = false
3840
) {
3941
$this->merchant_order_id = $merchant_order_id;
4042
$this->amount = $amount;
4143
$this->installments = $installments;
44+
$this->is_recurring = $is_recurring;
4245
$this->currency = $currency;
4346
$this->customer = $customer;
4447
$this->billing_address = $billing_address;
@@ -52,7 +55,7 @@ public function __construct(
5255

5356
$this->assertValidAmount();
5457
$this->assertValidInstallments();
55-
$this->assertValidMerchantOrderId();
58+
// $this->assertValidMerchantOrderId();
5659
}
5760

5861
protected function assertValidAmount(): void
@@ -103,6 +106,7 @@ public function jsonSerialize()
103106
'merchant_order_id' => $this->merchant_order_id,
104107
'amount' => $this->amount,
105108
'installments' => $this->installments,
109+
'is_recurring' => $this->is_recurring,
106110
'currency' => (string)$this->currency,
107111
'status' => (string)$this->status,
108112
'customer' => $this->customer->jsonSerialize(),

src/Domain/Order/PaymentMethod.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,15 @@ class PaymentMethod implements Stringable
2121
public const VISAELECTRON = 'visaelectron';
2222
public const MAESTRO = 'maestro';
2323
public const ELODEBIT = 'elodebit';
24+
25+
public const CREDIT_CARD = 'creditcard';
26+
public const DEBIT_CARD = 'debitcard';
2427
public const PIX = 'pix';
2528
public const BILLET = 'billet';
2629

2730
public const ALLOWED = [
31+
self::CREDIT_CARD,
32+
self::DEBIT_CARD,
2833
self::VISA,
2934
self::MASTERCARD,
3035
self::ELO,
@@ -123,6 +128,15 @@ public static function billet(): self
123128
return new static(self::BILLET);
124129
}
125130

131+
public static function creditCard(): self
132+
{
133+
return new static(self::CREDIT_CARD);
134+
}
135+
136+
public static function debitCard(): self
137+
{
138+
return new static(self::DEBIT_CARD);
139+
}
126140

127141
public function __toString(): string
128142
{

0 commit comments

Comments
 (0)