Download the PHP package mlocati/nexi-xpay-web without Composer
On this page you can find all versions of the php package mlocati/nexi-xpay-web. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package nexi-xpay-web
MLocati's unofficial Nexi XPay Web client library for PHP
This project contains a PHP library that makes it easy to use the Nexi XPay Web APIs (for Intesa Sanpaolo bank).
This requires an API Key. If instead you have a Terminal Alias and a MAC Key, you may need to use this other library.
It has been built (almost) automatically from the official documentation (see the /build
directory, which is only available if you clone this repository).
Installation
Install with composer
Simply run the following command:
Manual installation
Download the code of this library, place it somewhere in your project, and add this PHP instruction before using anything of this library:
Usage
Configuration
First of all, you have need an API Key (generated by your XPay back office).
For test environment, you can use the value of the MLocati\Nexi\XPayWeb\Configuration::DEFAULT_APIKEY_TEST
constant.
You also need the base URL of the Nexi XPay Web API.
You can find them again in MLocati\Nexi\XPayWeb\Configuration
:
- for test environments: you can use
MLocati\Nexi\XPayWeb\Configuration::DEFAULT_BASEURL_TEST
- for production environments: you can use
MLocati\Nexi\XPayWeb\Configuration::DEFAULT_BASEURL_PRODUCTION
This library provides an easy way to represent a configuration, by using the MLocati\Nexi\XPayWeb\Configuration\FromArray
class:
Of course you can override the default base URL (use the baseUrl
array key).
You can also use a custom class, provided it implements the MLocati\Nexi\XPayWeb\Configuration
interface.
The Nexi Client
The main class of this library is MLocati\Nexi\XPayWeb\Client
: it allows you invoking the Nexi APIs.
You can create an instance of it simply with:
HTTP Communications
The Nexi client needs to perform HTTP requests. In order to do that, it automatically detects the best available way to do that:
- if the cURL PHP extension is available, it uses it (see the
MLocati\Nexi\XPayWeb\HttpClient\Curl
class) - otherwise, if the PHP HTTP stream wrapper is enabled, it uses it (it requires the OpenSSL PHP extension - see the
MLocati\Nexi\XPayWeb\HttpClient\StreamWrapper
class)
You can also provide your own implementation, provided it implements the MLocati\Nexi\XPayWeb\HttpClient
interface.
That way you can easily log the communication with the Nexi servers, as well as customize the HTTP client (for example because you are behind a proxy).
For example, if you want to use your custom HTTP client implementation, you can simply write:
The Correlation-Id
Header
Every request to the Nexi servers is associated to an unique identifier, sent via an HTTP header named Correlation-Id
.
By default, the Next client randomly generates it and doesn't store it.
If you want to generate the value of the Correlation-Id
header on your own, or if you want to log the generated Correlation-Id
values, you can create a custom class that implements the MLocati\Nexi\XPayWeb\CorrelationProvider
interface.
Then, when you create the Nexi client, you can write some code like this:
Sample Usage
The methods provided by Nexi client has well documented documentation (see the PHPDoc comments). The Nexi client provided by this library allows you to use all the methods you can find in the Nexi documentation website.
Here's a sample code that allows you to accept payments:
-
Your customer is on your website and clicks a "Pay" button which invokes a route on your project that executes this code:
- you then redirects your customer to the URL provided by
$response->getHostedPage()
- when the customer pays on the Nexi website, he is redirected to your website at the URL used in the
setResultUrl()
above. When that URL is called, you can have some code like this:
All versions of nexi-xpay-web with dependencies
ext-json Version *