Redsys Virtual POS is an unofficial standalone PHP library to handle payments through the spanish payment service Redsys.
NOTE: This library its been used in production for over a year now (as Oct. 2015) but its still under development and its functionality is subject to change.
- PHP 5.6 or above
Installation is recommended through Composer.
$ composer require nkm/redsys-virtual-pos
Go to the sample
folder an run the following command in a terminal to start PHP's built-in web server:
# install dependencies
$ composer install
# start the server
$ php -S 0.0.0.0:8000
Then open your browser and go to here.
If you want to test the online (async) response, replace localhost
with your public IP or hostname, making sure that your machine is accesible through the port 8000 (you can use another port if you want).
Basic usage:
use nkm\RedsysVirtualPos\Message\WebRequest;
use nkm\RedsysVirtualPos\Field\Currency;
use nkm\RedsysVirtualPos\Field\TransactionType;
$secret = 'sq7HjrUOBfKmC576ILgskD5srU870gJ7';
$merchantCode = '999008881';
$terminal = '1';
// The Environment object holds connection details
$env = new nkm\RedsysVirtualPos\Environment\DevelopmentEnvironment();
$env->setSecret($secret);
// Setup the Parameters for the Request
$params['Amount'] = '145'; // €1,45
$params['Order'] = strval(time());
$params['MerchantCode'] = $merchantCode;
$params['Currency'] = Currency::EUR;
$params['TransactionType'] = TransactionType::STANDARD;
$params['Terminal'] = $terminal;
$params['MerchantName'] = 'Test Store'; // optional
$params['ProductDescription'] = 'Product Description'; // optional
$params['UrlOk'] = 'http://localhost:8000/success.php'; // optional
$params['UrlKo'] = 'http://localhost:8000/failure.php'; // optional
// Generate the Request
$webRequest = new WebRequest($env);
$webRequest->setParams($params);
// Generate the form
$submitBtn = "<p><input type='submit' value='Submit'></p>";
$wrForm = $webRequest->getForm([], $submitBtn);
// Render the HTML form w/ Submit button
echo $wrForm;
See sample/index.php
and sample/response.php
for more detailed examples.
Run the following command in a terminal:
# install dependencies
$ composer install
# run the tests
$ phpunit
- Normalize documentation filenames
- Hotfix
- Add request fields:
Ds_Merchant_Acquirer_Identifier
,Ds_Merchant_Cof_Ini
,Ds_Merchant_Cof_Txnid
,Ds_Merchant_Cof_Type
,Ds_Merchant_Customer_Mail
,Ds_Merchant_Customer_Mobile
,Ds_Merchant_Customer_Sms_Text
,Ds_Merchant_Dcc
,Ds_Merchant_DirectPayment
,Ds_Merchant_Emv3ds
,Ds_Merchant_Excep_Sca
,Ds_Merchant_Group
,Ds_Merchant_Identifier
,Ds_Merchant_IdOper
,Ds_Merchant_MatchingData
,Ds_Merchant_MerchantDescriptor
,Ds_Merchant_MpiExternal
,Ds_Merchant_P2f_ExpiryDate
,Ds_Merchant_P2f_XmlData
,Ds_Merchant_PayMethods
,Ds_Merchant_PersoCode
,Ds_Merchant_ShippingAddressPyp
,Ds_Merchant_Tax_Reference
,Ds_Merchant_Terminal
,Ds_Merchant_Titular
,Ds_Merchant_TransactionDate
,Ds_Merchant_TransactionType
,Ds_Merchant_UrlKo
,Ds_Merchant_UrlOk
,Ds_Merchant_XPayData
,Ds_Merchant_XPayOrigen
andDs_Merchant_XPayType
- Add response fields:
Codigo
,Ds_Merchant_Cof_Txnid
,Ds_DCC
,Ds_Merchant_Identifier
andDs_UrlPago2Fases
- Update field name cases
- Add documentation
- Add undocumented field
DS_Card_Brand
- Add undocumented field
DS_MerchantPartialPayment
(only used by CaixaBank’s Cyberpac) - Add documentation for CaixaBank’s Cyberpac
- Update Redsys’ official documentation
- Fix field names on params array indices
- Fix missing case-sensitive renames (OSX, Y U NO CS?)
- Refactoring of the Sample
- Minor fixes in sample
- Add support new cryptographic algorithm (SHA-2, HMAC_SHA256_V1) for message signing
- Update for the new Redsys API
- General overhaul and simplification
- Improve sample with request/response support, logging and detailed reporting
- Update documentation (Redsys and Banco Sabadell)
- Handle unknown or empty Error and Response codes gracefully
- Translate response type descriptions and error messages to Spanish for consistency
- Improve naming of response types
Response::getType()
now returns the type name instead of its description- Rename
AbstractMessage::getFieldClassName()
toAbstractMessage::resolveFieldClassName()
- Lowercase field key names in order to ease integration with databases
- Add method
Field\Response::getTypeDescription()
- Other minor fixes and improvements
- Rename the response fields to match Redsys's Online Response ones
- Add Error Code field to the Response
- Add source implementation docs
Initial (stealth) release
The BSD 3-Clause License
Copyright (c) 2015, Javier Zapata All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
-
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
-
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
-
Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.