Giter Club home page Giter Club logo

swisspaymentslip's Introduction

SwissPaymentSlip - Swiss Payment Slips

Travis Build Status Scrutinizer CI Build Status Scrutinizer CI Code Coverage Scrutinizer CI Code Quality Total Downloads Latest Stable Version

Do you need to create Swiss payment slips (called ES or ESR) as PDF files in a project of yours? Then you found almost the right place, go to SwissPaymentSlipFpdf or SwissPaymentSlipTcpdf.

If you need to include some basic logic for Swiss payment slips in your PHP code base then you are probably right though...

The partial and unfinished support for the red payment slip was dropped in version 0.13.0 due to lack of demand.

How to use

Just install the the package (see Installation) and check out the contained examples in the examples folder.

If you need help for extending and/or customizing the library to your needs, just ask for help.

Installation

Requirements

  • PHP 5.6.x+

Composer

To add this library to your project through Composer, install Composer on your system first, then initialize a composer.json file and then execute the following from within your project's folder:

$ php composer.phar require "swiss-payment-slip/swiss-payment-slip"

Background Story

In february 2013 I was looking for a solution to create swiss payment slips for a project I had to do at my work place. After a short Google search I came across Manuel Reinhard's blog post about the class he made for that. On his Github project's page I found Peter Siska's pull request. His pull request introduced PSR-0 compatibility and he created a composer package on Packagist. So I tried Peter's version and it suited my basic needs.

BUT since the customer I was working for used custom designed payment slips I couldn't use Manuel's/Peter's script since it wasn't flexible enough. Now I had to decide whether I want to "just" change the script to fit my needs or to rewrite it and make it as flexible as possible. I decided myself for the latter.

TODOs

  • Improve code documentation
  • Add more examples/improve existing ones, showcase disabling the various field blocks better
  • Improve the tests
  • Release the stable release of the API

Submitting bugs and feature requests

Bugs and feature request are tracked on GitHub.

Author

This project was created by Marc Würth. See Background Story for more details.

License

SwissPaymentSlip is licensed under the MIT License. See the LICENSE file for details.

Thanks to

swisspaymentslip's People

Contributors

d4rkmindz avatar ravage84 avatar steampilot avatar tekkcraft avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swisspaymentslip's Issues

Improve ESR pictures

The pictures used in the library are not ideal (especially the colors and contrast) and a version without a bank is missing. Postfinance has better ones available on their website in PDF format. If somebody is interested in implementing them or if you are searching for them (because it took me quite some time to find them), they can be found here:

https://www.postfinance.ch/de/cust/download/bizdoc.html

I have also created a drop-in replacement of the orange ESR gif specifically without bank:

esr_ohne_bank

If somebody wants to use it, this is how (with this class and the new gif in the same directory):

use SwissPaymentSlip\SwissPaymentSlip\OrangePaymentSlip;

class ImprovedOrangePaymentSlip extends OrangePaymentSlip
{
  /**
   * Sets the default attributes of the elements for an orange slip
   *
   * @return $this The current instance for a fluent interface.
   */
  protected function setDefaults()
  {
    parent::setDefaults();

    $this->setSlipBackground(__DIR__.'/esr_ohne_bank.gif');

    $this->setRecipientLeftAttr(3, 15, 50, 4);
    $this->setRecipientRightAttr(66, 15, 50, 4);

    return $this;
  }
}

Sub classing the orange and red payment slips

Instead of using a monolithic design for all payment slips (currently orange and red), it would make the library more atomic if we would put the specific logic for red and orange slips (and any other) into sub classes, while preserving all common code in a generalized payment slip class.

That could look like this for the data classes:

  • RedSlipData extends PaymentSlipData
  • OrangeSlipData extends PaymentSlipData

And for the slip classes:

  • RedSlip extends PaymentSlip
  • OrangeSlip extends PaymentSlip

Implement a fluent interface

Currently the libary returns true or false in most cases, in some always true, which does not make much sense.

A fluent interface would make the the API more comfortable.

Support clarification

Hi Marc Würth!
Just a clarification. The readme document says about using the library to produce Einzahlungsschein as PDFs.
Have you ever used the library to print on pre-printed Einzahlungsschein?

Using setSlipBackground(null); it is possible to print without a background. Just wondering how accurate it is in filling the fields on a pre-printed Einzahlungsschein.

