Skip to content

Commit 3ffe820

Browse files
authored
Merge pull request #28 from dnetix/improve-dispersion-handling
Improve dispersion handling
2 parents cb19462 + 08aa33a commit 3ffe820

File tree

5 files changed

+17
-21
lines changed

5 files changed

+17
-21
lines changed

src/Entities/Payment.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Payment extends Entity
2222
protected ?Discount $discount = null;
2323
protected ?Instrument $instrument = null;
2424
public bool $subscribe = false;
25-
protected string $agreement = '';
25+
protected ?int $agreement = null;
2626
protected string $agreementType = '';
2727

2828
public function __construct(array $data = [])
@@ -57,7 +57,7 @@ public function amount(): ?Amount
5757
return $this->amount;
5858
}
5959

60-
public function agreement(): string
60+
public function agreement(): ?int
6161
{
6262
return $this->agreement;
6363
}
@@ -135,18 +135,18 @@ public function itemsToArray(): array
135135
public function toArray(): array
136136
{
137137
return self::arrayFilter([
138+
'agreement' => $this->agreement(),
139+
'agreementType' => $this->agreementType(),
138140
'reference' => $this->reference(),
139141
'description' => $this->description(),
140142
'amount' => $this->amount() ? $this->amount()->toArray() : null,
141-
'allowPartial' => $this->allowPartial,
142143
'shipping' => $this->shipping() ? $this->shipping()->toArray() : null,
143144
'items' => $this->itemsToArray(),
144145
'recurring' => $this->recurring() ? $this->recurring()->toArray() : null,
145146
'discount' => $this->discount() ? $this->discount()->toArray() : null,
146-
'subscribe' => $this->subscribe(),
147147
'fields' => $this->fieldsToArray(),
148-
'agreement' => $this->agreement(),
149-
'agreementType' => $this->agreementType(),
148+
'subscribe' => $this->subscribe() ?: null,
149+
'allowPartial' => $this->allowPartial ?: null,
150150
]);
151151
}
152152
}

tests/Entities/PaymentEntityTest.php

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,7 @@ public function testItAddsAField()
4646
'name' => 'Testing2',
4747
],
4848
],
49-
'allowPartial' => false,
50-
'subscribe' => false,
49+
'allowPartial' => true,
5150
];
5251
$payment = new Payment($data);
5352
$this->assertEquals(1, count($payment->fields()));
@@ -166,8 +165,7 @@ public function testItParsesTheDataCorrectly()
166165
'base' => '10',
167166
'percent' => 0,
168167
],
169-
'allowPartial' => false,
170-
'subscribe' => false,
168+
'subscribe' => true,
171169
];
172170
$payment = new Payment($data);
173171

@@ -284,8 +282,6 @@ public function testItParsesCorrectlyADispersion()
284282
'currency' => 'COP',
285283
'total' => 207890,
286284
],
287-
'allowPartial' => false,
288-
'subscribe' => false,
289285
],
290286
[
291287
'reference' => 'TEST_3',
@@ -301,12 +297,8 @@ public function testItParsesCorrectlyADispersion()
301297
'currency' => 'COP',
302298
'total' => 35700,
303299
],
304-
'allowPartial' => false,
305-
'subscribe' => false,
306300
],
307301
],
308-
'allowPartial' => false,
309-
'subscribe' => false,
310302
],
311303
'expiration' => date('c', strtotime('+1 day')),
312304
'returnUrl' => 'https://dnetix.co/ping/rtest',

tests/Messages/CollectRequestTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,6 @@ public function testItParsesCorrectlyACollectWithCredit()
2525
'currency' => 'COP',
2626
'total' => 143000,
2727
],
28-
'allowPartial' => false,
29-
'subscribe' => false,
3028
],
3129
'instrument' => [
3230
'token' => [

tests/Messages/RedirectRequestTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,13 @@ public function testItParsesCorrectlyASubscriptionRequest()
169169
$this->assertEquals($additional['expiration'], $request->expiration());
170170
$this->assertEquals($additional['cancelUrl'], $request->cancelUrl());
171171
}
172+
173+
public function testItHandlesADispersionRequest()
174+
{
175+
$data = json_decode('{"payment": {"amount": {"taxes": [{"base": 1885200,"kind": "valueAddedTax","amount": 47130},{"base": 0,"kind": "airportTax","amount": 603100}],"total": 3809000,"currency": "COP"},"reference": "800166551","subscribe": false,"dispersion": [{"amount": {"taxes": [{"base": 0,"kind": "valueAddedTax","amount": 47130},{"base": 0,"kind": "airportTax","amount": 603100}],"total": 2535430,"currency": "COP"},"agreement": 30,"reference": "800166551","subscribe": false,"description": "Pago en micrositio","allowPartial": false,"agreementType": "AIRLINE"},{"amount": {"taxes": [{"base": 0,"kind": "valueAddedTax","amount": 0}],"total": 1273570,"currency": "COP"},"reference": "800166551","subscribe": false,"description": "Pago en micrositio","agreement": null,"agreementType": "MERCHANT"}],"description": "Pago en micrositio","allowPartial": false},"ipAddress": "186.84.220.137","returnUrl": "https://sites.placetopay.com/colreservas/payments/c9b7f796dbc707a555a73a0aa14388be878ed69482513150e3ae6d6307e05d44/992939eb60","userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 14_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.1 Mobile/15E148 Safari/604.1","expiration": "2021-07-19T17:05:23-05:00"}', true);
176+
$request = new RedirectRequest($data);
177+
178+
$this->assertSame(30, $request->payment()->dispersion()[0]->agreement());
179+
$this->assertNull($request->payment()->dispersion()[1]->agreement());
180+
}
172181
}

tests/Validators/PaymentValidatorTest.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public function testItPassesWhenAllOk()
1717
'total' => 1000,
1818
],
1919
'allowPartial' => true,
20-
'subscribe' => false,
2120
];
2221
$payment = new Payment($data);
2322
$this->assertEquals($data['reference'], $payment->reference());
@@ -65,7 +64,6 @@ public function testItReceivesAllTheEntities()
6564
],
6665
],
6766
'allowPartial' => true,
68-
'subscribe' => false,
6967
];
7068

7169
$payment = new Payment($data);
@@ -88,7 +86,6 @@ public function testItPassesWhenDescriptionOk()
8886
'total' => 1000,
8987
],
9088
'allowPartial' => true,
91-
'subscribe' => false,
9289
];
9390
$payment = new Payment($data);
9491
$this->assertEquals($data['reference'], $payment->reference());

0 commit comments

Comments
 (0)