rikudou / pay-by-square-decoder
Decoder for the Pay By Square standard
Installs: 86
Dependents: 0
Suggesters: 1
Security: 0
Stars: 1
Watchers: 2
Forks: 3
Open Issues: 0
Type:symfony-bundle
Requires
- php: ^7.1
Requires (Dev)
- friendsofphp/php-cs-fixer: ^2.16
- phpstan/phpstan: ^0.12.14
- symfony/framework-bundle: >=4.4
Suggests
- rikudou/skqrpayment: If you want to encode payments using Pay By Square standard
- symfony/framework-bundle: Version 4.4 or greater, if you want this package to work with symfony
This package is auto-updated.
Last update: 2024-12-12 04:52:05 UTC
README
This library decodes the string encoded according to the Slovakian Pay By Square standard.
This package can be used as a standalone library or a Symfony bundle
Installing
composer require rikudou/pay-by-square-decoder
Requirements
You must have the xz
binary from xz-utils
in your system.
Usage
The class \Rikudou\BySquare\Decoder\PayBySquareDecoder
has a
public method called decode
which accepts a string argument with
the encoded data.
Example:
<?php use Rikudou\BySquare\Decoder\PayBySquareDecoder; $encodedData = '0006Q0000UAT63HVES6GL5A5A0O9NSPEEHUHIEP70EG9LM6LU6EBNQ8KG6RB2N2LUIHMVTV51KQ77DGFC25KM2S9V46EQSN5GSD9J1N4BKT1L9ASVOOT1LPOMAO66IS2BHJDCNA4D9LFKG9MTFLISBD36O5CQQNJIBB2TJILQVVN684000'; $decoder = new PayBySquareDecoder(); $decodedData = $decoder->decode($encodedData); // $decodedData is now an instance of \Rikudou\BySquare\VO\DecodedBySquareData
If the xz
binary is not in your PATH
you must set the path
first:
<?php use Rikudou\BySquare\Decoder\PayBySquareDecoder; $decoder = new PayBySquareDecoder(); $decoder->setXzBinary('/path/to/xz'); $decodedData = $decoder->decode($encodedData); // $decodedData is now an instance of \Rikudou\BySquare\VO\DecodedBySquareData
Advanced configuration
The \Rikudou\BySquare\Decoder\PayBySquareDecoder
takes a configuration
object as a first argument, where some advanced configuration can take place.
If no configuration object is provided, one with default values is created.
Currently only partial data config is available.
<?php use Rikudou\BySquare\Decoder\PayBySquareDecoder; use Rikudou\BySquare\Config\PayBySquareDecoderConfiguration; $config = new PayBySquareDecoderConfiguration(); $config ->setAllowPartialData(false); $decoder = new PayBySquareDecoder($config);
Options
- allow partial data
- type:
bool
- default:
true
- methods:
setAllowPartialData(bool)
/isPartialDataAllowed()
- description: The xz binary can sometimes fail due to unexpected end of input because of numerous reasons which often are not an issue. When set to true, the decoder will accept the partial data even if xz thinks it's incomplete.
- type:
Usage in Symfony
If you use Symfony flex, the package should be configured
automatically, if not, just add \Rikudou\BySquare\RikudouPayBySquareDecoderBundle
to your config/bundles.php
.
You can now use Rikudou\BySquare\Decoder\PayBySquareDecoder
as
a service:
<?php use Rikudou\BySquare\Decoder\PayBySquareDecoder; class MyService { /** * @var PayBySquareDecoder */ private $decoder; public function __construct(PayBySquareDecoder $decoder) { $this->decoder = $decoder; } }
If your xz
binary is not in your path, you can create a config
file in config/packages/rikudou_pay_by_square_decoder.yaml
and change the path, here is the default config (generated using
config:dump
command):
# Default configuration for extension with alias: "rikudou_pay_by_square_decoder" rikudou_pay_by_square_decoder: # The path to the xz binary, null means auto detect xz_path: null # Whether to continue even if decoding fails due to unexpected end of input and only partial data are available allow_partial_data: true
Return values description
The decode
method returns an instance of \Rikudou\BySquare\VO\DecodedBySquareData
which is a value object. The method names are self-explanatory
in most cases.
getVersion(): int
- returns the Pay By Square version, currently only version 0 is supportedgetPaymentId(): ?string
- internal payment idgetPaymentsCount(): int
- the count of payments the encoded string containsisRegularPayment(): bool
- returns true if the payment is a standard one-off paymentgetAmount(): float
- the payment amountgetCurrency(): ?string
- the three-letter ISO currency codegetDueDate(): ?DateTime
- returns the due date, if no due date was given returns the date 1970-01-01getVariableSymbol(): ?int
- returns variable symbol if present, null otherwisegetConstantSymbol(): ?int
- returns constant symbol if present, null otherwisegetSpecificSymbol(): ?int
- returns specific symbol if present, null otherwisegetPayerReference(): ?string
- returns the payer reference, e.g. a variable, constant and specific symbol as a single string
Note: The payer reference and variable/constant/specific symbols are NOT constructed from each other but taken directly from the payment data, meaning you should check for both if you're looking for e.g. variable symbol
getNote(): ?string
- returns the note/commentgetIbanCount(): int
- returns the count of IBANs present in encoded stringgetIban(): IBAN
- returns the first IBAN - if no IBANs are present it throws an exceptiongetIbans(): iterable<IBAN>
- returns an iterable of all IBANs presentisStandingOrder(): bool
- whether the payment is a standing orderisDirectDebit(): bool
- whether the payment is a direct debitgetPayeeName(): ?string
- returns the name of the payeegetPayeeAddressLine1(): ?string
- returns the address line 1 of the payeegetPayeeAddressLine2(): ?string
- returns the address line 2 of the payee
The methods getIban
and getIbans
return \Rikudou\BySquare\VO\IBAN
(or iterable of it) which is a really simple value object with
two methods:
getIban(): ?string
- returns the IBANgetBic(): ?string
- returns the BIC/SWIFT code
Exception handling
The only exception thrown by this library is
\Rikudou\BySquare\Exception\PayBySquareException