Thanks in advance for any advice you can give!
Frederick

ISO 20022

Dear Marc,

Is there any plan to adapt your library with new standard ISO 20022 which include QR Code?

Best regards and thanks for your very useful work 👍

Uncaught TypeError under PHP 7.0+

An uncaught type error appears under PHP 7.0+:

PHP Fatal error: Uncaught TypeError: Argument 1 passed to SwissPaymentSlip\SwissPaymentSlip\PaymentSlip::__construct() must be an instance of SwissPaymentSlip\SwissPaymentSlip\PaymentSlipData, null given, called in /home/travis/build/ravage84/SwissPaymentSlip/tests/PaymentSlipTest.php on line 100 and defined in /home/travis/build/ravage84/SwissPaymentSlip/src/PaymentSlip.php:252

PHP 7.0 https://travis-ci.org/ravage84/SwissPaymentSlip/jobs/261917191
PHP 7.1 https://travis-ci.org/ravage84/SwissPaymentSlip/jobs/261917192
PHP 7.2 https://travis-ci.org/ravage84/SwissPaymentSlip/jobs/261917193

Wrong return value in getAmountCents()

I have set 2714.05 with setAmount().
In the return value from function $paymentSlipData->getAmountCents() it is
2714.50.

The bug is in the code line 840 in PaymentSlipData.php

$ret = str_pad($cents, 2, '0', STR_PAD_RIGHT);

STR_PAD_RIGHT should be STR_PAD_LEFT then it works correctly.

Rework the tests

With so many changes done (mainly the sub classing), the tests probably do not reflect the actual code well enough anymore.

Also there is quite some duplicated/less optimal test code.

Use an object for attributes

Currently an array of attribute settings describes where and how an element is places/displayed.

This leads to quite some amount of redundant code, such as the setAttributes() method.
This could be improved by using an object which encapsulates the attribute settings and the logic to set and retrieve these settings.

Each set of attribute settings contains the following attributes:

  • posX
  • posY
  • width
  • height
  • background
  • fontFamily
  • fontSize
  • fontColor
  • lineHeight
  • textAlign

Each element has it's own default attribute settings (depending on the type of payment slip).

Update to PHPUnit 4.x

Currently we use PHPUnit 3.7.38 which is EOL.
We should update to PHPUnit 4.x, possibly to the latest version.

Update code to PHP 5.4

Currently the code requires PHP 5.3 as a minimum.
Since PHP 5.3 is EOL we should update the code to PHP 5.4 which would enable us to use the array short syntax.

Make better use of Exceptions

Currently the libary does not throw exceptions, e.g. in case of invalid inputs or if a disabled element is requested.

I'm not sure if throwing an exception in case someone requests a disabled element actually makes sense but in case of an invalid input it certainly is the better way than to either just don't set it it and not give any feedback or to not set it and return a simple false.

Implement full red slip support

Formatting Individual Recipient Data Lines

Hi!
First of Marc Würth thanks for your hard work on this and the other Swiss Payment Slip PHP classes.
I am guessing from the todo on line 57 of PaymentSlipData.php:

  • @todo Create a getRecipientData with formatting parameter, e.g. stripping blank lines

that there is currently no way to format individual lines of the RecipientData.

I found the public functions:
setRecipientLeftAttr()
getRecipientLeftAttr()
setRecipientRightAttr()
getRecipientRightAttr()

However it appears they set the same attributes for the Left or Right printings of the Recipient Data. I am guessing that new functions that allow setting the attributes on a per line bases would need to be added to do this.

My use case is the company name on line one of the recipient data lines is in a different font from the default and the company slogan on line two is in another different font from the default.

In any case just wanted to confirm that I was understanding this correctly.
God Bless!
Frederick

setNotForPayment() should respect disabled data

Currently the setNotForPayment() method does not respect if a certain field is disabled.
Thus if a field is disabled and someone calls setNotForPayment()it will result in a DisabledDataException.

All data classes are affected:
https://github.com/ravage84/SwissPaymentSlip/blob/0.11.1/src/OrangePaymentSlipData.php#L195-L196
https://github.com/ravage84/SwissPaymentSlip/blob/0.11.1/src/PaymentSlipData.php#L856-L860
https://github.com/ravage84/SwissPaymentSlip/blob/0.11.1/src/RedPaymentSlipData.php#L342-L343

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.