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

Commit 5aaa536

Browse files
authored
⬆️ Use mrkriskrisu/ereceipt v0.1 interfaces (#6)
1 parent 5e3feb7 commit 5aaa536

File tree

13 files changed

+211
-203
lines changed

13 files changed

+211
-203
lines changed

.github/workflows/php.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
strategy:
1515
matrix:
16-
php: [ 7.4, 8.0, 8.1 ]
16+
php: [ 8.1 ]
1717
dependency-version: [ prefer-stable ]
1818

1919
steps:

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2020 Kristian Stöckel
3+
Copyright (c) 2022 Kristian Stöckel
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,40 @@ $ composer require mrkriskrisu/rewe-ereceipt-parser
1010
```
1111

1212
## Example Usage
13+
1314
```php
1415
<?php
1516
require 'vendor/autoload.php';
1617

17-
use REWEParser\Parser;
18+
use K118\Receipt\REWE\Parser;
1819

1920
$receipt = Parser::parseFromPDF('receipt.pdf');
2021

21-
echo "You've paid " . $receipt->getTotal() . " Euros.";
22+
echo "You've paid " . $receipt->getTotalPrice() . " Euros.";
2223
```
2324

2425
## Requirements
25-
If you want to use the build in PDF Parser you need to install ``pdftotext`` in your system.
26-
But don't worry, you can use your own PDF to Text Software if you want and give it to
27-
the eReceipt-Parser via the ``Parser::parseFromText($text)`` function.
26+
27+
If you want to use the build in PDF Parser you need to install ``pdftotext`` in your system. But don't worry, you can
28+
use your own PDF to Text Software if you want and give it to the eReceipt-Parser via
29+
the ``Parser::parseFromText($text)`` function.
2830

2931
## Get the eReceipt
30-
To get your digital Receipt at REWE you need to register at rewe.de and connect your
31-
bonus card (PAYBACK) to the account. Then you can activate the "eBon" in the settings
32-
and you'll receive the receipt after every purchase via Mail.
32+
33+
To get your digital Receipt at REWE you need to register at rewe.de and connect your bonus card (PAYBACK) to the
34+
account. Then you can activate the "eBon" in the settings and you'll receive the receipt after every purchase via Mail.
3335

3436
## Contribution
35-
I'm glad that you want to help this library to be perfect.
36-
Just do your magic und make a Pull Request. ✨
37+
38+
I'm glad that you want to help this library to be perfect. Just do your magic und make a Pull Request. ✨
39+
40+
## Related
41+
42+
- [eReceipt](https://github.com/MrKrisKrisu/eReceipt) - PHP interfaces for all eReceipt libraries libraries
43+
44+
- [eReceipt Parser](https://github.com/MrKrisKrisu/eReceipt-Parser) - PHP library which combines all of the following
45+
libraries
46+
47+
- [eReceipt Parser for Lidl](https://github.com/MrKrisKrisu/Lidl-eReceipt-Parser)
48+
49+
- [eReceipt Parser for Edeka](https://github.com/MrKrisKrisu/EDEKA-eReceipt-Parser)

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
}
1111
],
1212
"require": {
13-
"php": "^7.4 || ^8.0",
13+
"php": "^8.1",
1414
"spatie/pdf-to-text": "^1.3",
15-
"nesbot/carbon": "^2.38"
15+
"mrkriskrisu/ereceipt": "^0.1.0"
1616
},
1717
"autoload": {
1818
"psr-4": {
19-
"REWEParser\\": "src/"
19+
"K118\\Receipt\\REWE\\": "src/"
2020
}
2121
},
2222
"require-dev": {

examples/parseFromPDF.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

3-
use REWEParser\Exception\ReceiptParseException;
4-
use REWEParser\Parser;
53
use Spatie\PdfToText\Exceptions\PdfNotFound;
4+
use K118\Receipt\REWE\Parser;
5+
use K118\Receipt\Format\Exception\ReceiptParseException;
66

77
require_once '../vendor/autoload.php';
88

src/Address.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace K118\Receipt\REWE;
4+
5+
class Address implements \K118\Receipt\Format\Models\Address {
6+
7+
private ?string $street;
8+
private ?string $postalCode;
9+
private ?string $city;
10+
private ?string $country;
11+
12+
public function __construct(string $street = null, string $postalCode = null, string $city = null, string $country = null) {
13+
$this->street = $street;
14+
$this->postalCode = $postalCode;
15+
$this->city = $city;
16+
$this->country = $country;
17+
}
18+
19+
public function getStreet(): ?string {
20+
return $this->street;
21+
}
22+
23+
public function getPostalCode(): ?string {
24+
return $this->postalCode;
25+
}
26+
27+
public function getCity(): ?string {
28+
return $this->city;
29+
}
30+
31+
public function getCountry(): ?string {
32+
return $this->country;
33+
}
34+
}

src/Exception/PositionNotFoundException.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

3-
namespace REWEParser\Exception;
3+
namespace K118\Receipt\REWE\Exception;
44

55
use Exception;
66

src/Exception/ReceiptParseException.php

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/Parser.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

3-
namespace REWEParser;
3+
namespace K118\Receipt\REWE;
44

55
use Spatie\PdfToText\Exceptions\PdfNotFound;
66
use Spatie\PdfToText\Pdf;

src/Position.php

Lines changed: 49 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,82 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

3-
namespace REWEParser;
3+
namespace K118\Receipt\REWE;
44

5-
use REWEParser\Exception\ReceiptParseException;
5+
use K118\Receipt\Format\Exception\ReceiptParseException;
6+
use K118\Receipt\Format\Models\Receipt;
67

7-
class Position {
8+
class Position implements \K118\Receipt\Format\Models\Position {
89

9-
private $name;
10-
private $priceTotal;
11-
private $priceSingle;
12-
private $taxCode;
10+
private Receipt $receipt;
1311

14-
private $weight;
15-
private $amount;
12+
private string $name;
13+
private ?float $priceTotal;
14+
private ?float $priceSingle;
15+
private ?string $taxCode;
16+
private ?float $quantity;
1617

17-
/**
18-
* The name of the product.
19-
*
20-
* @return string|NULL
21-
*/
22-
public function getName(): ?string {
18+
public function __construct(Receipt $receipt, string $name = null, float $priceTotal = null, float $priceSingle = null, string $taxCode = null, float $quantity = null) {
19+
$this->receipt = $receipt;
20+
$this->name = $name;
21+
$this->priceTotal = $priceTotal;
22+
$this->priceSingle = $priceSingle;
23+
$this->taxCode = $taxCode;
24+
$this->quantity = $quantity;
25+
}
26+
27+
public function getName(): string {
2328
return $this->name;
2429
}
2530

2631
/**
27-
* The total sum of the position
28-
*
29-
* @return float
30-
* @throws ReceiptParseException
32+
* The Tax Code of the position (e.g. "A" or "B")
33+
* @return string|NULL
34+
* @todo support tax amount
3135
*/
32-
public function getPriceTotal(): float {
33-
if($this->priceTotal !== null) {
34-
return $this->priceTotal;
35-
}
36-
if($this->priceSingle !== null && $this->amount !== null) {
37-
return $this->priceSingle * $this->amount;
38-
}
39-
if($this->priceSingle !== null && $this->weight !== null) {
40-
return $this->priceSingle * $this->weight;
41-
}
42-
throw new ReceiptParseException();
36+
public function getTaxCode(): ?string {
37+
return $this->taxCode;
38+
}
39+
40+
public function getReceipt(): Receipt {
41+
return $this->receipt;
4342
}
4443

4544
/**
46-
* The single value for one unit of the product
47-
*
48-
* @return float
4945
* @throws ReceiptParseException
5046
*/
51-
public function getPriceSingle(): float {
47+
public function getSinglePrice(): float {
5248
if($this->priceSingle !== null) {
5349
return $this->priceSingle;
5450
}
55-
if($this->priceTotal !== null && $this->amount !== null) {
56-
return $this->priceTotal / $this->amount;
57-
}
58-
if($this->priceTotal !== null && $this->weight !== null) {
59-
return $this->priceTotal / $this->weight;
51+
if($this->priceTotal !== null && $this->quantity !== null) {
52+
return $this->priceTotal / $this->quantity;
6053
}
6154
if($this->priceTotal !== null) {
6255
return $this->priceTotal;
6356
}
6457
throw new ReceiptParseException();
6558
}
6659

67-
/**
68-
* The Tax Code of the position (e.g. "A" or "B")
69-
*
70-
* @return string|NULL
71-
*/
72-
public function getTaxCode(): ?string {
73-
return $this->taxCode;
60+
public function getQuantity(): float {
61+
return $this->quantity ?? 1.0;
7462
}
7563

7664
/**
77-
* The weight of the position (if the product is weightable)
78-
*
79-
* @return float|NULL
65+
* @throws ReceiptParseException
8066
*/
81-
public function getWeight(): ?float {
82-
return $this->weight;
67+
public function getTotalPrice(): float {
68+
if($this->priceTotal !== null) {
69+
return $this->priceTotal;
70+
}
71+
if($this->priceSingle !== null && $this->quantity !== null) {
72+
return $this->priceSingle * $this->quantity;
73+
}
74+
throw new ReceiptParseException();
8375
}
8476

85-
/**
86-
* The amount of the position (if the product is countable)
87-
*
88-
* @return int|NULL
89-
*/
90-
public function getAmount(): ?int {
91-
if($this->amount === null && $this->weight === null) {
92-
return 1;
93-
}
94-
return $this->amount;
77+
public function getTax(): float {
78+
// TODO: Implement getTax() method.
79+
return -1;
9580
}
9681

9782
public function setName(string $name): void {
@@ -110,12 +95,7 @@ public function setTaxCode(string $taxCode): void {
11095
$this->taxCode = $taxCode;
11196
}
11297

113-
public function setWeight(float $weight): void {
114-
$this->weight = $weight;
115-
}
116-
117-
public function setAmount(int $amount): void {
118-
$this->amount = $amount;
98+
public function setQuantity(float $quantity): void {
99+
$this->quantity = $quantity;
119100
}
120-
121101
}

0 commit comments

Comments
 (0)