Skip to content

Commit

Permalink
added functions to better analyze payment methods
Browse files Browse the repository at this point in the history
  • Loading branch information
MrKrisKrisu committed Aug 22, 2020
1 parent fa4469a commit 1a0a9ff
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Receipt.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 4 additions & 0 deletions tests/ReceiptParsingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 1a0a9ff

Please sign in to comment.