Skip to content

Commit 6899fb0

Browse files
authored
Merge pull request #40 from andrextor/feature/redirect-request-metadata
feat: adds support for `metadata` and `provider` properties.
2 parents 923df20 + 9dd8f18 commit 6899fb0

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

src/Message/CollectRequest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,18 @@ class CollectRequest extends RedirectRequest
1111
protected string $returnUrl = '';
1212
protected string $ipAddress = '';
1313
protected string $userAgent = '';
14+
protected ?string $provider = null;
1415

1516
public function __construct(array $data = [])
1617
{
1718
parent::__construct($data);
1819
$this->loadEntity($data['instrument'], 'instrument', Instrument::class);
20+
$this->provider = $data['provider'] ?? null;
21+
}
22+
23+
public function provider(): ?string
24+
{
25+
return $this->provider;
1926
}
2027

2128
public function instrument(): Instrument
@@ -27,6 +34,7 @@ public function toArray(): array
2734
{
2835
return array_merge(parent::toArray(), [
2936
'instrument' => $this->instrument() ? $this->instrument()->toArray() : null,
37+
'provider' => $this->provider(),
3038
]);
3139
}
3240
}

src/Message/RedirectRequest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ class RedirectRequest extends Entity
2727
protected bool $skipResult = false;
2828
protected bool $noBuyerFill = false;
2929

30+
protected array $metadata = [];
31+
3032
public function __construct($data = [])
3133
{
3234
// Setting the default values
@@ -48,6 +50,8 @@ public function __construct($data = [])
4850
if (isset($data['fields'])) {
4951
$this->setFields($data['fields']);
5052
}
53+
54+
$this->metadata = $data['metadata'] ?? [];
5155
}
5256

5357
public function locale(): string
@@ -177,6 +181,11 @@ public function noBuyerFill(): bool
177181
return filter_var($this->noBuyerFill, FILTER_VALIDATE_BOOLEAN);
178182
}
179183

184+
public function metadata(): array
185+
{
186+
return $this->metadata;
187+
}
188+
180189
public function toArray(): array
181190
{
182191
return $this->arrayFilter([
@@ -195,6 +204,7 @@ public function toArray(): array
195204
'captureAddress' => $this->captureAddress(),
196205
'skipResult' => $this->skipResult(),
197206
'noBuyerFill' => $this->noBuyerFill(),
207+
'metadata' => $this->metadata(),
198208
]);
199209
}
200210
}

tests/Messages/CollectRequestTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ public function testItParsesCorrectlyACollectWithCredit()
4343
'captureAddress' => false,
4444
'skipResult' => false,
4545
'noBuyerFill' => false,
46+
'provider' => 'PROVIDER',
47+
'metadata' => [
48+
"initiatorIndicator" => "AGENT"
49+
]
4650
];
4751
$request = new CollectRequest($data);
4852

@@ -53,5 +57,8 @@ public function testItParsesCorrectlyACollectWithCredit()
5357

5458
$this->assertEquals($data['instrument'], $request->instrument()->toArray());
5559
$this->assertEquals($data, $request->toArray());
60+
$this->assertEquals($data['metadata'], $request->metadata());
61+
$this->assertEquals($data['provider'], $request->provider());
62+
5663
}
5764
}

tests/Messages/RedirectRequestTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ public function testItParsesCorrectlyAPaymentRequest()
103103
'noBuyerFill' => true,
104104
'captureAddress' => true,
105105
'paymentMethod' => 'CR_VS,_ATH_',
106+
'metadata' => [
107+
"initiatorIndicator" => "AGENT"
108+
],
106109
];
107110
$request = new RedirectRequest($data);
108111

@@ -112,6 +115,7 @@ public function testItParsesCorrectlyAPaymentRequest()
112115
$this->assertTrue($request->payment()->allowPartial());
113116
$this->assertEquals($data['returnUrl'], $request->returnUrl());
114117
$this->assertEquals($data['cancelUrl'], $request->cancelUrl());
118+
$this->assertEquals($data['metadata'], $request->metadata());
115119

116120
$this->assertEquals($data, $request->toArray());
117121
}

0 commit comments

Comments
 (0)