Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ You may provide the following as envelopes:

<a name="changelog"></a>
## Changelog
* `1.5.1`
* Change the data type of the field `language_browser` from `string(255)` to `string(1024)`
* Change the data type of the field `product_quantity` from `int` to `float` for the "Order Item" event
* Add the possibility to send zero in the following fields:
`amount`, `amount_converted`, `shipping_fee`, `shipping_fee_converted`,
`source_fee`, `source_fee_converted`, `tax_fee`, `tax_fee_converted`,
`transaction_amount`, `transaction_amount_converted`, `refund_amount`, `refund_amount_converted`,
`payout_amount`, `payout_amount_converted`, `one_operation_limit`,
`daily_limit`, `weekly_limit`, `monthly_limit`, `annual_limit`
* `1.5.0`
* The minimum PHP version has been changed from 5.4 to 7.3.
* Packages have been updated.
Expand Down
272 changes: 210 additions & 62 deletions src/Envelopes/Builder.php

Large diffs are not rendered by default.

38 changes: 36 additions & 2 deletions src/Envelopes/ValidatorV1.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ValidatorV1
'firstname' => 'string(255)',
'gender' => 'string(255)',
'language' => 'string(255)',
'language_browser' => 'string(255)',
'language_browser' => 'string(1024)',
'language_system' => 'string(255)',
'language_user' => 'string(255)',
'languages' => 'string(1024)',
Expand Down Expand Up @@ -274,6 +274,28 @@ class ValidatorV1
'translated_to' => 'string(225)'
);

private static $fieldWithZeroAllowed = array(
'amount',
'amount_converted',
'shipping_fee',
'shipping_fee_converted',
'source_fee',
'source_fee_converted',
'tax_fee',
'tax_fee_converted',
'transaction_amount',
'transaction_amount_converted',
'refund_amount',
'refund_amount_converted',
'payout_amount',
'payout_amount_converted',
'one_operation_limit',
'daily_limit',
'weekly_limit',
'monthly_limit',
'annual_limit'
);

private static $sharedOptional = array(
'ajax_validation',
'cookie_enabled',
Expand Down Expand Up @@ -1042,7 +1064,10 @@ public function analyzeTypeAndMandatoryFields(EnvelopeInterface $envelope)

// Mandatory fields check
foreach ($typeInfo['mandatory'] as $name) {
if (!isset($envelope[$name]) || empty($envelope[$name])) {
if (
!isset($envelope[$name]) ||
$this->emptyConditionForMandatoryField($envelope, $name)
) {
$details[] = sprintf(
'Field "%s" is mandatory for "%s", but not provided',
$name,
Expand Down Expand Up @@ -1224,4 +1249,13 @@ public function isCustom($key)
{
return is_string($key) && strlen($key) >= 7 && substr($key, 0, 7) === 'custom_';
}

private function emptyConditionForMandatoryField(EnvelopeInterface $envelope, $name)
{
if (in_array($name, self::$fieldWithZeroAllowed)) {
return is_null($envelope[$name]) || $envelope[$name] == '';
} else {
return empty($envelope[$name]);
}
}
}
118 changes: 118 additions & 0 deletions tests/Covery/BuildDocumentEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,122 @@ public function testBuild()

$validator->validate($result);
}

public function testZeroValueForFloatWithAllowedZero()
{
$validator = new ValidatorV1();
$result = Builder::documentEvent(
'tempEventId',
123456,
'tempUserId',
\Covery\Client\DocumentType::INTERNATIONAL_PASSPORT,
'tempSequenceId',
'tempGroupId',
'tempDocumentCountry',
'tempDocumentNumber',
'tempFileName',
'tempEmail',
'tempFirstName',
'tempLastName',
'tempFullname',
123456,
18,
'tempGender',
'tempNationality',
'tempCountry',
'tempCity',
'tempZip',
'tempAddress',
123456,
123456,
'tempAuthority',
'testRecordNumber',
'testPersonalNumber',
'testDescription',
10.4,
'testPaymentMethod',
0.0,
0.0
)->build();
self::assertSame(0.0, $result['amount']);
self::assertSame(0.0, $result['amount_converted']);
$validator->validate($result);
}

public function testEventExpectInvalidArgumentExceptionForNegativeAmount()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("Amount cannot be negative");
Builder::documentEvent(
'tempEventId',
123456,
'tempUserId',
\Covery\Client\DocumentType::INTERNATIONAL_PASSPORT,
'tempSequenceId',
'tempGroupId',
'tempDocumentCountry',
'tempDocumentNumber',
'tempFileName',
'tempEmail',
'tempFirstName',
'tempLastName',
'tempFullname',
123456,
18,
'tempGender',
'tempNationality',
'tempCountry',
'tempCity',
'tempZip',
'tempAddress',
123456,
123456,
'tempAuthority',
'testRecordNumber',
'testPersonalNumber',
'testDescription',
10.4,
'testPaymentMethod',
-23.6
)->build();
}

public function testEventExpectInvalidArgumentExceptionForNegativeAmountConverted()
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage("Amount converted cannot be negative");
Builder::documentEvent(
'tempEventId',
123456,
'tempUserId',
\Covery\Client\DocumentType::INTERNATIONAL_PASSPORT,
'tempSequenceId',
'tempGroupId',
'tempDocumentCountry',
'tempDocumentNumber',
'tempFileName',
'tempEmail',
'tempFirstName',
'tempLastName',
'tempFullname',
123456,
18,
'tempGender',
'tempNationality',
'tempCountry',
'tempCity',
'tempZip',
'tempAddress',
123456,
123456,
'tempAuthority',
'testRecordNumber',
'testPersonalNumber',
'testDescription',
10.4,
'testPaymentMethod',
23.6,
-34.5
)->build();
}
}
Loading