File manager - Edit - /home/opticamezl/www/newok/sagepay.tar
Back
.travis.yml 0000604 00000000317 15173220556 0006660 0 ustar 00 language: php php: - 5.3 - 5.4 - 5.5 - 5.6 - hhvm before_script: - composer install -n --dev --prefer-source script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text CONTRIBUTING.md 0000604 00000001040 15173220556 0006772 0 ustar 00 # Contributing Guidelines * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * Commit just the modifications, do not mess with the composer.json or CHANGELOG.md files. * Ensure your code is nicely formatted in the [PSR-2](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md) style and that all tests pass. * Send the pull request. * Check that the Travis CI build passed. If not, rinse and repeat. phpunit.xml.dist 0000604 00000001512 15173220556 0007720 0 ustar 00 <?xml version="1.0" encoding="UTF-8"?> <phpunit backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" syntaxCheck="false"> <testsuites> <testsuite name="Omnipay Test Suite"> <directory>./tests/</directory> </testsuite> </testsuites> <listeners> <listener class="Mockery\Adapter\Phpunit\TestListener" file="vendor/mockery/mockery/library/Mockery/Adapter/Phpunit/TestListener.php" /> </listeners> <filter> <whitelist> <directory>./src</directory> </whitelist> </filter> </phpunit> README.md 0000604 00000003552 15173220556 0006032 0 ustar 00 # Omnipay: Sage Pay **Sage Pay driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-sagepay) [](https://packagist.org/packages/omnipay/sagepay) [](https://packagist.org/packages/omnipay/sagepay) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements Sage Pay support for Omnipay. ## Installation Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it to your `composer.json` file: ```json { "require": { "omnipay/sagepay": "~2.0" } } ``` And run composer to update your dependencies: $ curl -s http://getcomposer.org/installer | php $ php composer.phar update ## Basic Usage The following gateways are provided by this package: * SagePay_Direct * SagePay_Server For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository. ## Support If you are having general issues with Omnipay, we suggest posting on [Stack Overflow](http://stackoverflow.com/). Be sure to add the [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. If you want to keep up to date with release anouncements, discuss ideas for the project, or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which you can subscribe to. If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/thephpleague/omnipay-sagepay/issues), or better yet, fork the library and submit a pull request. src/DirectGateway.php 0000604 00000004117 15173220556 0010605 0 ustar 00 <?php namespace Omnipay\SagePay; use Omnipay\Common\AbstractGateway; /** * Sage Pay Direct Gateway */ class DirectGateway extends AbstractGateway { // Gateway identification. public function getName() { return 'Sage Pay Direct'; } public function getDefaultParameters() { return array( 'vendor' => '', 'testMode' => false, 'referrerId' => '', ); } // Vendor identification. public function getVendor() { return $this->getParameter('vendor'); } public function setVendor($value) { return $this->setParameter('vendor', $value); } // Access to the HTTP client for debugging. // NOTE: this is likely to be removed or replaced with something // more appropriate. public function getHttpClient() { return $this->httpClient; } // Available services. public function getReferrerId() { return $this->getParameter('referrerId'); } public function setReferrerId($value) { return $this->setParameter('referrerId', $value); } public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\SagePay\Message\DirectAuthorizeRequest', $parameters); } public function completeAuthorize(array $parameters = array()) { return $this->createRequest('\Omnipay\SagePay\Message\DirectCompleteAuthorizeRequest', $parameters); } public function capture(array $parameters = array()) { return $this->createRequest('\Omnipay\SagePay\Message\CaptureRequest', $parameters); } public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\SagePay\Message\DirectPurchaseRequest', $parameters); } public function completePurchase(array $parameters = array()) { return $this->completeAuthorize($parameters); } public function refund(array $parameters = array()) { return $this->createRequest('\Omnipay\SagePay\Message\RefundRequest', $parameters); } } src/Message/ServerAuthorizeRequest.php 0000604 00000001472 15173220556 0014150 0 ustar 00 <?php namespace Omnipay\SagePay\Message; /** * Sage Pay Server Authorize Request */ class ServerAuthorizeRequest extends DirectAuthorizeRequest { public function getProfile() { return $this->getParameter('profile'); } public function setProfile($value) { return $this->setParameter('profile', $value); } public function getData() { $this->validate('returnUrl'); $data = $this->getBaseAuthorizeData(); $data['NotificationURL'] = $this->getReturnUrl(); $data['Profile'] = $this->getProfile(); return $data; } public function getService() { return 'vspserver-register'; } protected function createResponse($data) { return $this->response = new ServerAuthorizeResponse($this, $data); } } src/Message/ServerCompleteAuthorizeRequest.php 0000604 00000005534 15173220556 0015644 0 ustar 00 <?php namespace Omnipay\SagePay\Message; use Omnipay\Common\Exception\InvalidResponseException; /** * Sage Pay Server Complete Authorize Request */ class ServerCompleteAuthorizeRequest extends AbstractRequest { /** * Get the signature calculated from the three pieces of saved local * information: * - VendorTxCode - merchant site ID (aka transactionId). * - VPSTxId - SagePay ID (aka transactionReference) * - SecurityKey - SagePay one-use token. * and the POSTed transaction results. * * Note that the three items above are passed in as a single JSON structure * as the transactionReference. Would be nice if that were just the fallback, * if not passed in as three separate items to the relevant fields. */ public function getSignature() { $this->validate('transactionReference'); $reference = json_decode($this->getTransactionReference(), true); // Re-create the VPSSignature $signature_string = $reference['VPSTxId']. $reference['VendorTxCode']. $this->httpRequest->request->get('Status'). $this->httpRequest->request->get('TxAuthNo'). $this->getVendor(). $this->httpRequest->request->get('AVSCV2'). $reference['SecurityKey']. $this->httpRequest->request->get('AddressResult'). $this->httpRequest->request->get('PostCodeResult'). $this->httpRequest->request->get('CV2Result'). $this->httpRequest->request->get('GiftAid'). $this->httpRequest->request->get('3DSecureStatus'). $this->httpRequest->request->get('CAVV'). $this->httpRequest->request->get('AddressStatus'). $this->httpRequest->request->get('PayerStatus'). $this->httpRequest->request->get('CardType'). $this->httpRequest->request->get('Last4Digits'). // New for protocol v3.00 // Described in the docs as "mandatory" but not supplied when PayPal is used, // so provide the defaults. $this->httpRequest->request->get('DeclineCode', ''). $this->httpRequest->request->get('ExpiryDate', ''). $this->httpRequest->request->get('FraudResponse', ''). $this->httpRequest->request->get('BankAuthCode', ''); return md5($signature_string); } /** * Get the POSTed data, checking that the signature is valid. */ public function getData() { $signature = $this->getSignature(); if (strtolower($this->httpRequest->request->get('VPSSignature')) !== $signature) { throw new InvalidResponseException; } return $this->httpRequest->request->all(); } public function sendData($data) { return $this->response = new ServerCompleteAuthorizeResponse($this, $data); } } src/Message/DirectAuthorizeRequest.php 0000604 00000006675 15173220556 0014126 0 ustar 00 <?php namespace Omnipay\SagePay\Message; /** * Sage Pay Direct Authorize Request */ class DirectAuthorizeRequest extends AbstractRequest { protected $action = 'DEFERRED'; protected $cardBrandMap = array( 'mastercard' => 'mc', 'diners_club' => 'dc' ); protected function getBaseAuthorizeData() { $this->validate('amount', 'card', 'transactionId'); $card = $this->getCard(); $data = $this->getBaseData(); $data['Description'] = $this->getDescription(); $data['Amount'] = $this->getAmount(); $data['Currency'] = $this->getCurrency(); $data['VendorTxCode'] = $this->getTransactionId(); $data['ClientIPAddress'] = $this->getClientIp(); $data['ApplyAVSCV2'] = $this->getApplyAVSCV2() ?: 0; $data['Apply3DSecure'] = $this->getApply3DSecure() ?: 0; if ($this->getReferrerId()) { $data['ReferrerID'] = $this->getReferrerId(); } // billing details $data['BillingFirstnames'] = $card->getBillingFirstName(); $data['BillingSurname'] = $card->getBillingLastName(); $data['BillingAddress1'] = $card->getBillingAddress1(); $data['BillingAddress2'] = $card->getBillingAddress2(); $data['BillingCity'] = $card->getBillingCity(); $data['BillingPostCode'] = $card->getBillingPostcode(); $data['BillingState'] = $card->getBillingCountry() === 'US' ? $card->getBillingState() : ''; $data['BillingCountry'] = $card->getBillingCountry(); $data['BillingPhone'] = $card->getBillingPhone(); // shipping details $data['DeliveryFirstnames'] = $card->getShippingFirstName(); $data['DeliverySurname'] = $card->getShippingLastName(); $data['DeliveryAddress1'] = $card->getShippingAddress1(); $data['DeliveryAddress2'] = $card->getShippingAddress2(); $data['DeliveryCity'] = $card->getShippingCity(); $data['DeliveryPostCode'] = $card->getShippingPostcode(); $data['DeliveryState'] = $card->getShippingCountry() === 'US' ? $card->getShippingState() : ''; $data['DeliveryCountry'] = $card->getShippingCountry(); $data['DeliveryPhone'] = $card->getShippingPhone(); $data['CustomerEMail'] = $card->getEmail(); $basketXML = $this->getItemData(); if (!empty($basketXML)) { $data['BasketXML'] = $basketXML; } return $data; } public function getData() { $data = $this->getBaseAuthorizeData(); $this->getCard()->validate(); $data['CardHolder'] = $this->getCard()->getName(); $data['CardNumber'] = $this->getCard()->getNumber(); $data['CV2'] = $this->getCard()->getCvv(); $data['ExpiryDate'] = $this->getCard()->getExpiryDate('my'); $data['CardType'] = $this->getCardBrand(); if ($this->getCard()->getStartMonth() and $this->getCard()->getStartYear()) { $data['StartDate'] = $this->getCard()->getStartDate('my'); } if ($this->getCard()->getIssueNumber()) { $data['IssueNumber'] = $this->getCard()->getIssueNumber(); } return $data; } public function getService() { return 'vspdirect-register'; } protected function getCardBrand() { $brand = $this->getCard()->getBrand(); if (isset($this->cardBrandMap[$brand])) { return $this->cardBrandMap[$brand]; } return $brand; } } src/Message/ServerCompleteAuthorizeResponse.php 0000604 00000010421 15173220556 0016001 0 ustar 00 <?php namespace Omnipay\SagePay\Message; use Omnipay\Common\Message\RequestInterface; /** * Sage Pay Server Complete Authorize Response */ class ServerCompleteAuthorizeResponse extends Response { public function __construct(RequestInterface $request, $data) { $this->request = $request; $this->data = $data; } public function getTransactionReference() { if (isset($this->data['TxAuthNo'])) { $reference = json_decode($this->getRequest()->getTransactionReference(), true); $reference['VendorTxCode'] = $this->getRequest()->getTransactionId(); $reference['TxAuthNo'] = $this->data['TxAuthNo']; return json_encode($reference); } } /** * Confirm (Sage Pay Server only) * * Notify Sage Pay you received the payment details and wish to confirm the payment, and * provide a URL to forward the customer to. * * @param string URL to forward the customer to. Note this is different to your standard * return controller action URL. * @param string Optional human readable reasons for accepting the transaction. */ public function confirm($nextUrl, $detail = null) { $this->sendResponse('OK', $nextUrl, $detail); } /** * Error (Sage Pay Server only) * * Notify Sage Pay you received the payment details but there was an error and the payment * cannot be completed. Error should be called rarely, and only when something unforseen * has happened on your server or database. * * @param string URL to foward the customer to. Note this is different to your standard * return controller action URL. * @param string Optional human readable reasons for not accepting the transaction. */ public function error($nextUrl, $detail = null) { $this->sendResponse('ERROR', $nextUrl, $detail); } /** * Invalid (Sage Pay Server only) * * Notify Sage Pay you received the payment details but they were invalid and the payment * cannot be completed. Invalid should be called if you are not happy with the contents * of the POST, such as the MD5 hash signatures did not match or you do not wish to proceed * with the order. * * @param string URL to foward the customer to. Note this is different to your standard * return controller action URL. * @param string Optional human readable reasons for not accepting the transaction. */ public function invalid($nextUrl, $detail = null) { $this->sendResponse('INVALID', $nextUrl, $detail); } /** * Respond to SagePay confirming or rejecting the payment. * * Sage Pay Server does things backwards compared to every other gateway (including Sage Pay * Direct). The return URL is called by their server, and they expect you to confirm receipt * and then pass a URL for them to forward the customer to. * * Because of this, an extra step is required. In your return controller, after calling * $gateway->completePurchase(), you should attempt to process the payment. You must then call * either $response->confirm(), $response->error() or $response->invalid() to notify Sage Pay * whether to complete the payment or not, and provide a URL to forward the customer to. * * Keep in mind your original confirmPurchase() script is being called by Sage Pay, not * the customer. * * @param string The status to send to Sage Pay, either OK, INVALID or ERROR. * @param string URL to forward the customer to. Note this is different to your standard * return controller action URL. * @param string Optional human readable reasons for accepting the transaction. */ public function sendResponse($status, $nextUrl, $detail = null) { $message = "Status=$status\r\nRedirectUrl=$nextUrl"; if (null !== $detail) { $message .= "\r\nStatusDetail=".$detail; } $this->exitWith($message); } /** * Exit to ensure no other HTML, headers, comments, or text are included. * * @access private * @codeCoverageIgnore */ public function exitWith($message) { echo $message; exit; } } src/Message/DirectCompleteAuthorizeRequest.php 0000604 00000001247 15173220556 0015605 0 ustar 00 <?php namespace Omnipay\SagePay\Message; use Omnipay\Common\Exception\InvalidResponseException; /** * Sage Pay Direct Complete Authorize Request */ class DirectCompleteAuthorizeRequest extends AbstractRequest { public function getData() { $data = array( 'MD' => $this->httpRequest->request->get('MD'), 'PARes' => $this->httpRequest->request->get('PaRes'), // inconsistent caps are intentional ); if (empty($data['MD']) || empty($data['PARes'])) { throw new InvalidResponseException; } return $data; } public function getService() { return 'direct3dcallback'; } } src/Message/AbstractRequest.php 0000604 00000016635 15173220556 0012561 0 ustar 00 <?php namespace Omnipay\SagePay\Message; use Omnipay\Common\Exception\InvalidRequestException; /** * Sage Pay Abstract Request */ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { protected $liveEndpoint = 'https://live.sagepay.com/gateway/service'; protected $testEndpoint = 'https://test.sagepay.com/gateway/service'; public function getVendor() { return $this->getParameter('vendor'); } public function setVendor($value) { return $this->setParameter('vendor', $value); } public function getService() { return $this->action; } public function getAccountType() { return $this->getParameter('accountType'); } /** * Set account type. * * This is ignored for all PAYPAL transactions. * * @param string $value E: Use the e-commerce merchant account. (default) * M: Use the mail/telephone order account. (if present) * C: Use the continuous authority merchant account. (if present) */ public function setAccountType($value) { return $this->setParameter('accountType', $value); } public function getReferrerId() { return $this->getParameter('referrerId'); } /** * Set the referrer ID for PAYMENT, DEFERRED and AUTHENTICATE transactions. */ public function setReferrerId($value) { return $this->setParameter('referrerId', $value); } public function getApplyAVSCV2() { return $this->getParameter('applyAVSCV2'); } /** * Set the apply AVSCV2 checks. * * @param int $value 0: If AVS/CV2 enabled then check them. If rules apply, use rules. (default) * 1: Force AVS/CV2 checks even if not enabled for the account. If rules apply * use rules. * 2: Force NO AVS/CV2 checks even if enabled on account. * 3: Force AVS/CV2 checks even if not enabled for account but DON'T apply any * rules. */ public function setApplyAVSCV2($value) { return $this->setParameter('applyAVSCV2', $value); } public function getApply3DSecure() { return $this->getParameter('apply3DSecure'); } /** * Whether or not to apply 3D secure authentication. * * This is ignored for PAYPAL, EUROPEAN PAYMENT transactions. * * @param int $value 0: If 3D-Secure checks are possible and rules allow, perform the * checks and apply the authorisation rules. (default) * 1: Force 3D-Secure checks for this transaction if possible and * apply rules for authorisation. * 2: Do not perform 3D-Secure checks for this transactios and always * authorise. * 3: Force 3D-Secure checks for this transaction if possible but ALWAYS * obtain an auth code, irrespective of rule base. */ public function setApply3DSecure($value) { return $this->setParameter('apply3DSecure', $value); } protected function getBaseData() { $data = array(); $data['VPSProtocol'] = '3.00'; $data['TxType'] = $this->action; $data['Vendor'] = $this->getVendor(); $data['AccountType'] = $this->getAccountType() ?: 'E'; return $data; } public function sendData($data) { // Issue #20 no data values should be null. array_walk($data, function (&$value) { if (!isset($value)) { $value = ''; } }); $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); return $this->createResponse($httpResponse->getBody()); } public function getEndpoint() { $service = strtolower($this->getService()); if ($this->getTestMode()) { return $this->testEndpoint."/$service.vsp"; } return $this->liveEndpoint."/$service.vsp"; } protected function createResponse($data) { return $this->response = new Response($this, $data); } /** * Filters out any characters that SagePay does not support from the item name. * * Believe it or not, SagePay actually have separate rules for allowed characters * for item names and discount names, hence the need for two separate methods. * * @param string $name * * @return string */ protected function filterItemName($name) { $standardChars = "0-9a-zA-Z"; $allowedSpecialChars = " +'/\\&:,.-{}"; $pattern = '`[^'.$standardChars.preg_quote($allowedSpecialChars, '/').']`'; $name = trim(substr(preg_replace($pattern, '', $name), 0, 100)); return $name; } /** * Filters out any characters that SagePay does not support from the discount name. * * Believe it or not, SagePay actually have separate rules for allowed characters * for item names and discount names, hence the need for two separate methods. * * @param string $name * * @return string */ protected function filterDiscountName($name) { $standardChars = "0-9a-zA-Z"; $allowedSpecialChars = " +'/\\:,.-{};_@()^\"~[]$=!#?|"; $pattern = '`[^'.$standardChars.preg_quote($allowedSpecialChars, '/').']`'; $name = trim(substr(preg_replace($pattern, '', $name), 0, 100)); return $name; } /** * Get an XML representation of the current cart items * * @return string The XML string; an empty string if no basket items are present */ protected function getItemData() { $result = ''; $items = $this->getItems(); // If there are no items, then do not construct any of the basket. if (empty($items) || $items->all() === array()) { return $result; } $xml = new \SimpleXMLElement('<basket/>'); $cartHasDiscounts = false; foreach ($items as $basketItem) { if ($basketItem->getPrice() < 0) { $cartHasDiscounts = true; } else { $total = ($basketItem->getQuantity() * $basketItem->getPrice()); $item = $xml->addChild('item'); $item->description = $this->filterItemName($basketItem->getName()); $item->addChild('quantity', $basketItem->getQuantity()); $item->addChild('unitNetAmount', $basketItem->getPrice()); $item->addChild('unitTaxAmount', '0.00'); $item->addChild('unitGrossAmount', $basketItem->getPrice()); $item->addChild('totalGrossAmount', $total); } } if ($cartHasDiscounts) { $discounts = $xml->addChild('discounts'); foreach ($items as $discountItem) { if ($discountItem->getPrice() < 0) { $discount = $discounts->addChild('discount'); $discount->addChild('fixed', ($discountItem->getPrice() * $discountItem->getQuantity()) * -1); $discount->description = $this->filterDiscountName($discountItem->getName()); } } } $xmlString = $xml->asXML(); if ($xmlString) { $result = $xmlString; } return $result; } } src/Message/Response.php 0000604 00000005510 15173220556 0011231 0 ustar 00 <?php namespace Omnipay\SagePay\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RedirectResponseInterface; use Omnipay\Common\Message\RequestInterface; /** * Sage Pay Response */ class Response extends AbstractResponse implements RedirectResponseInterface { public function __construct(RequestInterface $request, $data) { $this->request = $request; $this->data = $this->decode($data); } public function isSuccessful() { return isset($this->data['Status']) && 'OK' === $this->data['Status']; } public function isRedirect() { return isset($this->data['Status']) && '3DAUTH' === $this->data['Status']; } /** * Gateway Reference * * Unfortunately Sage Pay requires the original VendorTxCode as well as 3 separate * fields from the response object to capture or refund transactions at a later date. * * Active Merchant solves this dilemma by returning the gateway reference in the following * custom format: VendorTxCode;VPSTxId;TxAuthNo;SecurityKey * * We have opted to return this reference as JSON, as the keys are much more explicit. */ public function getTransactionReference() { $reference = array(); $reference['VendorTxCode'] = $this->getRequest()->getTransactionId(); foreach (array('SecurityKey', 'TxAuthNo', 'VPSTxId') as $key) { if (isset($this->data[$key])) { $reference[$key] = $this->data[$key]; } } ksort($reference); return json_encode($reference); } public function getStatus() { return isset($this->data['Status']) ? $this->data['Status'] : null; } public function getMessage() { return isset($this->data['StatusDetail']) ? $this->data['StatusDetail'] : null; } public function getRedirectUrl() { if ($this->isRedirect()) { return $this->data['ACSURL']; } } public function getRedirectMethod() { return 'POST'; } public function getRedirectData() { if ($this->isRedirect()) { return array( 'PaReq' => $this->data['PAReq'], 'TermUrl' => $this->getRequest()->getReturnUrl(), 'MD' => $this->data['MD'], ); } } /** * Decode raw ini-style response body * * @param string The raw response body * @return array */ protected function decode($response) { $lines = explode("\n", $response); $data = array(); foreach ($lines as $line) { $line = explode('=', $line, 2); if (!empty($line[0])) { $data[trim($line[0])] = isset($line[1]) ? trim($line[1]) : ''; } } return $data; } } src/Message/ServerAuthorizeResponse.php 0000604 00000001211 15173220556 0014305 0 ustar 00 <?php namespace Omnipay\SagePay\Message; /** * Sage Pay Server Authorize Response */ class ServerAuthorizeResponse extends Response { public function isSuccessful() { return false; } public function isRedirect() { return isset($this->data['Status']) && in_array($this->data['Status'], array('OK', 'OK REPEATED')); } public function getRedirectUrl() { return isset($this->data['NextURL']) ? $this->data['NextURL'] : null; } public function getRedirectMethod() { return 'GET'; } public function getRedirectData() { return null; } } src/Message/CaptureRequest.php 0000604 00000001242 15173220556 0012405 0 ustar 00 <?php namespace Omnipay\SagePay\Message; /** * Sage Pay Capture Request */ class CaptureRequest extends AbstractRequest { protected $action = 'RELEASE'; public function getData() { $this->validate('amount', 'transactionReference'); $reference = json_decode($this->getTransactionReference(), true); $data = $this->getBaseData(); $data['ReleaseAmount'] = $this->getAmount(); $data['VendorTxCode'] = $reference['VendorTxCode']; $data['VPSTxId'] = $reference['VPSTxId']; $data['SecurityKey'] = $reference['SecurityKey']; $data['TxAuthNo'] = $reference['TxAuthNo']; return $data; } } src/Message/ServerPurchaseRequest.php 0000604 00000000271 15173220556 0013744 0 ustar 00 <?php namespace Omnipay\SagePay\Message; /** * Sage Pay Server Purchase Request */ class ServerPurchaseRequest extends ServerAuthorizeRequest { protected $action = 'PAYMENT'; } src/Message/DirectPurchaseRequest.php 0000604 00000000271 15173220556 0013710 0 ustar 00 <?php namespace Omnipay\SagePay\Message; /** * Sage Pay Direct Purchase Request */ class DirectPurchaseRequest extends DirectAuthorizeRequest { protected $action = 'PAYMENT'; } src/Message/RefundRequest.php 0000604 00000001652 15173220556 0012232 0 ustar 00 <?php namespace Omnipay\SagePay\Message; /** * Sage Pay Refund Request */ class RefundRequest extends AbstractRequest { protected $action = 'REFUND'; public function getData() { $this->validate('amount', 'transactionReference'); $reference = json_decode($this->getTransactionReference(), true); $data = $this->getBaseData(); $data['Amount'] = $this->getAmount(); $data['Currency'] = $this->getCurrency(); $data['Description'] = $this->getDescription(); $data['RelatedVendorTxCode'] = $reference['VendorTxCode']; $data['RelatedVPSTxId'] = $reference['VPSTxId']; $data['RelatedSecurityKey'] = $reference['SecurityKey']; $data['RelatedTxAuthNo'] = $reference['TxAuthNo']; // VendorTxCode must be unique for the refund (different from original) $data['VendorTxCode'] = $this->getTransactionId(); return $data; } } src/ServerGateway.php 0000604 00000001776 15173220556 0010651 0 ustar 00 <?php namespace Omnipay\SagePay; use Omnipay\SagePay\Message\ServerAuthorizeRequest; use Omnipay\SagePay\Message\ServerCompleteAuthorizeRequest; use Omnipay\SagePay\Message\ServerPurchaseRequest; /** * Sage Pay Server Gateway */ class ServerGateway extends DirectGateway { public function getName() { return 'Sage Pay Server'; } public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\SagePay\Message\ServerAuthorizeRequest', $parameters); } public function completeAuthorize(array $parameters = array()) { return $this->createRequest('\Omnipay\SagePay\Message\ServerCompleteAuthorizeRequest', $parameters); } public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\SagePay\Message\ServerPurchaseRequest', $parameters); } public function completePurchase(array $parameters = array()) { return $this->completeAuthorize($parameters); } } composer.json 0000604 00000001721 15173220556 0007271 0 ustar 00 { "name": "omnipay/sagepay", "type": "library", "description": "Sage Pay driver for the Omnipay PHP payment processing library", "keywords": [ "gateway", "merchant", "omnipay", "pay", "payment", "purchase", "sage pay", "sagepay" ], "homepage": "https://github.com/thephpleague/omnipay-sagepay", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-sagepay/contributors" } ], "autoload": { "psr-4": { "Omnipay\\SagePay\\" : "src/" } }, "require": { "omnipay/common": "~2.0" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } tests/DirectGatewayTest.php 0000604 00000015551 15173220556 0012024 0 ustar 00 <?php namespace Omnipay\SagePay; use Omnipay\Tests\GatewayTestCase; class DirectGatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new DirectGateway($this->getHttpClient(), $this->getHttpRequest()); $this->purchaseOptions = array( 'amount' => '10.00', 'transactionId' => '123', 'card' => $this->getValidCard(), 'returnUrl' => 'https://www.example.com/return', ); $this->captureOptions = array( 'amount' => '10.00', 'transactionId' => '123', 'transactionReference' => '{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"4255","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"438791"}', ); } public function testAuthorizeFailureSuccess() { $this->setMockHttpResponse('DirectPurchaseSuccess.txt'); $response = $this->gateway->authorize($this->purchaseOptions)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('{"SecurityKey":"OUWLNYQTVT","TxAuthNo":"9962","VPSTxId":"{5A1BC414-5409-48DD-9B8B-DCDF096CE0BE}","VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame('Direct transaction from Simulator.', $response->getMessage()); } public function testAuthorizeFailure() { $this->setMockHttpResponse('DirectPurchaseFailure.txt'); $response = $this->gateway->authorize($this->purchaseOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame('The VendorTxCode \'984297\' has been used before. Each transaction you send should have a unique VendorTxCode.', $response->getMessage()); } public function testAuthorize3dSecure() { $this->setMockHttpResponse('DirectPurchase3dSecure.txt'); $response = $this->gateway->authorize($this->purchaseOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertSame('https://test.sagepay.com/Simulator/3DAuthPage.asp', $response->getRedirectUrl()); $redirectData = $response->getRedirectData(); $this->assertSame('065379457749061954', $redirectData['MD']); $this->assertSame('BSkaFwYFFTYAGyFbAB0LFRYWBwsBZw0EGwECEX9YRGFWc08pJCVVKgAANS0KADoZCCAMBnIeOxcWRg0LERdOOTQRDFRdVHNYUgwTMBsBCxABJw4DJHE+ERgPCi8MVC0HIAROCAAfBUk4ER89DD0IWDkvMQ1VdFwoUFgwXVYvbHgvMkdBXXNbQGIjdl1ZUEc1XSwqAAgUUicYBDYcB3I2AjYjIzsn', $redirectData['PaReq']); $this->assertSame('https://www.example.com/return', $redirectData['TermUrl']); } public function testPurchaseSuccess() { $this->setMockHttpResponse('DirectPurchaseSuccess.txt'); $response = $this->gateway->purchase($this->purchaseOptions)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('{"SecurityKey":"OUWLNYQTVT","TxAuthNo":"9962","VPSTxId":"{5A1BC414-5409-48DD-9B8B-DCDF096CE0BE}","VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame('Direct transaction from Simulator.', $response->getMessage()); } public function testPurchaseFailure() { $this->setMockHttpResponse('DirectPurchaseFailure.txt'); $response = $this->gateway->purchase($this->purchaseOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame('The VendorTxCode \'984297\' has been used before. Each transaction you send should have a unique VendorTxCode.', $response->getMessage()); } public function testPurchase3dSecure() { $this->setMockHttpResponse('DirectPurchase3dSecure.txt'); $response = $this->gateway->purchase($this->purchaseOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertSame('https://test.sagepay.com/Simulator/3DAuthPage.asp', $response->getRedirectUrl()); $redirectData = $response->getRedirectData(); $this->assertSame('065379457749061954', $redirectData['MD']); $this->assertSame('BSkaFwYFFTYAGyFbAB0LFRYWBwsBZw0EGwECEX9YRGFWc08pJCVVKgAANS0KADoZCCAMBnIeOxcWRg0LERdOOTQRDFRdVHNYUgwTMBsBCxABJw4DJHE+ERgPCi8MVC0HIAROCAAfBUk4ER89DD0IWDkvMQ1VdFwoUFgwXVYvbHgvMkdBXXNbQGIjdl1ZUEc1XSwqAAgUUicYBDYcB3I2AjYjIzsn', $redirectData['PaReq']); $this->assertSame('https://www.example.com/return', $redirectData['TermUrl']); } public function testCaptureSuccess() { $this->setMockHttpResponse('CaptureSuccess.txt'); $response = $this->gateway->capture($this->captureOptions)->send(); $this->assertTrue($response->isSuccessful()); $this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame('The transaction was RELEASEed successfully.', $response->getMessage()); } public function testCaptureFailure() { $this->setMockHttpResponse('CaptureFailure.txt'); $response = $this->gateway->capture($this->captureOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame('You are trying to RELEASE a transaction that has already been RELEASEd or ABORTed.', $response->getMessage()); } public function testRefundSuccess() { $this->setMockHttpResponse('CaptureSuccess.txt'); $response = $this->gateway->refund($this->captureOptions)->send(); $this->assertTrue($response->isSuccessful()); $this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame('The transaction was RELEASEed successfully.', $response->getMessage()); } public function testRefundFailure() { $this->setMockHttpResponse('CaptureFailure.txt'); $response = $this->gateway->refund($this->captureOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame('You are trying to RELEASE a transaction that has already been RELEASEd or ABORTed.', $response->getMessage()); } } tests/ServerGatewayTest.php 0000604 00000014715 15173220556 0012061 0 ustar 00 <?php namespace Omnipay\SagePay; use Omnipay\Tests\GatewayTestCase; class ServerGatewayTest extends GatewayTestCase { protected $error_3082_text = '3082 : The Description value is too long.'; public function setUp() { parent::setUp(); $this->gateway = new ServerGateway($this->getHttpClient(), $this->getHttpRequest()); $this->gateway->setVendor('example'); $this->purchaseOptions = array( 'amount' => '10.00', 'transactionId' => '123', 'card' => $this->getValidCard(), 'returnUrl' => 'https://www.example.com/return', ); $this->completePurchaseOptions = array( 'amount' => '10.00', 'transactionId' => '123', 'transactionReference' => '{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"4255","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"438791"}', ); } public function testInheritsDirectGateway() { $this->assertInstanceOf('Omnipay\SagePay\DirectGateway', $this->gateway); } public function testAuthorizeSuccess() { $this->setMockHttpResponse('ServerPurchaseSuccess.txt'); $response = $this->gateway->authorize($this->purchaseOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertSame('{"SecurityKey":"IK776BWNHN","VPSTxId":"{1E7D9C70-DBE2-4726-88EA-D369810D801D}","VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame('Server transaction registered successfully.', $response->getMessage()); $this->assertSame('https://test.sagepay.com/Simulator/VSPServerPaymentPage.asp?TransactionID={1E7D9C70-DBE2-4726-88EA-D369810D801D}', $response->getRedirectUrl()); } public function testAuthorizeFailure() { $this->setMockHttpResponse('ServerPurchaseFailure.txt'); $response = $this->gateway->authorize($this->purchaseOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame($this->error_3082_text, $response->getMessage()); } public function testCompleteAuthorizeSuccess() { $this->getHttpRequest()->request->replace( array( 'Status' => 'OK', 'TxAuthNo' => 'b', 'AVSCV2' => 'c', 'AddressResult' => 'd', 'PostCodeResult' => 'e', 'CV2Result' => 'f', 'GiftAid' => 'g', '3DSecureStatus' => 'h', 'CAVV' => 'i', 'AddressStatus' => 'j', 'PayerStatus' => 'k', 'CardType' => 'l', 'Last4Digits' => 'm', // New fields for protocol v3.00 'DeclineCode' => '00', 'ExpiryDate' => '0722', 'BankAuthCode' => '999777', 'VPSSignature' => md5( '{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}' . '438791' . 'OK' . 'bexamplecJEUPDN1N7Edefghijklm' . '00' . '0722' . '999777' ), ) ); $response = $this->gateway->completeAuthorize($this->completePurchaseOptions)->send(); $this->assertTrue($response->isSuccessful()); $this->assertSame( '{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"b","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"123"}', $response->getTransactionReference() ); $this->assertNull($response->getMessage()); } /** * @expectedException Omnipay\Common\Exception\InvalidResponseException */ public function testCompleteAuthorizeInvalid() { $response = $this->gateway->completeAuthorize($this->completePurchaseOptions)->send(); } public function testPurchaseSuccess() { $this->setMockHttpResponse('ServerPurchaseSuccess.txt'); $response = $this->gateway->purchase($this->purchaseOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertSame('{"SecurityKey":"IK776BWNHN","VPSTxId":"{1E7D9C70-DBE2-4726-88EA-D369810D801D}","VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame('Server transaction registered successfully.', $response->getMessage()); $this->assertSame('https://test.sagepay.com/Simulator/VSPServerPaymentPage.asp?TransactionID={1E7D9C70-DBE2-4726-88EA-D369810D801D}', $response->getRedirectUrl()); } public function testPurchaseFailure() { $this->setMockHttpResponse('ServerPurchaseFailure.txt'); $response = $this->gateway->purchase($this->purchaseOptions)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('{"VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertSame($this->error_3082_text, $response->getMessage()); } public function testCompletePurchaseSuccess() { $this->getHttpRequest()->request->replace( array( 'Status' => 'OK', 'TxAuthNo' => 'b', 'AVSCV2' => 'c', 'AddressResult' => 'd', 'PostCodeResult' => 'e', 'CV2Result' => 'f', 'GiftAid' => 'g', '3DSecureStatus' => 'h', 'CAVV' => 'i', 'AddressStatus' => 'j', 'PayerStatus' => 'k', 'CardType' => 'l', 'Last4Digits' => 'm', 'VPSSignature' => md5('{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}438791OKbexamplecJEUPDN1N7Edefghijklm'), ) ); $response = $this->gateway->completePurchase($this->completePurchaseOptions)->send(); $this->assertTrue($response->isSuccessful()); $this->assertSame('{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"b","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } /** * @expectedException Omnipay\Common\Exception\InvalidResponseException */ public function testCompletePurchaseInvalid() { $response = $this->gateway->completePurchase($this->completePurchaseOptions)->send(); } } tests/Message/ServerCompleteAuthorizeResponseTest.php 0000604 00000007226 15173220556 0017225 0 ustar 00 <?php namespace Omnipay\SagePay\Message; use Omnipay\Tests\TestCase; use Mockery as m; class ServerCompleteAuthorizeResponseTest extends TestCase { public function testServerCompleteAuthorizeResponseSuccess() { $response = new ServerCompleteAuthorizeResponse( $this->getMockRequest(), array( 'Status' => 'OK', 'TxAuthNo' => 'b', 'AVSCV2' => 'c', 'AddressResult' => 'd', 'PostCodeResult' => 'e', 'CV2Result' => 'f', 'GiftAid' => 'g', '3DSecureStatus' => 'h', 'CAVV' => 'i', 'AddressStatus' => 'j', 'PayerStatus' => 'k', 'CardType' => 'l', 'Last4Digits' => 'm', 'DeclineCode' => '00', 'ExpiryDate' => '0722', 'BankAuthCode' => '999777', ) ); $this->getMockRequest()->shouldReceive('getTransactionId')->once()->andReturn('123'); $this->getMockRequest()->shouldReceive('getTransactionReference')->once()->andReturn('{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"4255","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"438791"}'); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"b","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"123"}', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testServerCompleteAuthorizeResponseFailure() { $response = new ServerCompleteAuthorizeresponse($this->getMockRequest(), array('Status' => 'INVALID')); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testConfirm() { $response = m::mock('\Omnipay\SagePay\Message\ServerCompleteAuthorizeResponse')->makePartial(); $response->shouldReceive('sendResponse')->once()->with('OK', 'https://www.example.com/', 'detail'); $response->confirm('https://www.example.com/', 'detail'); } public function testError() { $response = m::mock('\Omnipay\SagePay\Message\ServerCompleteAuthorizeResponse')->makePartial(); $response->shouldReceive('sendResponse')->once()->with('ERROR', 'https://www.example.com/', 'detail'); $response->error('https://www.example.com/', 'detail'); } public function testInvalid() { $response = m::mock('\Omnipay\SagePay\Message\ServerCompleteAuthorizeResponse')->makePartial(); $response->shouldReceive('sendResponse')->once()->with('INVALID', 'https://www.example.com/', 'detail'); $response->invalid('https://www.example.com/', 'detail'); } public function testSendResponse() { $response = m::mock('\Omnipay\SagePay\Message\ServerCompleteAuthorizeResponse')->makePartial(); $response->shouldReceive('exitWith')->once()->with("Status=FOO\r\nRedirectUrl=https://www.example.com/"); $response->sendResponse('FOO', 'https://www.example.com/'); } public function testSendResponseDetail() { $response = m::mock('\Omnipay\SagePay\Message\ServerCompleteAuthorizeResponse')->makePartial(); $response->shouldReceive('exitWith')->once()->with("Status=FOO\r\nRedirectUrl=https://www.example.com/\r\nStatusDetail=Bar"); $response->sendResponse('FOO', 'https://www.example.com/', 'Bar'); } } tests/Message/ResponseTest.php 0000604 00000007034 15173220556 0012447 0 ustar 00 <?php namespace Omnipay\SagePay\Message; use Omnipay\Tests\TestCase; class ResponseTest extends TestCase { public function setUp() { $this->getMockRequest()->shouldReceive('getTransactionId')->andReturn('123456'); } public function testDirectPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('DirectPurchaseSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('{"SecurityKey":"OUWLNYQTVT","TxAuthNo":"9962","VPSTxId":"{5A1BC414-5409-48DD-9B8B-DCDF096CE0BE}","VendorTxCode":"123456"}', $response->getTransactionReference()); $this->assertSame('Direct transaction from Simulator.', $response->getMessage()); } public function testDirectPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('DirectPurchaseFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('{"VendorTxCode":"123456"}', $response->getTransactionReference()); $this->assertSame('The VendorTxCode \'984297\' has been used before. Each transaction you send should have a unique VendorTxCode.', $response->getMessage()); } public function testDirectPurchase3dSecure() { $httpResponse = $this->getMockHttpResponse('DirectPurchase3dSecure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->getMockRequest()->shouldReceive('getReturnUrl')->once()->andReturn('https://www.example.com/return'); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertSame('{"VendorTxCode":"123456"}', $response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertSame('https://test.sagepay.com/Simulator/3DAuthPage.asp', $response->getRedirectUrl()); $redirectData = $response->getRedirectData(); $this->assertSame('065379457749061954', $redirectData['MD']); $this->assertSame('BSkaFwYFFTYAGyFbAB0LFRYWBwsBZw0EGwECEX9YRGFWc08pJCVVKgAANS0KADoZCCAMBnIeOxcWRg0LERdOOTQRDFRdVHNYUgwTMBsBCxABJw4DJHE+ERgPCi8MVC0HIAROCAAfBUk4ER89DD0IWDkvMQ1VdFwoUFgwXVYvbHgvMkdBXXNbQGIjdl1ZUEc1XSwqAAgUUicYBDYcB3I2AjYjIzsn', $redirectData['PaReq']); $this->assertSame('https://www.example.com/return', $redirectData['TermUrl']); } public function testCaptureSuccess() { $httpResponse = $this->getMockHttpResponse('CaptureSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertTrue($response->isSuccessful()); $this->assertSame('{"VendorTxCode":"123456"}', $response->getTransactionReference()); $this->assertSame('The transaction was RELEASEed successfully.', $response->getMessage()); } public function testCaptureFailure() { $httpResponse = $this->getMockHttpResponse('CaptureFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertSame('{"VendorTxCode":"123456"}', $response->getTransactionReference()); $this->assertSame('You are trying to RELEASE a transaction that has already been RELEASEd or ABORTed.', $response->getMessage()); } } tests/Message/ServerAuthorizeRequestTest.php 0000604 00000001633 15173220556 0015362 0 ustar 00 <?php namespace Omnipay\SagePay\Message; use Omnipay\Tests\TestCase; class ServerAuthorizeRequestTest extends TestCase { public function setUp() { parent::setUp(); $this->request = new ServerAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '12.00', 'transactionId' => '123', 'card' => $this->getValidCard(), ) ); } public function testProfile() { $this->assertSame($this->request, $this->request->setProfile('NORMAL')); $this->assertSame('NORMAL', $this->request->getProfile()); } public function getData() { $data = $this->request->getData(); $this->assertSame('https://www.example.com/return', $data['NotificationURL']); $this->assertSame('LOW', $data['Profile']); } } tests/Message/DirectAuthorizeRequestTest.php 0000604 00000022531 15173220556 0015326 0 ustar 00 <?php namespace Omnipay\SagePay\Message; use Omnipay\Tests\TestCase; class DirectAuthorizeRequestTest extends TestCase { /** * @var \Omnipay\Common\Message\AbstractRequest $request */ protected $request; public function setUp() { parent::setUp(); $this->request = new DirectAuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '12.00', 'currency' => 'GBP', 'transactionId' => '123', 'card' => $this->getValidCard(), ) ); } public function testGetDataDefaults() { $data = $this->request->getData(); $this->assertSame('E', $data['AccountType']); $this->assertSame(0, $data['ApplyAVSCV2']); $this->assertSame(0, $data['Apply3DSecure']); } public function testGetData() { $this->request->setAccountType('M'); $this->request->setApplyAVSCV2(2); $this->request->setApply3DSecure(3); $this->request->setDescription('food'); $this->request->setClientIp('127.0.0.1'); $this->request->setReferrerId('3F7A4119-8671-464F-A091-9E59EB47B80C'); $data = $this->request->getData(); $this->assertSame('M', $data['AccountType']); $this->assertSame('food', $data['Description']); $this->assertSame('12.00', $data['Amount']); $this->assertSame('GBP', $data['Currency']); $this->assertSame('123', $data['VendorTxCode']); $this->assertSame('127.0.0.1', $data['ClientIPAddress']); $this->assertSame(2, $data['ApplyAVSCV2']); $this->assertSame(3, $data['Apply3DSecure']); $this->assertSame('3F7A4119-8671-464F-A091-9E59EB47B80C', $data['ReferrerID']); } public function testNoBasket() { // First with no basket set at all. $data = $this->request->getData(); $this->assertArrayNotHasKey('BasketXML', $data); // Then with a basket containing no items. $items = new \Omnipay\Common\ItemBag(array()); $this->request->setItems($items); $data = $this->request->getData(); $this->assertArrayNotHasKey('BasketXML', $data); } public function testBasket() { $items = new \Omnipay\Common\ItemBag(array( new \Omnipay\Common\Item(array( 'name' => 'Name', 'description' => 'Description', 'quantity' => 1, 'price' => 1.23, )) )); $basketXml = '<basket><item>' . '<description>Name</description><quantity>1</quantity>' . '<unitNetAmount>1.23</unitNetAmount><unitTaxAmount>0.00</unitTaxAmount>' . '<unitGrossAmount>1.23</unitGrossAmount><totalGrossAmount>1.23</totalGrossAmount>' . '</item></basket>'; $this->request->setItems($items); $data = $this->request->getData(); // The element does exist, and must contain the basket XML, with optional XML header and // trailing newlines. $this->assertArrayHasKey('BasketXML', $data); $this->assertContains($basketXml, $data['BasketXML']); } public function testGetDataNoReferrerId() { // Default value is equivalent to this: $this->request->setReferrerId(''); $data = $this->request->getData(); $this->assertArrayNotHasKey('ReferrerID', $data); } public function testGetDataCustomerDetails() { $card = $this->request->getCard(); $data = $this->request->getData(); $this->assertSame($card->getFirstName(), $data['BillingFirstnames']); $this->assertSame($card->getLastName(), $data['BillingSurname']); $this->assertSame($card->getBillingAddress1(), $data['BillingAddress1']); $this->assertSame($card->getBillingAddress2(), $data['BillingAddress2']); $this->assertSame($card->getBillingCity(), $data['BillingCity']); $this->assertSame($card->getBillingPostcode(), $data['BillingPostCode']); $this->assertSame($card->getBillingState(), $data['BillingState']); $this->assertSame($card->getBillingCountry(), $data['BillingCountry']); $this->assertSame($card->getBillingPhone(), $data['BillingPhone']); $this->assertSame($card->getFirstName(), $data['DeliveryFirstnames']); $this->assertSame($card->getLastName(), $data['DeliverySurname']); $this->assertSame($card->getShippingAddress1(), $data['DeliveryAddress1']); $this->assertSame($card->getShippingAddress2(), $data['DeliveryAddress2']); $this->assertSame($card->getShippingCity(), $data['DeliveryCity']); $this->assertSame($card->getShippingPostcode(), $data['DeliveryPostCode']); $this->assertSame($card->getShippingState(), $data['DeliveryState']); $this->assertSame($card->getShippingCountry(), $data['DeliveryCountry']); $this->assertSame($card->getShippingPhone(), $data['DeliveryPhone']); } public function testGetDataCustomerDetailsIgnoresStateOutsideUS() { $card = $this->request->getCard(); $card->setBillingCountry('UK'); $card->setShippingCountry('NZ'); $data = $this->request->getData(); // these must be empty string, not null // (otherwise Guzzle ignores them, and SagePay throws a fit) $this->assertSame('', $data['BillingState']); $this->assertSame('', $data['DeliveryState']); } public function testGetDataVisa() { $this->request->getCard()->setNumber('4929000000006'); $data = $this->request->getData(); $this->assertSame('visa', $data['CardType']); } public function testGetDataMastercard() { $this->request->getCard()->setNumber('5404000000000001'); $data = $this->request->getData(); $this->assertSame('mc', $data['CardType']); } public function testGetDataDinersClub() { $this->request->getCard()->setNumber('30569309025904'); $data = $this->request->getData(); $this->assertSame('dc', $data['CardType']); } public function testGetDataNullBillingAddress2() { $card = $this->request->getCard(); // This emulates not setting the billing address 2 at all // (it defaults to null). $card->setBillingAddress2(null); $data = $this->request->getData(); $this->assertNull($data['BillingAddress2']); // This tests that the BillingAddress2 may be left unset, // which defaults to null. When it is sent to SagePay, it gets // converted to an empty string. I'm not clear how that would be // tested. } public function testBasketWithNoDiscount() { $items = new \Omnipay\Common\ItemBag(array( new \Omnipay\Common\Item(array( 'name' => 'Name', 'description' => 'Description', 'quantity' => 1, 'price' => 1.23, )) )); $this->request->setItems($items); $data = $this->request->getData(); // The element does exist, and must contain the basket XML, with optional XML header and // trailing newlines. $this->assertArrayHasKey('BasketXML', $data); $this->assertNotContains('<discount>', $data['BasketXML']); } public function testMixedBasketWithSpecialChars() { $items = new \Omnipay\Common\ItemBag(array( new \Omnipay\Common\Item(array( 'name' => "Denisé's Odd & Wierd £name? #12345678901234567890123456789012345678901234567890123456789012345678901234567890", 'description' => 'Description', 'quantity' => 2, 'price' => 4.23, )), array( 'name' => "Denisé's \"Odd\" & Wierd £discount? #", 'description' => 'My Offer', 'quantity' => 2, 'price' => -0.10, ), array( // 101 character name 'name' => '12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901', 'description' => 'My 2nd Offer', 'quantity' => 1, 'price' => -1.60, ) )); // Names/descriptions should be max 100 characters in length, once invalid characters have been removed. $expected = '<basket><item>' . '<description>Denis\'s Odd & Wierd name 123456789012345678901234567890123456789012345678901234567890123456789012345</description><quantity>2</quantity>' . '<unitNetAmount>4.23</unitNetAmount><unitTaxAmount>0.00</unitTaxAmount>' . '<unitGrossAmount>4.23</unitGrossAmount><totalGrossAmount>8.46</totalGrossAmount>' . '</item><discounts>' . '<discount><fixed>0.2</fixed><description>Denis\'s "Odd" Wierd discount? #</description></discount>' . '<discount><fixed>1.6</fixed><description>1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890</description></discount>' . '</discounts></basket>'; $this->request->setItems($items); $data = $this->request->getData(); $this->assertArrayHasKey('BasketXML', $data); $this->assertContains($expected, $data['BasketXML'], 'Basket XML does not match the expected output'); } } tests/Message/ServerAuthorizeResponseTest.php 0000604 00000003675 15173220556 0015540 0 ustar 00 <?php namespace Omnipay\SagePay\Message; use Omnipay\Tests\TestCase; class ServerAuthorizeResponseTest extends TestCase { public function setUp() { $this->getMockRequest()->shouldReceive('getTransactionId')->andReturn('123456'); } public function testServerPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('ServerPurchaseSuccess.txt'); $response = new ServerAuthorizeResponse($this->getMockRequest(), $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertSame('{"SecurityKey":"IK776BWNHN","VPSTxId":"{1E7D9C70-DBE2-4726-88EA-D369810D801D}","VendorTxCode":"123456"}', $response->getTransactionReference()); $this->assertSame('Server transaction registered successfully.', $response->getMessage()); $this->assertSame('https://test.sagepay.com/Simulator/VSPServerPaymentPage.asp?TransactionID={1E7D9C70-DBE2-4726-88EA-D369810D801D}', $response->getRedirectUrl()); $this->assertSame('GET', $response->getRedirectMethod()); $this->assertNull($response->getRedirectData()); } public function testServerPurchaseRepeated() { $response = new ServerAuthorizeResponse($this->getMockRequest(), 'Status=OK REPEATED'); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); } public function testServerPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('ServerPurchaseFailure.txt'); $response = new ServerAuthorizeResponse($this->getMockRequest(), $httpResponse->getBody()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('{"VendorTxCode":"123456"}', $response->getTransactionReference()); $this->assertSame('3082 : The Description value is too long.', $response->getMessage()); } } tests/Message/RefundRequestTest.php 0000604 00000002370 15173220556 0013443 0 ustar 00 <?php namespace Omnipay\SagePay\Message; use Omnipay\Tests\TestCase; class RefundRequestTest extends TestCase { public function setUp() { parent::setUp(); $this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '12.00', 'transactionReference' => '{"SecurityKey":"JEUPDN1N7E","TxAuthNo":"4255","VPSTxId":"{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}","VendorTxCode":"438791"}', 'testMode' => true, ) ); } public function testGetData() { $data = $this->request->getData(); $this->assertSame('REFUND', $data['TxType']); $this->assertSame('12.00', $data['Amount']); $this->assertSame('438791', $data['RelatedVendorTxCode']); $this->assertSame('{F955C22E-F67B-4DA3-8EA3-6DAC68FA59D2}', $data['RelatedVPSTxId']); $this->assertSame('JEUPDN1N7E', $data['RelatedSecurityKey']); $this->assertSame('4255', $data['RelatedTxAuthNo']); } public function testGetEndpoint() { $url = $this->request->getEndpoint(); $this->assertSame('https://test.sagepay.com/gateway/service/refund.vsp', $url); } } tests/Mock/CaptureFailure.txt 0000604 00000000601 15173220556 0012252 0 ustar 00 HTTP/1.1 200 OK Date: Sat, 16 Feb 2013 08:21:41 GMT Server: Microsoft-IIS/6.0 P3P: CP="CUR" X-Powered-By: ASP.NET Content-Length: 129 Content-Type: Text/Plain Set-Cookie: ASPSESSIONIDSEHSCTTR=NNBHGPBDLOMKKPGPNDDJFBAB; secure; path=/ Cache-control: private VPSProtocol=3.00 Status=INVALID StatusDetail=You are trying to RELEASE a transaction that has already been RELEASEd or ABORTed. tests/Mock/ServerPurchaseFailure.txt 0000604 00000000510 15173220556 0013607 0 ustar 00 HTTP/1.1 200 OK P3P: CP="CUR" Content-Language: en-GB Content-Length: 88 Date: Tue, 20 Jan 2015 16:45:41 GMT Server: undisclosed Set-Cookie: NSC_WRE-uftu.tbhfqbz.dpn-Kbwb7=f76fde52445f8236609ebb88e4554f525455a4a4d5e0;path=/;secure;httponly VPSProtocol=3.00 Status=INVALID StatusDetail=3082 : The Description value is too long. tests/Mock/DirectPurchaseFailure.txt 0000604 00000000634 15173220556 0013562 0 ustar 00 HTTP/1.1 200 OK Date: Sat, 16 Feb 2013 06:40:30 GMT Server: Microsoft-IIS/6.0 P3P: CP="CUR" X-Powered-By: ASP.NET Content-Length: 156 Content-Type: Text/Plain Set-Cookie: ASPSESSIONIDSEHSCTTR=PIMGGPBDEAHAGKNHFGMICIAM; secure; path=/ Cache-control: private VPSProtocol=3.00 Status=INVALID StatusDetail=The VendorTxCode '984297' has been used before. Each transaction you send should have a unique VendorTxCode. tests/Mock/ServerPurchaseSuccess.txt 0000604 00000001024 15173220556 0013631 0 ustar 00 HTTP/1.1 200 OK Date: Sat, 16 Feb 2013 09:02:04 GMT Server: Microsoft-IIS/6.0 P3P: CP="CUR" X-Powered-By: ASP.NET Content-Length: 281 Content-Type: Text/Plain Set-Cookie: ASPSESSIONIDSEHSCTTR=JAEHGPBDBOBICGBGJEHFJHPE; secure; path=/ Cache-control: private VPSProtocol=3.00 Status=OK StatusDetail=Server transaction registered successfully. VPSTxId={1E7D9C70-DBE2-4726-88EA-D369810D801D} SecurityKey=IK776BWNHN NextURL=https://test.sagepay.com/Simulator/VSPServerPaymentPage.asp?TransactionID={1E7D9C70-DBE2-4726-88EA-D369810D801D} tests/Mock/DirectPurchaseSuccess.txt 0000604 00000000760 15173220556 0013603 0 ustar 00 HTTP/1.1 200 OK Date: Sat, 16 Feb 2013 06:39:41 GMT Server: Microsoft-IIS/6.0 P3P: CP="CUR" X-Powered-By: ASP.NET Content-Length: 249 Content-Type: Text/Plain Set-Cookie: ASPSESSIONIDSEHSCTTR=CIMGGPBDFDIKICAGIIHCNFHJ; secure; path=/ Cache-control: private VPSProtocol=3.00 Status=OK StatusDetail=Direct transaction from Simulator. VPSTxId={5A1BC414-5409-48DD-9B8B-DCDF096CE0BE} SecurityKey=OUWLNYQTVT TxAuthNo=9962 AVSCV2=ALL MATCH AddressResult=MATCHED PostCodeResult=MATCHED CV2Result=MATCHED tests/Mock/CaptureSuccess.txt 0000604 00000000524 15173220556 0012277 0 ustar 00 HTTP/1.1 200 OK Date: Sat, 16 Feb 2013 08:21:03 GMT Server: Microsoft-IIS/6.0 P3P: CP="CUR" X-Powered-By: ASP.NET Content-Length: 85 Content-Type: Text/Plain Set-Cookie: ASPSESSIONIDSEHSCTTR=FNBHGPBDMGDJCNLCDCDPGKCA; secure; path=/ Cache-control: private VPSProtocol=3.00 Status=OK StatusDetail=The transaction was RELEASEed successfully. tests/Mock/DirectPurchase3dSecure.txt 0000604 00000001144 15173220556 0013645 0 ustar 00 HTTP/1.1 200 OK Date: Sat, 16 Feb 2013 06:53:15 GMT Server: Microsoft-IIS/6.0 P3P: CP="CUR" X-Powered-By: ASP.NET Content-Length: 359 Content-Type: Text/Plain Set-Cookie: ASPSESSIONIDSEHSCTTR=FDNGGPBDBPAHLBIMINACENLN; secure; path=/ Cache-control: private VPSProtocol=3.00 Status=3DAUTH 3DSecureStatus=OK MD=065379457749061954 ACSURL=https://test.sagepay.com/Simulator/3DAuthPage.asp PAReq=BSkaFwYFFTYAGyFbAB0LFRYWBwsBZw0EGwECEX9YRGFWc08pJCVVKgAANS0KADoZCCAMBnIeOxcWRg0LERdOOTQRDFRdVHNYUgwTMBsBCxABJw4DJHE+ERgPCi8MVC0HIAROCAAfBUk4ER89DD0IWDkvMQ1VdFwoUFgwXVYvbHgvMkdBXXNbQGIjdl1ZUEc1XSwqAAgUUicYBDYcB3I2AjYjIzsn LICENSE 0000604 00000002047 15173220556 0005556 0 ustar 00 Copyright (c) 2012-2013 Adrian Macneil Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. .gitignore 0000604 00000000060 15173220556 0006532 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml
| ver. 1.4 |
Github
|
.
| PHP 8.3.23 | Generation time: 0 |
proxy
|
phpinfo
|
Settings