1. Go to this page and download the library: Download dwmsw/sagepay library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dwmsw / sagepay example snippets
// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();
// New Basket instance
$basket = new dwmsw\sagepay\Basket();
// Add an item to the basket
$basket->addItem(new dwmsw\sagepay\Item('Test Item', 30.00, 6, 1));
// Add another item to the basket
$basket->addItem(new dwmsw\sagepay\Item('Test Item Two', 30.00, 6, 2));
// Add a discount
$basket->addDiscount(new dwmsw\sagepay\Discount(50.00, 'This is a discount'));
// Set the Basket
$sagepay->setBasket($basket);
// Set up the config
$sagepay->setConnectionMode(CONNECTION MODE TEST/LIVE);
$sagepay->setVendorName(YOUR VENDOR NAME);
$sagepay->setCurrency('GBP');
$sagepay->setApplyAvsCv2(1);
$sagepay->setApply3dSecure(0);
$sagepay->setGiftAid(0);
$vendorTxCode = md5(rand(1, 1000));
// TX Specific bits
$sagepay->setVendorTxCode($vendorTxCode);
$sagepay->setDescription('Test Payment');
$sagepay->setCustomerEmail('[email protected]');
// Set up addresses
$BillingAddress = new dwmsw\sagepay\Address();
$BillingAddress->setName('Daryll', 'Doyle');
$BillingAddress->setPhone('46554789658');
$BillingAddress->setAddress('88', 'Test Address', 'Town', 'GB', '412');
// Set Addresses into the class
$sagepay->setBillingAddress($BillingAddress);
// Delivery Address can be a different instance of address if needed
$sagepay->setDeliveryAddress($BillingAddress);
// New card instance
$card = new dwmsw\sagepay\Card();
// Card details
$card->setCardHolder('Mr D Doyle');
$card->setCardType('VISA');
$card->setCardNumber('4929000000006');
$card->setStartDate(false);
$card->setExpiryDate('1216');
$card->setCV2('123');
$sagepay->setCard($card);
$output = $sagepay->register('PAYMENT');
// Do whatever you want with $output
$sagepay->setCreateToken(1);
// New card instance
$card = new dwmsw\sagepay\Card();
$card->setToken('TOKEN');
$card->setCV2('CV2');
$sagepay->setCard($card);
// As above, but use the following line
$output = $sagepay->register('DEFERRED');
// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();
// Make the release
$output = $sagepay->release('VPSTxId', 'SecurityKey', 'vendorTxCode', 'TxAuthNo', 'AMOUNT TO RELEASE');
// Do whatever with $output
// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();
// Make the refund
$output = $sagepay->refund('NEWvendorTxCode', 'AMOUNT TO REFUND', 'OLDVPSTxId', 'OLDvendorTxCode', 'OLDSecurityKey', 'OLDTxAuthNo', 'Refund Message');
// Do whatever with $output
// Create instance of Direct
$sagepay = new dwmsw\sagepay\Direct();
$sagepay->setConnectionMode('test');
// Send the output back to Sagepay
$output = $sagepay->threeDResponse($_POST['MD'], $_POST['PaRes']);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.