Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
105 changes: 105 additions & 0 deletions src/DataTypes/EPC.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace SimpleSoftwareIO\QrCode\DataTypes;

class EPC implements DataTypeInterface
{
/**
* The prefix of the QrCode.
*
* @var string
*/
protected $prefix = 'epc:';

/**
* The BIC.
*
* @var string
*/
protected $bic;

/**
* The iban.
*
* @var string
*/
protected $iban;

/**
* The amount of credit_transfer.
*
* @var string
*/
protected $amount;

/**
* The Name of the Beneficiary.
*
* @var string
*/
protected $name;

/**
* The text.
*
* @var string
*/
protected $text;

/**
* Generates the DataType Object and sets all of its properties.
*
* @param $arguments
*/
public function create(array $arguments)
{
$this->setProperties($arguments);
}

/**
* Returns the correct QrCode format.
*
* @return string
*/
public function __toString()
{
$string = "BCD\n";
$string .= "002\n";
$string .= "2\n";
$string .= "SCT\n";
$string .= $this->bic."\n";
$string .= $this->name."\n";
$string .= $this->iban."\n";
$string .= 'EUR'.number_format($this->amount, 2)."\n";
$string .= "\n";
$string .= "\n";
$string .= $this->text."\n";

return $string;
}

/**
* Sets the properties.
*
* @param $arguments
*/
protected function setProperties(array $arguments)
{
$arguments = $arguments[0];
if (isset($arguments['bic'])) {
$this->bic = $arguments['bic'];
}
if (isset($arguments['iban'])) {
$this->iban = $arguments['iban'];
}
if (isset($arguments['amount'])) {
$this->amount = $arguments['amount'];
}
if (isset($arguments['name'])) {
$this->name = $arguments['name'];
}
if (isset($arguments['text'])) {
$this->text = $arguments['text'];
}
}
}
55 changes: 55 additions & 0 deletions tests/DataTypes/EPCTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

use PHPUnit\Framework\TestCase;
use SimpleSoftwareIO\QrCode\DataTypes\EPC;

class EPCTest extends TestCase
{
public function testToString()
{
$arguments = [
'bic' => 'BIC123',
'iban' => 'IBAN456',
'amount' => '1000.50',
'name' => 'John Doe',
'text' => 'Test payment',
];

$epc = new EPC();
$epc->create([$arguments]);

$expected = "BCD\n";
$expected .= "002\n";
$expected .= "2\n";
$expected .= "SCT\n";
$expected .= $arguments['bic']."\n";
$expected .= $arguments['name']."\n";
$expected .= $arguments['iban']."\n";
$expected .= 'EUR'.number_format($arguments['amount'], 2)."\n";
$expected .= "\n";
$expected .= "\n";
$expected .= $arguments['text']."\n";

$this->assertEquals($expected, $epc->__toString());
}

public function testSetProperties()
{
$arguments = [
'bic' => 'BIC123',
'iban' => 'IBAN456',
'amount' => '1000.50',
'name' => 'John Doe',
'text' => 'Test payment',
];

$epc = new EPC();
$epc->create([$arguments]);

$this->assertEquals($arguments['bic'], $epc->getBic());
$this->assertEquals($arguments['iban'], $epc->getIban());
$this->assertEquals($arguments['amount'], $epc->getAmount());
$this->assertEquals($arguments['name'], $epc->getName());
$this->assertEquals($arguments['text'], $epc->getText());
}
}