crefopay/php-clientlibrary

一个用于简化CrefoPay Web-API实现的PHP库

3.0.1 2024-07-05 12:15 UTC

README

CrefoPay API的PHP客户端库。基于以下API文档:[https://docs.crefopay.de/api/](https://docs.crefopay.de/api/)。关于此库的问题,请发送电子邮件至service@crefopay.de

已知问题

以下问题已知,将在后续版本中添加

  • 未报告问题

安装库

将两个文件夹 srcvendor 复制到您的项目的库路径中。在您的应用程序中注册库路径,并在代码中使用composer自动加载器

require_once 'vendor/autoload.php';

使用库

有关详细信息,请参阅此存储库的文档

请求

请求库分为三个部分

```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.