crefopay/php-clientlibrary

PHP Library for the Crefopay API

1.2.4 2021-03-15 16:59 UTC

README

PHP Client Library for the CrefoPay API. Based on the API Documentation found here: https://docs.crefopay.de/api/ For questions regarding this library please send an email to service@crefopay.de

Known Issues

The following issues are known and will be added in coming versions:

  • No issues reported

Installing the Library

Copy the two folders src and vendor to the library path of your project. Register the path of the library in your application and use the composer autoloader in your code:

require_once 'vendor/autoload.php';

Using the Library

For extensive information, please refer to the docs of this repository

Requests

The Library for requests is split in three parts:

```Upg\Library\Request\Objects``` contains classes for the JSON objects that are documented in the API documentation.
If a request has a property that requires a JSON object please pass in the appropriately populated ```Upg\Library\Request\Objects``` class for that property.

All properties in the request and JSON objects have getters and setters. For example, to set a field called userType on the request or object you would call `setUserType` and to get it you would call `getUserType`.

### Sending requests ###
Once you have populated a request object with the appropriate values simply create an instance of a ```Upg\Library\Api```
class for the appropriate method call. Pass in a config object and the request you want to send. Then call the
`sendRequest()` method to send the response. This method might raise an Exception or provide an object of the class SuccessResponse.

The exceptions which can be raised are in ```Upg\Library\Api\Exception```.
For any parsed responses you will have access to an ```Upg\Library\Response\SuccessResponse``` or ```Upg\Library\Response\FailureResponse``` object.
The SuccessResponse object is returned if no exception is thrown.
The FailureResponse object is returned in a ```Upg\Library\Api\Exception\ApiError``` exception.

## Handling MNS notifications ##

The library provides a helper class to validate MNS notifications:
```Upg\Library\Mns\Handler```

It takes the following as a constructor:

  * $config: The config object for the integration
  * $data: The data from the post variables which should be an associated array of the MNS callback
  * $processor: An instance of a class which implements the ```Upg\Library\Mns\ProcessorInterface```, which the method will invoke after validation.

The processor object should implement `sendData` to get data from the handler and a `run` method which executes your callback after successful validation.

The processor callback should avoid processing the request, instead it should save it to a database for asynchronous processing via a cron script.

If you use the handler class to save a MNS to the database for later processing you can assume the MNS is perfectly valid with out checking the MAC.

Please note the MNS call must always return a 200 response to CrefoPay otherwise the CrefoPay system will retry to send this notification and eventually lock the MNS queue for your system.

## Working on the library ##

If you want to contribute to the library, please note that all code should be written according to the **PSR2 standard**.
There are many tools to conform to this standard, e.g. PHP-Codesniffer or PHP Coding Standards Fixer.
We will also specify a contributing guideline in the future.