Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit 1a0a9ff

Browse files
committed
added functions to better analyze payment methods
1 parent fa4469a commit 1a0a9ff

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

src/Receipt.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,18 @@ public function getPaymentMethods(): array
109109
return $paymentMethods;
110110
}
111111

112+
public function hasPayedCashless(): bool
113+
{
114+
return preg_match('/Kartenzahlung/', $this->raw_receipt) ||
115+
//the following line is just for old receipts which doesn't have "Kartenzahlung" in it
116+
(preg_match('/Bezahlung/', $this->raw_receipt) && preg_match('/(VISA|MasterCard|American Express|JCB)/', $this->raw_receipt));
117+
}
118+
119+
public function hasPayedContactless(): bool
120+
{
121+
return preg_match('/Kontaktlos/', $this->raw_receipt);
122+
}
123+
112124
/**
113125
* @return Carbon
114126
*/

tests/ReceiptParsingTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ public function testBonParsingWeight(): void
3737
$this->assertEquals(2, $receipt->getCashregisterNr());
3838
$this->assertEquals(5, $receipt->getEarnedPaybackPoints());
3939
$this->assertContains("EC-Cash", $receipt->getPaymentMethods());
40+
$this->assertTrue( $receipt->hasPayedCashless());
41+
$this->assertTrue( $receipt->hasPayedContactless());
4042
$this->assertEquals(1577880000, $receipt->getTimestamp()->getTimestamp());
4143
$this->assertEquals(1, $receipt->getPositionByName('BROT')->getPriceSingle());
4244
$this->assertEquals(0.5, $receipt->getPositionByName('AUFSCHNITT')->getPriceSingle());
@@ -72,6 +74,8 @@ public function testBonParsingPaymentMethods(): void
7274
$this->assertEquals(22, $receipt->getEarnedPaybackPoints());
7375
$this->assertContains("BAR", $receipt->getPaymentMethods());
7476
$this->assertContains("VISA", $receipt->getPaymentMethods());
77+
$this->assertTrue($receipt->hasPayedCashless());
78+
$this->assertFalse($receipt->hasPayedContactless());
7579
$this->assertEquals(1577880000, $receipt->getTimestamp()->getTimestamp());
7680

7781
$this->assertEquals(0.25, $receipt->getPositionByName('LEERGUT')->getPriceSingle());

0 commit comments

Comments
 (0)