From 1a0a9ff54ebc312536206df004de20a5a4a75c4a Mon Sep 17 00:00:00 2001 From: Kris Date: Sat, 22 Aug 2020 21:55:05 +0200 Subject: [PATCH] added functions to better analyze payment methods --- src/Receipt.php | 12 ++++++++++++ tests/ReceiptParsingTest.php | 4 ++++ 2 files changed, 16 insertions(+) diff --git a/src/Receipt.php b/src/Receipt.php index 68c9043..9f2d885 100644 --- a/src/Receipt.php +++ b/src/Receipt.php @@ -109,6 +109,18 @@ public function getPaymentMethods(): array return $paymentMethods; } + public function hasPayedCashless(): bool + { + return preg_match('/Kartenzahlung/', $this->raw_receipt) || + //the following line is just for old receipts which doesn't have "Kartenzahlung" in it + (preg_match('/Bezahlung/', $this->raw_receipt) && preg_match('/(VISA|MasterCard|American Express|JCB)/', $this->raw_receipt)); + } + + public function hasPayedContactless(): bool + { + return preg_match('/Kontaktlos/', $this->raw_receipt); + } + /** * @return Carbon */ diff --git a/tests/ReceiptParsingTest.php b/tests/ReceiptParsingTest.php index a1670f9..177f3d1 100644 --- a/tests/ReceiptParsingTest.php +++ b/tests/ReceiptParsingTest.php @@ -37,6 +37,8 @@ public function testBonParsingWeight(): void $this->assertEquals(2, $receipt->getCashregisterNr()); $this->assertEquals(5, $receipt->getEarnedPaybackPoints()); $this->assertContains("EC-Cash", $receipt->getPaymentMethods()); + $this->assertTrue( $receipt->hasPayedCashless()); + $this->assertTrue( $receipt->hasPayedContactless()); $this->assertEquals(1577880000, $receipt->getTimestamp()->getTimestamp()); $this->assertEquals(1, $receipt->getPositionByName('BROT')->getPriceSingle()); $this->assertEquals(0.5, $receipt->getPositionByName('AUFSCHNITT')->getPriceSingle()); @@ -72,6 +74,8 @@ public function testBonParsingPaymentMethods(): void $this->assertEquals(22, $receipt->getEarnedPaybackPoints()); $this->assertContains("BAR", $receipt->getPaymentMethods()); $this->assertContains("VISA", $receipt->getPaymentMethods()); + $this->assertTrue($receipt->hasPayedCashless()); + $this->assertFalse($receipt->hasPayedContactless()); $this->assertEquals(1577880000, $receipt->getTimestamp()->getTimestamp()); $this->assertEquals(0.25, $receipt->getPositionByName('LEERGUT')->getPriceSingle());