Skip to content

Commit 9709936

Browse files
authored
Merge pull request #106 from swlodarski-sumoheavy/9.3.x
SP-1099 - do not throw IPN validation exception when email casing mismatch
2 parents e264454 + b501c56 commit 9709936

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

Model/Ipn/Validator.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class Validator
1515
public function __construct(\BitPaySDK\Model\Invoice\Invoice $invoice, array $ipnData)
1616
{
1717
$name = $ipnData['buyerFields']['buyerName'];
18-
$email = $ipnData['buyerFields']['buyerEmail'];
18+
$email = strtolower($ipnData['buyerFields']['buyerEmail']);
1919
$address1 = $ipnData['buyerFields']['buyerAddress1'] ?? null;
2020
$address2 = $ipnData['buyerFields']['buyerAddress2'] ?? null;
2121
$amountPaid = $ipnData['amountPaid'];
@@ -25,8 +25,8 @@ public function __construct(\BitPaySDK\Model\Invoice\Invoice $invoice, array $ip
2525
$this->errors[] = "Name from IPN data ('{$name}') does not match with " .
2626
"name from invoice ('{$invoiceBuyerName}')";
2727
}
28-
29-
if ($email !== $invoiceBuyerEmail = $invoiceBuyer->getEmail()) {
28+
$invoiceBuyerEmail = strtolower($invoiceBuyer->getEmail());
29+
if ($email !== $invoiceBuyerEmail) {
3030
$this->errors[] = "Email from IPN data ('{$email}') does not match with " .
3131
"email from invoice ('{$invoiceBuyerEmail}')";
3232
}

Test/Unit/Model/IpnManagementTest.php

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,45 @@ public function testPostIpnValidatorError(): void
299299
$client->expects($this->once())->method('getInvoice')->willReturn($invoice);
300300
$this->client->expects($this->once())->method('initialize')->willReturn($client);
301301
$this->transactionRepository->expects($this->once())->method('findBy')->willReturn([]);
302-
$this->throwException(new IPNValidationException('Email from IPN data (\'[email protected]\') does not' .
303-
'match with email from invoice (\'[email protected]\')'));
302+
303+
$this->response->expects($this->once())->method('addMessage')->with(
304+
"Email from IPN data ('{$data['data']['buyerFields']['buyerEmail']}') does not match with " .
305+
"email from invoice ('{$invoice->getBuyer()->getEmail()}')",
306+
500
307+
);
308+
309+
$this->ipnManagement->postIpn();
310+
}
311+
312+
public function testPostIpnNoValidatorErrorWhenEmailCasingMismatch(): void
313+
{
314+
$eventName = 'ivoice_confirmed';
315+
$orderInvoiceId = '12';
316+
$data = [
317+
'data' => [
318+
'orderId' => '00000012',
319+
'id' => $orderInvoiceId,
320+
'buyerFields' => [
321+
'buyerName' => 'test',
322+
'buyerEmail' => '[email protected]',
323+
'buyerAddress1' => '12 test road'
324+
],
325+
'amountPaid' => 1232132
326+
],
327+
'event' => ['name' => $eventName]
328+
];
329+
$serializer = new Json();
330+
$serializerData = $serializer->serialize($data);
331+
$this->serializer->expects($this->once())->method('unserialize')->willReturn($data);
332+
$this->request->expects($this->once())->method('getContent')->willReturn($serializerData);
333+
334+
$invoice = $this->prepareInvoice();
335+
$client = $this->getMockBuilder(\BitPaySDK\Client::class)->disableOriginalConstructor()->getMock();
336+
$client->expects($this->once())->method('getInvoice')->willReturn($invoice);
337+
$this->client->expects($this->once())->method('initialize')->willReturn($client);
338+
$this->transactionRepository->expects($this->once())->method('findBy')->willReturn([]);
339+
340+
$this->response->expects($this->never())->method('addMessage');
304341

305342
$this->ipnManagement->postIpn();
306343
}

0 commit comments

Comments
 (0)