Download the PHP package cakasim/payone-sdk without Composer
On this page you can find all versions of the php package cakasim/payone-sdk. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cakasim/payone-sdk
More information about cakasim/payone-sdk
Files in cakasim/payone-sdk
Package payone-sdk
Short Description A SDK for PAYONE payment integration.
License MIT
Homepage https://cakasim.de
Informations about the package payone-sdk
SDK for PAYONE Payment Integration
Introduction
The SDK for PAYONE Payment Integration helps you to integrate payment into your app. The SDK makes use of the PAYONE Server API which is quite feature rich but has aged and direct use may be uncomfortable.
Features
- Modern interface and robust concepts to make using this SDK a pleasure
- Flexible design and extendable structure for tailored solutions
- Simple yet powerful use of the PAYONE Server API
- Automatic processing of PAYONE Notifications
- Secure redirect URL generation with state data payload for redirect payments
Requirements
- At least PHP 7.1
- Composer Dependency Manager
Although the SDK uses Composer, it does not have extensive dependencies on other packages. Currently, the only dependencies are on PSR interfaces.
License
The SDK for PAYONE Payment Integration is open-sourced software licensed under the MIT license.
Installing the SDK
Just run composer require cakasim/payone-sdk
to install the SDK via composer.
Core Concepts
The SDK is based on several core principles that should make it easy to use and flexible to integrate.
- Sensible Defaults. A useful and functional default configuration allows easy bootstrapping of the SDK without extensive initialization of dependencies.
- Inversion of Control. A simple IoC implementation using constructor parameter injection allows a central modification of relevant components.
- Services. Service classes make individual components of the SDK and their features accessible.
PSR Interfaces
The use of PSR interfaces allows a high degree of adaptability to an existing system that already provides PSR compatible components.
The SDK makes use of the following PSR interfaces:
- PSR-3, Logger Interface
- PSR-11, Container Interface
- PSR-7, HTTP Message Interfaces
- PSR-17, HTTP Factories
- PSR-18, HTTP Client
Using the SDK
This section explains how to use the SDK. Various code examples are given. For reasons of clarity, general code components have been omitted (e.g. use statements).
Construct the SDK
To use the SDK, the main class Sdk
must be instantiated. There are three different
ways to do that.
Variant 1 – Using All Defaults
This variant is the easiest to get started. The SDK will be constructed using all defaults which requires you to install some default PSR implementation packages:
cakasim/payone-sdk-http-message
(PSR-7, PSR-17)cakasim/payone-sdk-stream-client
(PSR-18)cakasim/payone-sdk-silent-logger
(PSR-3)
Now you are able to construct the SDK with just a single line of code:
Variant 2 – Replacing Defaults by Providing Other Bindings
In order to change defaults you may override the default container bindings with your own or even third-party implementations. This enables a deep integration of the SDK into any existing environment which already provides PSR implementations.
Variant 3 – Deeply Integrate with Existing IoC Environments
Often you will have a scenario with an already existing PSR-11 compatible IoC container which provides constructor parameter DI. In such cases you may replace the SDK container completely with the existing one.
You will have to provide all necessary bindings by yourself. Have a look at the
src/ContainerBuilder.php
source to get an idea of the required bindings.
Once you have configured the existing container you may use it to instantiate the SDK:
For all following examples we assume that the variable $sdk
contains the Sdk
instance.
Configure the SDK
The SDK requires various configuration parameters to be set. These parameters
must be provided via the Config
class. Some parameters have sane defaults and
others need to be set. Have a look at the table below which lists all parameters.
Parameter | Type | Default | Description |
---|---|---|---|
api.endpoint |
string |
https://api.pay1.de/post-gateway/ |
PAYONE Server API endpoint |
api.merchant_id |
string |
required | Merchant ID of your PAYONE account |
api.portal_id |
string |
required | Portal ID which can be configured in your PAYONE account |
api.sub_account_id |
string |
required | ID of your configured sub-account |
api.mode |
string |
test |
API mode, choose between test or live |
api.key |
string |
required | PAYONE Server API endpoint |
api.key_hash_type |
string |
sha384 |
API key hashing method |
api.integrator_name |
string |
required | Name of your app or company |
api.integrator_version |
string |
required | Version of your app |
notification.sender_address_whitelist |
string[] |
Valid sender IP list | List of valid sender IPs |
redirect.url |
string |
required | Redirect URL template, use $token as placeholder for the actual token value |
redirect.token_lifetime |
int |
3600 |
Redirect token lifetime (in seconds) |
redirect.token_encryption_key |
string |
required | Encryption key for redirect tokens |
redirect.token_encryption_method |
string |
aes-256-ctr |
Encryption method for redirect tokens |
redirect.token_signing_key |
string |
required | Signing key for redirect tokens |
redirect.token_signing_algo |
string |
sha256 |
Signing algorithm for redirect tokens |
The following example shows how to set all required parameters.
Sending API Requests
The following example shows how to send a simple API request that pre-authorizes a debit payment. There is no need to set global API parameters (e.g your API credentials) because the SDK uses the config to set them before sending the actual request.
Handling Notifications From PAYONE
With the SDK, PAYONE notifications can be easily processed. The SDK takes important steps in the verification and mapping of notifications.
The Redirect Service
For certain payment methods the customer will be redirected to a third party service (PayPal, Sofortüberweisung, etc.) in order to authenticate and authorize the payment.
The SDK can set the successurl
, errorurl
and backurl
API request parameters for you to specify the
target URL a customer will be redirected to after he finishes the third party service process. Furthermore, the SDK
appends a token to the target URL.
The token holds metadata (e.g. creation timestamp) as well as custom data you may set. The token itself will be encrypted and signed which ensures protection of the payload data against unauthorized access and modification. Additionally, the SDK verifies the age of the token and ensures it does not exceed the configured max age.
Apply Redirect Parameters to an API Request
The example below shows how to apply redirect parameters to a (pre-)authorization API request. The API response
has a status of REDIRECT
and a redirecturl
parameter which must be used to redirect the customer.
In some scenarios a redirect is not always necessary, the example covers this as well.
Process a Redirect Token
If a customer returns to your app you first need to read the redirect token. The SDK does not make any assumptions how this should be done. Basically using a simple query parameter is a sane and totally valid approach.
Have a look at the example below which shows you how to process the token and access the token payload data.
All versions of payone-sdk with dependencies
ext-json Version *
ext-openssl Version *
psr/http-message Version ^1.0
psr/http-client Version ^1.0
psr/http-factory Version ^1.0
psr/log Version ^1.1
psr/container Version ^1.0