File manager - Edit - /home/opticamezl/www/newok/omnipay.tar
Back
paymentexpress/src/PxPostGateway.php 0000604 00000003613 15173176031 0013715 0 ustar 00 <?php namespace Omnipay\PaymentExpress; use Omnipay\Common\AbstractGateway; use Omnipay\PaymentExpress\Message\PxPostAuthorizeRequest; use Omnipay\PaymentExpress\Message\PxPostCaptureRequest; use Omnipay\PaymentExpress\Message\PxPostPurchaseRequest; use Omnipay\PaymentExpress\Message\PxPostRefundRequest; /** * DPS PaymentExpress PxPost Gateway */ class PxPostGateway extends AbstractGateway { public function getName() { return 'PaymentExpress PxPost'; } public function getDefaultParameters() { return array( 'username' => '', 'password' => '', ); } public function getUsername() { return $this->getParameter('username'); } public function setUsername($value) { return $this->setParameter('username', $value); } public function getPassword() { return $this->getParameter('password'); } public function setPassword($value) { return $this->setParameter('password', $value); } public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPostAuthorizeRequest', $parameters); } public function capture(array $parameters = array()) { return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPostCaptureRequest', $parameters); } public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPostPurchaseRequest', $parameters); } public function refund(array $parameters = array()) { return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPostRefundRequest', $parameters); } public function createCard(array $parameters = array()) { return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPostCreateCardRequest', $parameters); } } paymentexpress/src/PxPayGateway.php 0000604 00000003705 15173176031 0013523 0 ustar 00 <?php namespace Omnipay\PaymentExpress; use Omnipay\Common\AbstractGateway; use Omnipay\PaymentExpress\Message\PxPayAuthorizeRequest; use Omnipay\PaymentExpress\Message\PxPayCompleteAuthorizeRequest; use Omnipay\PaymentExpress\Message\PxPayPurchaseRequest; /** * DPS PaymentExpress PxPay Gateway */ class PxPayGateway extends AbstractGateway { public function getName() { return 'PaymentExpress PxPay'; } public function getDefaultParameters() { return array( 'username' => '', 'password' => '', ); } public function getUsername() { return $this->getParameter('username'); } public function setUsername($value) { return $this->setParameter('username', $value); } public function getPassword() { return $this->getParameter('password'); } public function setPassword($value) { return $this->setParameter('password', $value); } public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPayAuthorizeRequest', $parameters); } public function completeAuthorize(array $parameters = array()) { return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPayCompleteAuthorizeRequest', $parameters); } public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPayPurchaseRequest', $parameters); } public function completePurchase(array $parameters = array()) { return $this->completeAuthorize($parameters); } public function createCard(array $parameters = array()) { return $this->createRequest('\Omnipay\PaymentExpress\Message\PxPayCreateCardRequest', $parameters); } public function completeCreateCard(array $parameters = array()) { return $this->completeAuthorize($parameters); } } paymentexpress/src/Message/PxPostCreateCardRequest.php 0000604 00000001221 15173176031 0017237 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; /** * PaymentExpress PxPost Create Credit Card Request */ class PxPostCreateCardRequest extends PxPostAuthorizeRequest { public function getData() { $this->validate('card'); $this->getCard()->validate(); $data = $this->getBaseData(); $data->Amount = '1.00'; $data->EnableAddBillCard = 1; $data->CardNumber = $this->getCard()->getNumber(); $data->CardHolderName = $this->getCard()->getName(); $data->DateExpiry = $this->getCard()->getExpiryDate('my'); $data->Cvc2 = $this->getCard()->getCvv(); return $data; } } paymentexpress/src/Message/PxPayCreateCardRequest.php 0000604 00000000575 15173176031 0017056 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; /** * PaymentExpress PxPost Create Credit Card Request */ class PxPayCreateCardRequest extends PxPayAuthorizeRequest { public function getData() { $this->setAmount('1.00'); $this->setCurrency('NZD'); $data = parent::getData(); $data->EnableAddBillCard = 1; return $data; } } paymentexpress/src/Message/PxPostAuthorizeRequest.php 0000604 00000004011 15173176031 0017214 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; use Omnipay\Common\Message\AbstractRequest; /** * PaymentExpress PxPost Authorize Request */ class PxPostAuthorizeRequest extends AbstractRequest { protected $endpoint = 'https://sec.paymentexpress.com/pxpost.aspx'; protected $action = 'Auth'; public function getUsername() { return $this->getParameter('username'); } public function setUsername($value) { return $this->setParameter('username', $value); } public function getPassword() { return $this->getParameter('password'); } public function setPassword($value) { return $this->setParameter('password', $value); } protected function getBaseData() { $data = new \SimpleXMLElement('<Txn />'); $data->PostUsername = $this->getUsername(); $data->PostPassword = $this->getPassword(); $data->TxnType = $this->action; return $data; } public function getData() { $this->validate('amount'); $data = $this->getBaseData(); $data->InputCurrency = $this->getCurrency(); $data->Amount = $this->getAmount(); $data->MerchantReference = $this->getDescription(); if ($this->getCardReference()) { $data->DpsBillingId = $this->getCardReference(); } elseif ($this->getCard()) { $this->getCard()->validate(); $data->CardNumber = $this->getCard()->getNumber(); $data->CardHolderName = $this->getCard()->getName(); $data->DateExpiry = $this->getCard()->getExpiryDate('my'); $data->Cvc2 = $this->getCard()->getCvv(); } else { // either cardReference or card is required $this->validate('card'); } return $data; } public function sendData($data) { $httpResponse = $this->httpClient->post($this->endpoint, null, $data->asXML())->send(); return $this->response = new Response($this, $httpResponse->xml()); } } paymentexpress/src/Message/PxPostRefundRequest.php 0000604 00000000277 15173176031 0016477 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; /** * PaymentExpress PxPost Refund Request */ class PxPostRefundRequest extends PxPostCaptureRequest { protected $action = 'Refund'; } paymentexpress/src/Message/PxPostCaptureRequest.php 0000604 00000000722 15173176031 0016652 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; /** * PaymentExpress PxPost Capture Request */ class PxPostCaptureRequest extends PxPostAuthorizeRequest { protected $action = 'Complete'; public function getData() { $this->validate('transactionReference', 'amount'); $data = $this->getBaseData(); $data->DpsTxnRef = $this->getTransactionReference(); $data->Amount = $this->getAmount(); return $data; } } paymentexpress/src/Message/PxPayCompleteAuthorizeRequest.php 0000604 00000001461 15173176031 0020517 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; use SimpleXMLElement; use Omnipay\Common\Exception\InvalidResponseException; /** * PaymentExpress PxPay Complete Authorize Request */ class PxPayCompleteAuthorizeRequest extends PxPayAuthorizeRequest { public function getData() { $result = $this->httpRequest->query->get('result'); if (empty($result)) { throw new InvalidResponseException; } // validate dps response $data = new SimpleXMLElement('<ProcessResponse/>'); $data->PxPayUserId = $this->getUsername(); $data->PxPayKey = $this->getPassword(); $data->Response = $result; return $data; } protected function createResponse($data) { return $this->response = new Response($this, $data); } } paymentexpress/src/Message/PxPayPurchaseRequest.php 0000604 00000000304 15173176031 0016621 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; /** * PaymentExpress PxPay Purchase Request */ class PxPayPurchaseRequest extends PxPayAuthorizeRequest { protected $action = 'Purchase'; } paymentexpress/src/Message/Response.php 0000604 00000001706 15173176031 0014321 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; use Omnipay\Common\Message\AbstractResponse; /** * PaymentExpress Response */ class Response extends AbstractResponse { public function isSuccessful() { return 1 === (int) $this->data->Success; } public function getTransactionReference() { return empty($this->data->DpsTxnRef) ? null : (string) $this->data->DpsTxnRef; } public function getCardReference() { if (! empty($this->data->Transaction->DpsBillingId)) { return (string) $this->data->Transaction->DpsBillingId; } elseif (! empty($this->data->DpsBillingId)) { return (string) $this->data->DpsBillingId; } return null; } public function getMessage() { if (isset($this->data->HelpText)) { return (string) $this->data->HelpText; } else { return (string) $this->data->ResponseText; } } } paymentexpress/src/Message/PxPayAuthorizeRequest.php 0000604 00000003171 15173176031 0017026 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; use SimpleXMLElement; use Omnipay\Common\Message\AbstractRequest; /** * PaymentExpress PxPay Authorize Request */ class PxPayAuthorizeRequest extends AbstractRequest { protected $endpoint = 'https://sec.paymentexpress.com/pxaccess/pxpay.aspx'; protected $action = 'Auth'; public function getUsername() { return $this->getParameter('username'); } public function setUsername($value) { return $this->setParameter('username', $value); } public function getPassword() { return $this->getParameter('password'); } public function setPassword($value) { return $this->setParameter('password', $value); } public function getData() { $this->validate('amount', 'returnUrl'); $data = new SimpleXMLElement('<GenerateRequest/>'); $data->PxPayUserId = $this->getUsername(); $data->PxPayKey = $this->getPassword(); $data->TxnType = $this->action; $data->AmountInput = $this->getAmount(); $data->CurrencyInput = $this->getCurrency(); $data->MerchantReference = $this->getDescription(); $data->UrlSuccess = $this->getReturnUrl(); $data->UrlFail = $this->getReturnUrl(); return $data; } public function sendData($data) { $httpResponse = $this->httpClient->post($this->endpoint, null, $data->asXML())->send(); return $this->createResponse($httpResponse->xml()); } protected function createResponse($data) { return $this->response = new PxPayAuthorizeResponse($this, $data); } } paymentexpress/src/Message/PxPostPurchaseRequest.php 0000604 00000000307 15173176031 0017020 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; /** * PaymentExpress PxPost Purchase Request */ class PxPostPurchaseRequest extends PxPostAuthorizeRequest { protected $action = 'Purchase'; } paymentexpress/src/Message/PxPayAuthorizeResponse.php 0000604 00000001706 15173176031 0017176 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RedirectResponseInterface; /** * PaymentExpress PxPay Authorize Response */ class PxPayAuthorizeResponse extends AbstractResponse implements RedirectResponseInterface { public function isSuccessful() { return false; } public function isRedirect() { return 1 === (int) $this->data['valid']; } public function getTransactionReference() { return null; } public function getMessage() { if (!$this->isRedirect()) { return (string) $this->data->URI; } } public function getRedirectUrl() { if ($this->isRedirect()) { return (string) $this->data->URI; } } public function getRedirectMethod() { return 'GET'; } public function getRedirectData() { return null; } } paymentexpress/.travis.yml 0000604 00000000372 15173176031 0011746 0 ustar 00 language: php php: - 5.3 - 5.4 - 5.5 - 5.6 - hhvm matrix: allow_failures: - php: hhvm before_script: - composer install -n --dev --prefer-source script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text paymentexpress/LICENSE 0000604 00000002047 15173176031 0010643 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. paymentexpress/phpunit.xml.dist 0000604 00000001512 15173176031 0013005 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> paymentexpress/composer.json 0000604 00000002132 15173176031 0012353 0 ustar 00 { "name": "omnipay/paymentexpress", "type": "library", "description": "Payment Express (DPS) driver for the Omnipay payment processing library", "keywords": [ "direct payment solutions", "dps", "gateway", "merchant", "omnipay", "pay", "payment express", "payment", "paymentexpress", "pxaccess", "pxpay", "pxpost" ], "homepage": "https://github.com/thephpleague/omnipay-paymentexpress", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-paymentexpress/contributors" } ], "autoload": { "psr-4": { "Omnipay\\PaymentExpress\\" : "src/" } }, "require": { "omnipay/common": "~2.0" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } paymentexpress/README.md 0000604 00000003710 15173176031 0011113 0 ustar 00 # Omnipay: Payment Express **DPS Payment Express driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-paymentexpress) [](https://packagist.org/packages/omnipay/paymentexpress) [](https://packagist.org/packages/omnipay/paymentexpress) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements Payment Express 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/paymentexpress": "~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: * PaymentExpress_PxPay * PaymentExpress_PxPost 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-paymentexpress/issues), or better yet, fork the library and submit a pull request. paymentexpress/tests/PxPostGatewayTest.php 0000604 00000010211 15173176032 0015121 0 ustar 00 <?php namespace Omnipay\PaymentExpress; use Omnipay\Tests\GatewayTestCase; class PxPostGatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new PxPostGateway($this->getHttpClient(), $this->getHttpRequest()); $this->options = array( 'amount' => '10.00', 'card' => $this->getValidCard(), ); } public function testAuthorizeSuccess() { $this->setMockHttpResponse('PxPostPurchaseSuccess.txt'); $response = $this->gateway->authorize($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('000000030884cdc6', $response->getTransactionReference()); $this->assertSame('Transaction Approved', $response->getMessage()); } public function testAuthorizeFailure() { $this->setMockHttpResponse('PxPostPurchaseFailure.txt'); $response = $this->gateway->authorize($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('The transaction was Declined (U5)', $response->getMessage()); } public function testCaptureSuccess() { $this->setMockHttpResponse('PxPostPurchaseSuccess.txt'); $options = array( 'amount' => '10.00', 'transactionReference' => '000000030884cdc6', ); $response = $this->gateway->capture($options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('000000030884cdc6', $response->getTransactionReference()); } public function testPurchaseSuccess() { $this->setMockHttpResponse('PxPostPurchaseSuccess.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('000000030884cdc6', $response->getTransactionReference()); $this->assertSame('Transaction Approved', $response->getMessage()); } public function testPurchaseFailure() { $this->setMockHttpResponse('PxPostPurchaseFailure.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('The transaction was Declined (U5)', $response->getMessage()); } public function testRefundSuccess() { $this->setMockHttpResponse('PxPostPurchaseSuccess.txt'); $options = array( 'amount' => '10.00', 'transactionReference' => '000000030884cdc6', ); $response = $this->gateway->refund($options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('000000030884cdc6', $response->getTransactionReference()); } public function testCreateCardSuccess() { $this->setMockHttpResponse('PxPostCreateCardSuccess.txt'); $response = $this->gateway->createCard($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('00000001040c73ea', $response->getTransactionReference()); $this->assertSame('0000010009328404', $response->getCardReference()); $this->assertSame('Transaction Approved', $response->getMessage()); } public function testCreateCardFailure() { $this->setMockHttpResponse('PxPostCreateCardFailure.txt'); $response = $this->gateway->createCard($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('An Invalid Card Number was entered. Check the card number', $response->getMessage()); } } paymentexpress/tests/Message/PxPayAuthorizeResponseTest.php 0000604 00000003153 15173176032 0020410 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; use Omnipay\Tests\TestCase; class PxPayAuthorizeResponseTest extends TestCase { public function testPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('PxPayPurchaseSuccess.txt'); $response = new PxPayAuthorizeResponse($this->getMockRequest(), $httpResponse->xml()); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertSame('https://sec.paymentexpress.com/pxpay/pxpay.aspx?userid=Developer&request=v5H7JrBTzH-4Whs__1iQnz4RGSb9qxRKNR4kIuDP8kIkQzIDiIob9GTIjw_9q_AdRiR47ViWGVx40uRMu52yz2mijT39YtGeO7cZWrL5rfnx0Mc4DltIHRnIUxy1EO1srkNpxaU8fT8_1xMMRmLa-8Fd9bT8Oq0BaWMxMquYa1hDNwvoGs1SJQOAJvyyKACvvwsbMCC2qJVyN0rlvwUoMtx6gGhvmk7ucEsPc_Cyr5kNl3qURnrLKxINnS0trdpU4kXPKOlmT6VacjzT1zuj_DnrsWAPFSFq-hGsow6GpKKciQ0V0aFbAqECN8rl_c-aZWFFy0gkfjnUM4qp6foS0KMopJlPzGAgMjV6qZ0WfleOT64c3E-FRLMP5V_-mILs8a', $response->getRedirectUrl()); $this->assertSame('GET', $response->getRedirectMethod()); } public function testPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('PxPayPurchaseFailure.txt'); $response = new PxPayAuthorizeResponse($this->getMockRequest(), $httpResponse->xml()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Invalid Key', $response->getMessage()); } } paymentexpress/tests/Message/ResponseTest.php 0000604 00000006562 15173176032 0015542 0 ustar 00 <?php namespace Omnipay\PaymentExpress\Message; use Omnipay\Tests\TestCase; class ResponseTest extends TestCase { public function testPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('PxPostPurchaseSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->xml()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('000000030884cdc6', $response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('Transaction Approved', $response->getMessage()); } public function testPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('PxPostPurchaseFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->xml()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('The transaction was Declined (U5)', $response->getMessage()); } public function testCompletePurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('PxPayCompletePurchaseSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->xml()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('0000000103f5dc65', $response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('APPROVED', $response->getMessage()); } public function testCompletePurchaseFailure() { $httpResponse = $this->getMockHttpResponse('PxPayCompletePurchaseFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->xml()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('Length of the data to decrypt is invalid.', $response->getMessage()); } public function testCreateCardSuccess() { $httpResponse = $this->getMockHttpResponse('PxPostCreateCardSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->xml()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('00000001040c73ea', $response->getTransactionReference()); $this->assertSame('0000010009328404', $response->getCardReference()); $this->assertSame('Transaction Approved', $response->getMessage()); } public function testCreateCardFailure() { $httpResponse = $this->getMockHttpResponse('PxPostCreateCardFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->xml()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('An Invalid Card Number was entered. Check the card number', $response->getMessage()); } } paymentexpress/tests/PxPayGatewayTest.php 0000604 00000020342 15173176032 0014733 0 ustar 00 <?php namespace Omnipay\PaymentExpress; use Omnipay\Tests\GatewayTestCase; class PxPayGatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new PxPayGateway($this->getHttpClient(), $this->getHttpRequest()); $this->options = array( 'amount' => '10.00', 'returnUrl' => 'https://www.example.com/return', ); } public function testAuthorizeSuccess() { $this->setMockHttpResponse('PxPayPurchaseSuccess.txt'); $response = $this->gateway->authorize($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertSame('https://sec.paymentexpress.com/pxpay/pxpay.aspx?userid=Developer&request=v5H7JrBTzH-4Whs__1iQnz4RGSb9qxRKNR4kIuDP8kIkQzIDiIob9GTIjw_9q_AdRiR47ViWGVx40uRMu52yz2mijT39YtGeO7cZWrL5rfnx0Mc4DltIHRnIUxy1EO1srkNpxaU8fT8_1xMMRmLa-8Fd9bT8Oq0BaWMxMquYa1hDNwvoGs1SJQOAJvyyKACvvwsbMCC2qJVyN0rlvwUoMtx6gGhvmk7ucEsPc_Cyr5kNl3qURnrLKxINnS0trdpU4kXPKOlmT6VacjzT1zuj_DnrsWAPFSFq-hGsow6GpKKciQ0V0aFbAqECN8rl_c-aZWFFy0gkfjnUM4qp6foS0KMopJlPzGAgMjV6qZ0WfleOT64c3E-FRLMP5V_-mILs8a', $response->getRedirectUrl()); $this->assertSame('GET', $response->getRedirectMethod()); } public function testAuthorizeFailure() { $this->setMockHttpResponse('PxPayPurchaseFailure.txt'); $response = $this->gateway->authorize($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Invalid Key', $response->getMessage()); } public function testPurchaseSuccess() { $this->setMockHttpResponse('PxPayPurchaseSuccess.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertSame('https://sec.paymentexpress.com/pxpay/pxpay.aspx?userid=Developer&request=v5H7JrBTzH-4Whs__1iQnz4RGSb9qxRKNR4kIuDP8kIkQzIDiIob9GTIjw_9q_AdRiR47ViWGVx40uRMu52yz2mijT39YtGeO7cZWrL5rfnx0Mc4DltIHRnIUxy1EO1srkNpxaU8fT8_1xMMRmLa-8Fd9bT8Oq0BaWMxMquYa1hDNwvoGs1SJQOAJvyyKACvvwsbMCC2qJVyN0rlvwUoMtx6gGhvmk7ucEsPc_Cyr5kNl3qURnrLKxINnS0trdpU4kXPKOlmT6VacjzT1zuj_DnrsWAPFSFq-hGsow6GpKKciQ0V0aFbAqECN8rl_c-aZWFFy0gkfjnUM4qp6foS0KMopJlPzGAgMjV6qZ0WfleOT64c3E-FRLMP5V_-mILs8a', $response->getRedirectUrl()); $this->assertSame('GET', $response->getRedirectMethod()); } public function testPurchaseFailure() { $this->setMockHttpResponse('PxPayPurchaseFailure.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Invalid Key', $response->getMessage()); } public function testCreateCardSuccess() { $this->setMockHttpResponse('PxPayCreateCardSuccess.txt'); $response = $this->gateway->authorize($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertSame('https://sec.paymentexpress.com/pxmi3/EF4054F622D6C4C1B0FA3975F5B37D5883A7AA411DF778AEBA9C4E3CBE1B394B50478552233E3FBD7', $response->getRedirectUrl()); $this->assertSame('GET', $response->getRedirectMethod()); } public function testCreateCardFailure() { $this->setMockHttpResponse('PxPayCreateCardFailure.txt'); $response = $this->gateway->authorize($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('userpass too short', $response->getMessage()); } public function testCompleteAuthorizeSuccess() { $this->getHttpRequest()->query->replace(array('result' => 'abc123')); $this->setMockHttpResponse('PxPayCompletePurchaseSuccess.txt'); $response = $this->gateway->completeAuthorize($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('0000000103f5dc65', $response->getTransactionReference()); $this->assertSame('APPROVED', $response->getMessage()); } public function testCompleteAuthorizeFailure() { $this->getHttpRequest()->query->replace(array('result' => 'abc123')); $this->setMockHttpResponse('PxPayCompletePurchaseFailure.txt'); $response = $this->gateway->completeAuthorize($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Length of the data to decrypt is invalid.', $response->getMessage()); } public function testCompleteCreateCardSuccess() { $this->getHttpRequest()->query->replace(array('result' => 'abc123')); $this->setMockHttpResponse('PxPayCompleteCreateCardSuccess.txt'); $response = $this->gateway->completeAuthorize($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('000000030a1806f0', $response->getTransactionReference()); $this->assertSame('0000030007487668', $response->getCardReference()); $this->assertSame('APPROVED', $response->getMessage()); } public function testCompleteCreateCardFailure() { $this->getHttpRequest()->query->replace(array('result' => 'abc123')); $this->setMockHttpResponse('PxPayCompleteCreateCardFailure.txt'); $response = $this->gateway->completeAuthorize($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Length of the data to decrypt is invalid.', $response->getMessage()); } /** * @expectedException Omnipay\Common\Exception\InvalidResponseException */ public function testCompleteAuthorizeInvalid() { $this->getHttpRequest()->query->replace(array()); $response = $this->gateway->completeAuthorize($this->options)->send(); } public function testCompletePurchaseSuccess() { $this->getHttpRequest()->query->replace(array('result' => 'abc123')); $this->setMockHttpResponse('PxPayCompletePurchaseSuccess.txt'); $response = $this->gateway->completePurchase($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('0000000103f5dc65', $response->getTransactionReference()); $this->assertSame('APPROVED', $response->getMessage()); } public function testCompletePurchaseFailure() { $this->getHttpRequest()->query->replace(array('result' => 'abc123')); $this->setMockHttpResponse('PxPayCompletePurchaseFailure.txt'); $response = $this->gateway->completePurchase($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Length of the data to decrypt is invalid.', $response->getMessage()); } /** * @expectedException Omnipay\Common\Exception\InvalidResponseException */ public function testCompletePurchaseInvalid() { $this->getHttpRequest()->query->replace(array()); $response = $this->gateway->completePurchase($this->options)->send(); } } paymentexpress/tests/Mock/PxPayCompletePurchaseSuccess.txt 0000604 00000002063 15173176032 0020207 0 ustar 00 HTTP/1.1 200 OK Server: DPS_PX_SERVER Cache-Control: private Content-Length: 866 Content-Type: application/xhtml+xml; charset=utf-8 Expires: Sat, 23 Feb 2013 15:11:45 GMT Date: Sat, 23 Feb 2013 15:12:45 GMT <Response valid="1"><Success>1</Success><TxnType>Auth</TxnType><CurrencyInput>NZD</CurrencyInput><MerchantReference></MerchantReference><TxnData1></TxnData1><TxnData2></TxnData2><TxnData3></TxnData3><AuthCode>041211</AuthCode><CardName>Visa</CardName><CardHolderName>JDFKL FDJKSL</CardHolderName><CardNumber>411111........11</CardNumber><DateExpiry>0819</DateExpiry><ClientInfo>115.67.229.192</ClientInfo><TxnId>P075985DA31094D8</TxnId><EmailAddress></EmailAddress><DpsTxnRef>0000000103f5dc65</DpsTxnRef><BillingId></BillingId><DpsBillingId></DpsBillingId><AmountSettlement>10.00</AmountSettlement><CurrencySettlement>NZD</CurrencySettlement><DateSettlement>20130224</DateSettlement><TxnMac></TxnMac><ResponseText>APPROVED</ResponseText><CardNumber2></CardNumber2><IssuerCountryId>0</IssuerCountryId><Cvc2ResultCode>NotUsed</Cvc2ResultCode><ReCo>00</ReCo></Response> paymentexpress/tests/Mock/PxPayPurchaseSuccess.txt 0000604 00000001310 15173176032 0016510 0 ustar 00 HTTP/1.1 200 OK Server: DPS_PX_SERVER Cache-Control: private Content-Length: 507 Content-Type: application/xhtml+xml; charset=utf-8 Expires: Sat, 23 Feb 2013 14:56:42 GMT Date: Sat, 23 Feb 2013 14:57:41 GMT <Request valid="1"><URI>https://sec.paymentexpress.com/pxpay/pxpay.aspx?userid=Developer&request=v5H7JrBTzH-4Whs__1iQnz4RGSb9qxRKNR4kIuDP8kIkQzIDiIob9GTIjw_9q_AdRiR47ViWGVx40uRMu52yz2mijT39YtGeO7cZWrL5rfnx0Mc4DltIHRnIUxy1EO1srkNpxaU8fT8_1xMMRmLa-8Fd9bT8Oq0BaWMxMquYa1hDNwvoGs1SJQOAJvyyKACvvwsbMCC2qJVyN0rlvwUoMtx6gGhvmk7ucEsPc_Cyr5kNl3qURnrLKxINnS0trdpU4kXPKOlmT6VacjzT1zuj_DnrsWAPFSFq-hGsow6GpKKciQ0V0aFbAqECN8rl_c-aZWFFy0gkfjnUM4qp6foS0KMopJlPzGAgMjV6qZ0WfleOT64c3E-FRLMP5V_-mILs8a</URI></Request> paymentexpress/tests/Mock/PxPostPurchaseFailure.txt 0000604 00000005125 15173176032 0016673 0 ustar 00 HTTP/1.1 200 OK Server: DPS_PX_SERVER Cache-Control: private Content-Length: 2435 Content-Type: application/xhtml+xml; charset=utf-8 Expires: Sat, 23 Feb 2013 14:09:13 GMT Date: Sat, 23 Feb 2013 14:10:12 GMT <Txn><Transaction success="0" reco="U5" responseText="DECLINED" pxTxn="true"><Authorized>0</Authorized><ReCo>U5</ReCo><RxDate>20130223141030</RxDate><RxDateLocal>20130223141030</RxDateLocal><LocalTimeZone>UTC</LocalTimeZone><MerchantReference></MerchantReference><CardName></CardName><Retry>0</Retry><StatusRequired>0</StatusRequired><AuthCode></AuthCode><AmountBalance>0.00</AmountBalance><Amount>10.00</Amount><CurrencyId>554</CurrencyId><InputCurrencyId>554</InputCurrencyId><InputCurrencyName>NZD</InputCurrencyName><CurrencyRate>1.00</CurrencyRate><CurrencyName>NZD</CurrencyName><CardHolderName>FJKSDL FJDKSL</CardHolderName><DateSettlement>19800101</DateSettlement><TxnType>Purchase</TxnType><CardNumber>411111........11</CardNumber><TxnMac></TxnMac><DateExpiry>0419</DateExpiry><ProductId></ProductId><AcquirerDate></AcquirerDate><AcquirerTime></AcquirerTime><AcquirerId>0</AcquirerId><Acquirer></Acquirer><AcquirerReCo>D5</AcquirerReCo><AcquirerResponseText></AcquirerResponseText><TestMode>0</TestMode><CardId>0</CardId><CardHolderResponseText>DECLINED</CardHolderResponseText><CardHolderHelpText>The transaction was Declined (U5)</CardHolderHelpText><CardHolderResponseDescription>The transaction was Declined (U5)</CardHolderResponseDescription><MerchantResponseText>DECLINED</MerchantResponseText><MerchantHelpText>The transaction was Declined (U5)</MerchantHelpText><MerchantResponseDescription>The transaction was Declined (U5)</MerchantResponseDescription><UrlFail></UrlFail><UrlSuccess></UrlSuccess><EnablePostResponse>0</EnablePostResponse><PxPayName></PxPayName><PxPayLogoSrc></PxPayLogoSrc><PxPayUserId></PxPayUserId><PxPayXsl></PxPayXsl><PxPayBgColor></PxPayBgColor><PxPayOptions></PxPayOptions><Cvc2ResultCode></Cvc2ResultCode><AcquirerPort>-</AcquirerPort><AcquirerTxnRef>0</AcquirerTxnRef><GroupAccount>-1</GroupAccount><DpsTxnRef></DpsTxnRef><AllowRetry>0</AllowRetry><DpsBillingId></DpsBillingId><BillingId></BillingId><TransactionId>00000000</TransactionId><PxHostId>00000001</PxHostId><RmReason></RmReason><RmReasonId>0000000000000000</RmReasonId><RiskScore>-1</RiskScore><RiskScoreText></RiskScoreText></Transaction><ReCo>U5</ReCo><ResponseText>DECLINED</ResponseText><HelpText>The transaction was Declined (U5)</HelpText><Success>0</Success><DpsTxnRef></DpsTxnRef><TxnRef></TxnRef><RmReason></RmReason><RmReasonId>0000000000000000</RmReasonId><RiskScore>-1</RiskScore><RiskScoreText></RiskScoreText></Txn> paymentexpress/tests/Mock/PxPostCreateCardSuccess.txt 0000604 00000005300 15173176032 0017132 0 ustar 00 HTTP/1.1 200 OK Server: DPS_PX_SERVER Cache-Control: private Content-Length: 2542 Content-Type: application/xhtml+xml; charset=utf-8 Expires: Tue, 26 Feb 2013 16:50:08 GMT Date: Tue, 26 Feb 2013 16:51:09 GMT <Txn><Transaction success="1" reco="00" responseText="APPROVED" pxTxn="true"><Authorized>1</Authorized><ReCo>00</ReCo><RxDate>20130226165114</RxDate><RxDateLocal>20130226165114</RxDateLocal><LocalTimeZone>UTC</LocalTimeZone><MerchantReference></MerchantReference><CardName>Visa</CardName><Retry>0</Retry><StatusRequired>0</StatusRequired><AuthCode>055111040c73ea00000001</AuthCode><AmountBalance>0.00</AmountBalance><Amount>1.00</Amount><CurrencyId>554</CurrencyId><InputCurrencyId>554</InputCurrencyId><InputCurrencyName>NZD</InputCurrencyName><CurrencyRate>1.00</CurrencyRate><CurrencyName>NZD</CurrencyName><CardHolderName>FJKSDL FJDKSL</CardHolderName><DateSettlement>20130227</DateSettlement><TxnType>Auth</TxnType><CardNumber>411111........11</CardNumber><TxnMac>2BC20210</TxnMac><DateExpiry>0419</DateExpiry><ProductId></ProductId><AcquirerDate>20130227</AcquirerDate><AcquirerTime>055111</AcquirerTime><AcquirerId>9001</AcquirerId><Acquirer>Undefined</Acquirer><AcquirerReCo>00</AcquirerReCo><AcquirerResponseText>APPROVED</AcquirerResponseText><TestMode>0</TestMode><CardId>2</CardId><CardHolderResponseText>APPROVED</CardHolderResponseText><CardHolderHelpText>The Transaction was approved</CardHolderHelpText><CardHolderResponseDescription>The Transaction was approved</CardHolderResponseDescription><MerchantResponseText>APPROVED</MerchantResponseText><MerchantHelpText>The Transaction was approved</MerchantHelpText><MerchantResponseDescription>The Transaction was approved</MerchantResponseDescription><UrlFail></UrlFail><UrlSuccess></UrlSuccess><EnablePostResponse>0</EnablePostResponse><PxPayName></PxPayName><PxPayLogoSrc></PxPayLogoSrc><PxPayUserId></PxPayUserId><PxPayXsl></PxPayXsl><PxPayBgColor></PxPayBgColor><PxPayOptions></PxPayOptions><Cvc2ResultCode>NotUsed</Cvc2ResultCode><AcquirerPort>10000000-10004021</AcquirerPort><AcquirerTxnRef>60744</AcquirerTxnRef><GroupAccount>9997</GroupAccount><DpsTxnRef>00000001040c73ea</DpsTxnRef><AllowRetry>1</AllowRetry><DpsBillingId>0000010009328404</DpsBillingId><BillingId></BillingId><TransactionId>040c73ea</TransactionId><PxHostId>00000001</PxHostId><RmReason></RmReason><RmReasonId>0000000000000000</RmReasonId><RiskScore>-1</RiskScore><RiskScoreText></RiskScoreText></Transaction><ReCo>00</ReCo><ResponseText>APPROVED</ResponseText><HelpText>Transaction Approved</HelpText><Success>1</Success><DpsTxnRef>00000001040c73ea</DpsTxnRef><TxnRef></TxnRef><RmReason></RmReason><RmReasonId>0000000000000000</RmReasonId><RiskScore>-1</RiskScore><RiskScoreText></RiskScoreText></Txn> paymentexpress/tests/Mock/PxPayCompleteCreateCardFailure.txt 0000604 00000001671 15173176032 0020415 0 ustar 00 HTTP/1.1 200 OK Server: DPS_PX_SERVER Cache-Control: private Content-Length: 744 Content-Type: application/xhtml+xml; charset=utf-8 Expires: Sat, 23 Feb 2013 15:14:26 GMT Date: Sat, 23 Feb 2013 15:15:26 GMT <Response valid="0"><Success></Success><TxnType></TxnType><CurrencyInput></CurrencyInput><MerchantReference></MerchantReference><TxnData1></TxnData1><TxnData2></TxnData2><TxnData3></TxnData3><AuthCode></AuthCode><CardName></CardName><CardHolderName></CardHolderName><CardNumber></CardNumber><DateExpiry></DateExpiry><ClientInfo></ClientInfo><TxnId></TxnId><EmailAddress></EmailAddress><DpsTxnRef></DpsTxnRef><BillingId></BillingId><DpsBillingId></DpsBillingId><AmountSettlement></AmountSettlement><CurrencySettlement></CurrencySettlement><TxnMac></TxnMac><ResponseText>Length of the data to decrypt is invalid.</ResponseText><CardNumber2></CardNumber2><IssuerCountryId></IssuerCountryId><Cvc2ResultCode></Cvc2ResultCode><ReCo></ReCo></Response> paymentexpress/tests/Mock/PxPayCreateCardFailure.txt 0000604 00000000412 15173176032 0016714 0 ustar 00 HTTP/1.1 200 OK Server: DPS_PX_SERVER Cache-Control: private Content-Length: 51 Content-Type: application/xhtml+xml; charset=utf-8 Expires: Sat, 23 Feb 2013 14:54:40 GMT Date: Sat, 23 Feb 2013 14:55:40 GMT <Request valid="0"><URI>userpass too short</URI></Request> paymentexpress/tests/Mock/PxPayCreateCardSuccess.txt 0000604 00000000557 15173176032 0016747 0 ustar 00 HTTP/1.1 200 OK Server: DPS_PX_SERVER Cache-Control: private Content-Length: 507 Content-Type: application/xhtml+xml; charset=utf-8 Expires: Sat, 23 Feb 2013 14:56:42 GMT Date: Sat, 23 Feb 2013 14:57:41 GMT <Request valid="1"><URI>https://sec.paymentexpress.com/pxmi3/EF4054F622D6C4C1B0FA3975F5B37D5883A7AA411DF778AEBA9C4E3CBE1B394B50478552233E3FBD7</URI></Request> paymentexpress/tests/Mock/PxPayCompleteCreateCardSuccess.txt 0000604 00000002700 15173176032 0020430 0 ustar 00 HTTP/1.1 200 OK Server: DPS_PX_SERVER Cache-Control: private Content-Length: 866 Content-Type: application/xhtml+xml; charset=utf-8 Expires: Sat, 23 Feb 2013 15:11:45 GMT Date: Sat, 23 Feb 2013 15:12:45 GMT <Response valid="1"><AmountSettlement>1.00</AmountSettlement><AuthCode>115141</AuthCode><CardName>Visa</CardName><CardNumber>411111........11</CardNumber><DateExpiry>1234</DateExpiry><DpsTxnRef>000000030a1806f0</DpsTxnRef><Success>1</Success><ResponseText>APPROVED</ResponseText><DpsBillingId>0000030007487668</DpsBillingId><CardHolderName>ABCD</CardHolderName><CurrencySettlement>NZD</CurrencySettlement><TxnData1></TxnData1><TxnData2></TxnData2><TxnData3></TxnData3><TxnType>Auth</TxnType><CurrencyInput>NZD</CurrencyInput><MerchantReference></MerchantReference><ClientInfo>122.62.25.44</ClientInfo><TxnId></TxnId><EmailAddress></EmailAddress><BillingId></BillingId><TxnMac>2BC20210</TxnMac><CardNumber2></CardNumber2><DateSettlement>20150401</DateSettlement><IssuerCountryId>0</IssuerCountryId><Cvc2ResultCode>NotUsed</Cvc2ResultCode><ReCo>00</ReCo><ProductSku></ProductSku><ShippingName></ShippingName><ShippingAddress></ShippingAddress><ShippingPostalCode></ShippingPostalCode><ShippingPhoneNumber></ShippingPhoneNumber><ShippingMethod></ShippingMethod><BillingName></BillingName><BillingPostalCode></BillingPostalCode><BillingAddress></BillingAddress><BillingPhoneNumber></BillingPhoneNumber><PhoneNumber></PhoneNumber><AccountInfo></AccountInfo></Response> paymentexpress/tests/Mock/PxPostCreateCardFailure.txt 0000604 00000005414 15173176032 0017117 0 ustar 00 HTTP/1.1 200 OK Server: DPS_PX_SERVER Cache-Control: private Content-Length: 2618 Content-Type: application/xhtml+xml; charset=utf-8 Expires: Tue, 26 Feb 2013 16:55:13 GMT Date: Tue, 26 Feb 2013 16:56:12 GMT <Txn><Transaction success="0" reco="QK" responseText="INVALID CARD NUMBER" pxTxn="true"><Authorized>0</Authorized><ReCo>QK</ReCo><RxDate>20130226165618</RxDate><RxDateLocal>20130226165618</RxDateLocal><LocalTimeZone>UTC</LocalTimeZone><MerchantReference></MerchantReference><CardName></CardName><Retry>0</Retry><StatusRequired>0</StatusRequired><AuthCode></AuthCode><AmountBalance>0.00</AmountBalance><Amount>1.00</Amount><CurrencyId>554</CurrencyId><InputCurrencyId>554</InputCurrencyId><InputCurrencyName>NZD</InputCurrencyName><CurrencyRate>1.00</CurrencyRate><CurrencyName>NZD</CurrencyName><CardHolderName>FJKSDL FJDKSL</CardHolderName><DateSettlement>19800101</DateSettlement><TxnType>Auth</TxnType><CardNumber>000000........00</CardNumber><TxnMac></TxnMac><DateExpiry>0419</DateExpiry><ProductId></ProductId><AcquirerDate></AcquirerDate><AcquirerTime></AcquirerTime><AcquirerId>9000</AcquirerId><Acquirer></Acquirer><AcquirerReCo>QK</AcquirerReCo><AcquirerResponseText>Invalid Card Number</AcquirerResponseText><TestMode>0</TestMode><CardId>0</CardId><CardHolderResponseText>INVALID CARD NUMBER</CardHolderResponseText><CardHolderHelpText>An Invalid Card Number was entered. Check the card number</CardHolderHelpText><CardHolderResponseDescription>An Invalid Card Number was entered. Check the card number</CardHolderResponseDescription><MerchantResponseText>INVALID CARD NUMBER</MerchantResponseText><MerchantHelpText>An Invalid Card Number was entered. Check the card number</MerchantHelpText><MerchantResponseDescription>An Invalid Card Number was entered. Check the card number</MerchantResponseDescription><UrlFail></UrlFail><UrlSuccess></UrlSuccess><EnablePostResponse>0</EnablePostResponse><PxPayName></PxPayName><PxPayLogoSrc></PxPayLogoSrc><PxPayUserId></PxPayUserId><PxPayXsl></PxPayXsl><PxPayBgColor></PxPayBgColor><PxPayOptions></PxPayOptions><Cvc2ResultCode></Cvc2ResultCode><AcquirerPort>-</AcquirerPort><AcquirerTxnRef>0</AcquirerTxnRef><GroupAccount>9997</GroupAccount><DpsTxnRef></DpsTxnRef><AllowRetry>0</AllowRetry><DpsBillingId></DpsBillingId><BillingId></BillingId><TransactionId>040c754e</TransactionId><PxHostId>00000001</PxHostId><RmReason></RmReason><RmReasonId>0000000000000000</RmReasonId><RiskScore>-1</RiskScore><RiskScoreText></RiskScoreText></Transaction><ReCo>QK</ReCo><ResponseText>INVALID CARD NUMBER</ResponseText><HelpText>An Invalid Card Number was entered. Check the card number</HelpText><Success>0</Success><DpsTxnRef></DpsTxnRef><TxnRef></TxnRef><RmReason></RmReason><RmReasonId>0000000000000000</RmReasonId><RiskScore>-1</RiskScore><RiskScoreText></RiskScoreText></Txn> paymentexpress/tests/Mock/PxPostPurchaseSuccess.txt 0000604 00000000315 15173176032 0016710 0 ustar 00 HTTP/1.1 200 OK <Txn><ReCo>00</ReCo><ResponseText>APPROVED</ResponseText><HelpText>Transaction Approved</HelpText><Success>1</Success><DpsTxnRef>000000030884cdc6</DpsTxnRef><TxnRef>inv1278</TxnRef></Txn> paymentexpress/tests/Mock/PxPayCompletePurchaseFailure.txt 0000604 00000001671 15173176032 0020172 0 ustar 00 HTTP/1.1 200 OK Server: DPS_PX_SERVER Cache-Control: private Content-Length: 744 Content-Type: application/xhtml+xml; charset=utf-8 Expires: Sat, 23 Feb 2013 15:14:26 GMT Date: Sat, 23 Feb 2013 15:15:26 GMT <Response valid="0"><Success></Success><TxnType></TxnType><CurrencyInput></CurrencyInput><MerchantReference></MerchantReference><TxnData1></TxnData1><TxnData2></TxnData2><TxnData3></TxnData3><AuthCode></AuthCode><CardName></CardName><CardHolderName></CardHolderName><CardNumber></CardNumber><DateExpiry></DateExpiry><ClientInfo></ClientInfo><TxnId></TxnId><EmailAddress></EmailAddress><DpsTxnRef></DpsTxnRef><BillingId></BillingId><DpsBillingId></DpsBillingId><AmountSettlement></AmountSettlement><CurrencySettlement></CurrencySettlement><TxnMac></TxnMac><ResponseText>Length of the data to decrypt is invalid.</ResponseText><CardNumber2></CardNumber2><IssuerCountryId></IssuerCountryId><Cvc2ResultCode></Cvc2ResultCode><ReCo></ReCo></Response> paymentexpress/tests/Mock/PxPayPurchaseFailure.txt 0000604 00000000403 15173176032 0016471 0 ustar 00 HTTP/1.1 200 OK Server: DPS_PX_SERVER Cache-Control: private Content-Length: 51 Content-Type: application/xhtml+xml; charset=utf-8 Expires: Sat, 23 Feb 2013 14:54:40 GMT Date: Sat, 23 Feb 2013 14:55:40 GMT <Request valid="0"><URI>Invalid Key</URI></Request> paymentexpress/CONTRIBUTING.md 0000604 00000001040 15173176032 0012060 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. paymentexpress/.gitignore 0000604 00000000060 15173176032 0011620 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml worldpay/CONTRIBUTING.md 0000604 00000001040 15173176032 0010632 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. worldpay/LICENSE 0000604 00000002047 15173176032 0007416 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. worldpay/composer.json 0000604 00000001652 15173176032 0011134 0 ustar 00 { "name": "omnipay/worldpay", "type": "library", "description": "WorldPay driver for the Omnipay payment processing library", "keywords": [ "gateway", "merchant", "omnipay", "pay", "payment", "worldpay" ], "homepage": "https://github.com/thephpleague/omnipay-worldpay", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-worldpay/contributors" } ], "autoload": { "psr-4": { "Omnipay\\WorldPay\\" : "src/" } }, "require": { "omnipay/common": "~2.0" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } worldpay/.gitignore 0000604 00000000060 15173176032 0010372 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml worldpay/phpunit.xml.dist 0000604 00000001512 15173176032 0011560 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> worldpay/tests/Message/CompletePurchaseResponseTest.php 0000604 00000004450 15173176032 0017472 0 ustar 00 <?php namespace Omnipay\WorldPay\Message; use Omnipay\Tests\TestCase; class CompletePurchaseResponseTest extends TestCase { public function testCompletePurchaseSuccess() { $response = new CompletePurchaseresponse( $this->getMockRequest(), array( 'transStatus' => 'Y', 'transId' => 'abc123', 'rawAuthMessage' => 'Success Message' ) ); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isCancelled()); $this->assertFalse($response->isRedirect()); $this->assertSame('abc123', $response->getTransactionReference()); $this->assertSame('Success Message', $response->getMessage()); } public function testCompletePurchaseCancel() { $response = new CompletePurchaseresponse( $this->getMockRequest(), array( 'transStatus' => 'C', 'transId' => null, 'rawAuthMessage' => 'Declined' ) ); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isCancelled()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Declined', $response->getMessage()); } public function testCompletePurchaseFailure() { $response = new CompletePurchaseresponse( $this->getMockRequest(), array( 'transStatus' => 'N', 'transId' => null, 'rawAuthMessage' => 'Declined' ) ); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isCancelled()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Declined', $response->getMessage()); } public function testCompletePurchaseInvalid() { $response = new CompletePurchaseresponse($this->getMockRequest(), array()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); } } worldpay/tests/Message/PurchaseResponseTest.php 0000604 00000001733 15173176032 0016002 0 ustar 00 <?php namespace Omnipay\WorldPay\Message; use Omnipay\Tests\TestCase; class PurchaseResponseTest extends TestCase { public function testPurchaseSuccess() { $response = new PurchaseResponse($this->getMockRequest(), array( 'amount' => 1000, 'returnUrl' => 'https://www.example.com/return', )); $this->getMockRequest()->shouldReceive('getEndpoint')->once()->andReturn('https://secure.worldpay.com/wcc/purchase'); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertSame('https://secure.worldpay.com/wcc/purchase?amount=1000&returnUrl=https%3A%2F%2Fwww.example.com%2Freturn', $response->getRedirectUrl()); $this->assertSame('GET', $response->getRedirectMethod()); $this->assertNull($response->getRedirectData()); } } worldpay/tests/Message/PurchaseRequestTest.php 0000604 00000002777 15173176032 0015645 0 ustar 00 <?php namespace Omnipay\WorldPay\Message; use Omnipay\Tests\TestCase; class PurchaseRequestTest extends TestCase { public function setUp() { $this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '10.00', 'returnUrl' => 'https://example.com/return', ) ); } public function testGetData() { $this->request->initialize( array( 'installationId' => 'id1', 'accountId' => 'id2', 'transactionId' => 'id3', 'description' => 'food', 'amount' => '12.00', 'currency' => 'GBP', 'returnUrl' => 'https://example.com/return', ) ); $data = $this->request->getData(); $this->assertSame('id1', $data['instId']); $this->assertSame('id2', $data['accId1']); $this->assertSame('id3', $data['cartId']); $this->assertSame('food', $data['desc']); $this->assertSame('12.00', $data['amount']); $this->assertSame('GBP', $data['currency']); $this->assertSame(0, $data['testMode']); $this->assertSame('https://example.com/return', $data['MC_callback']); } public function testGetDataTestMode() { $this->request->setTestMode(true); $data = $this->request->getData(); $this->assertSame(100, $data['testMode']); } } worldpay/tests/GatewayTest.php 0000604 00000004676 15173176032 0012537 0 ustar 00 <?php namespace Omnipay\WorldPay; use Omnipay\Tests\GatewayTestCase; class GatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); $this->gateway->setCallbackPassword('bar123'); $this->options = array( 'amount' => '10.00', 'returnUrl' => 'https://www.example.com/return', ); } public function testPurchase() { $response = $this->gateway->purchase($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertContains('https://secure.worldpay.com/wcc/purchase?', $response->getRedirectUrl()); } public function testCompletePurchaseSuccess() { $this->getHttpRequest()->request->replace( array( 'callbackPW' => 'bar123', 'transStatus' => 'Y', 'transId' => 'abc123', 'rawAuthMessage' => 'hello', ) ); $response = $this->gateway->completePurchase($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('abc123', $response->getTransactionReference()); $this->assertSame('hello', $response->getMessage()); } /** * @expectedException \Omnipay\Common\Exception\InvalidResponseException */ public function testCompletePurchaseInvalidCallbackPassword() { $this->getHttpRequest()->request->replace( array( 'callbackPW' => 'fake', ) ); $response = $this->gateway->completePurchase($this->options)->send(); } public function testCompletePurchaseError() { $this->getHttpRequest()->request->replace( array( 'callbackPW' => 'bar123', 'transStatus' => 'N', 'rawAuthMessage' => 'Declined', ) ); $response = $this->gateway->completePurchase($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Declined', $response->getMessage()); } } worldpay/src/Message/PurchaseRequest.php 0000604 00000006160 15173176032 0014420 0 ustar 00 <?php namespace Omnipay\WorldPay\Message; use Omnipay\Common\Message\AbstractRequest; /** * WorldPay Purchase Request */ class PurchaseRequest extends AbstractRequest { protected $liveEndpoint = 'https://secure.worldpay.com/wcc/purchase'; protected $testEndpoint = 'https://secure-test.worldpay.com/wcc/purchase'; public function getInstallationId() { return $this->getParameter('installationId'); } public function setInstallationId($value) { return $this->setParameter('installationId', $value); } public function getAccountId() { return $this->getParameter('accountId'); } public function setAccountId($value) { return $this->setParameter('accountId', $value); } public function getSecretWord() { return $this->getParameter('secretWord'); } public function setSecretWord($value) { return $this->setParameter('secretWord', $value); } public function getCallbackPassword() { return $this->getParameter('callbackPassword'); } public function setCallbackPassword($value) { return $this->setParameter('callbackPassword', $value); } public function getData() { $this->validate('amount'); // Either the nodifyUrl or the returnUrl can be provided. // The returnUrl is deprecated, as strictly this is a notifyUrl. if (!$this->getNotifyUrl()) { $this->validate('returnUrl'); } $data = array(); $data['instId'] = $this->getInstallationId(); $data['accId1'] = $this->getAccountId(); $data['cartId'] = $this->getTransactionId(); $data['desc'] = $this->getDescription(); $data['amount'] = $this->getAmount(); $data['currency'] = $this->getCurrency(); $data['testMode'] = $this->getTestMode() ? 100 : 0; $data['MC_callback'] = $this->getNotifyUrl() ?: $this->getReturnUrl(); if ($this->getCard()) { $data['name'] = $this->getCard()->getName(); $data['address1'] = $this->getCard()->getAddress1(); $data['address2'] = $this->getCard()->getAddress2(); $data['town'] = $this->getCard()->getCity(); $data['region'] = $this->getCard()->getState(); $data['postcode'] = $this->getCard()->getPostcode(); $data['country'] = $this->getCard()->getCountry(); $data['tel'] = $this->getCard()->getPhone(); $data['email'] = $this->getCard()->getEmail(); } if ($this->getSecretWord()) { $data['signatureFields'] = 'instId:amount:currency:cartId'; $signature_data = array($this->getSecretWord(), $data['instId'], $data['amount'], $data['currency'], $data['cartId']); $data['signature'] = md5(implode(':', $signature_data)); } return $data; } public function sendData($data) { return $this->response = new PurchaseResponse($this, $data); } public function getEndpoint() { return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; } } worldpay/src/Message/PurchaseResponse.php 0000604 00000001261 15173176032 0014563 0 ustar 00 <?php namespace Omnipay\WorldPay\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RedirectResponseInterface; /** * WorldPay Purchase Response */ class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface { public function isSuccessful() { return false; } public function isRedirect() { return true; } public function getRedirectUrl() { return $this->getRequest()->getEndpoint().'?'.http_build_query($this->data); } public function getRedirectMethod() { return 'GET'; } public function getRedirectData() { return null; } } worldpay/src/Message/CompletePurchaseRequest.php 0000604 00000001212 15173176032 0016102 0 ustar 00 <?php namespace Omnipay\WorldPay\Message; use Omnipay\Common\Exception\InvalidResponseException; /** * WorldPay Complete Purchase Request */ class CompletePurchaseRequest extends PurchaseRequest { public function getData() { $callbackPW = (string) $this->httpRequest->request->get('callbackPW'); if ($callbackPW !== $this->getCallbackPassword()) { throw new InvalidResponseException("Invalid callback password"); } return $this->httpRequest->request->all(); } public function sendData($data) { return $this->response = new CompletePurchaseResponse($this, $data); } } worldpay/src/Message/CompletePurchaseResponse.php 0000604 00000003076 15173176032 0016262 0 ustar 00 <?php namespace Omnipay\WorldPay\Message; use Omnipay\Common\Message\AbstractResponse; /** * WorldPay Complete Purchase Response */ class CompletePurchaseResponse extends AbstractResponse { public function isSuccessful() { return isset($this->data['transStatus']) && 'Y' === $this->data['transStatus']; } public function isCancelled() { return isset($this->data['transStatus']) && 'C' === $this->data['transStatus']; } public function getTransactionReference() { return isset($this->data['transId']) ? $this->data['transId'] : null; } public function getMessage() { return isset($this->data['rawAuthMessage']) ? $this->data['rawAuthMessage'] : null; } /** * Optional step: Redirect the customer back to your own domain. * * This is achieved by returning a HTML string containing a meta-redirect which is displayed by WorldPay * to the customer. This is far from ideal, but apparently (according to their support) this is the only * method currently available. * * @param string $returnUrl The URL to forward the customer to. * @param string|null $message Optional message to display to the customer before they are redirected. */ public function confirm($returnUrl, $message = null) { if (empty($message)) { $message = 'Thank you, your transaction has been processed. You are being redirected...'; } echo '<meta http-equiv="refresh" content="2;url='.$returnUrl.'" /><p>'.$message.'</p>'; exit; } } worldpay/src/Gateway.php 0000604 00000003525 15173176032 0011314 0 ustar 00 <?php namespace Omnipay\WorldPay; use Omnipay\Common\AbstractGateway; use Omnipay\WorldPay\Message\CompletePurchaseRequest; use Omnipay\WorldPay\Message\PurchaseRequest; /** * WorldPay Gateway * * @link http://www.worldpay.com/support/kb/bg/htmlredirect/rhtml.html */ class Gateway extends AbstractGateway { public function getName() { return 'WorldPay'; } public function getDefaultParameters() { return array( 'installationId' => '', 'accountId' => '', 'secretWord' => '', 'callbackPassword' => '', 'testMode' => false, ); } public function getInstallationId() { return $this->getParameter('installationId'); } public function setInstallationId($value) { return $this->setParameter('installationId', $value); } public function getAccountId() { return $this->getParameter('accountId'); } public function setAccountId($value) { return $this->setParameter('accountId', $value); } public function getSecretWord() { return $this->getParameter('secretWord'); } public function setSecretWord($value) { return $this->setParameter('secretWord', $value); } public function getCallbackPassword() { return $this->getParameter('callbackPassword'); } public function setCallbackPassword($value) { return $this->setParameter('callbackPassword', $value); } public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\WorldPay\Message\PurchaseRequest', $parameters); } public function completePurchase(array $parameters = array()) { return $this->createRequest('\Omnipay\WorldPay\Message\CompletePurchaseRequest', $parameters); } } worldpay/.travis.yml 0000604 00000000317 15173176032 0010520 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 worldpay/README.md 0000604 00000003533 15173176032 0007671 0 ustar 00 # Omnipay: WorldPay **WorldPay driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-worldpay) [](https://packagist.org/packages/omnipay/worldpay) [](https://packagist.org/packages/omnipay/worldpay) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements WorldPay 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/worldpay": "~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: * WorldPay 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-worldpay/issues), or better yet, fork the library and submit a pull request. sagepay/.travis.yml 0000604 00000000317 15173176032 0010310 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 sagepay/CONTRIBUTING.md 0000604 00000001040 15173176032 0010422 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. sagepay/phpunit.xml.dist 0000604 00000001512 15173176032 0011350 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> sagepay/README.md 0000604 00000003552 15173176032 0007462 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. sagepay/src/DirectGateway.php 0000604 00000004117 15173176032 0012235 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); } } sagepay/src/Message/ServerAuthorizeRequest.php 0000604 00000001472 15173176032 0015600 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); } } sagepay/src/Message/ServerCompleteAuthorizeRequest.php 0000604 00000005534 15173176032 0017274 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); } } sagepay/src/Message/DirectAuthorizeRequest.php 0000604 00000006675 15173176032 0015556 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; } } sagepay/src/Message/ServerCompleteAuthorizeResponse.php 0000604 00000010421 15173176032 0017431 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; } } sagepay/src/Message/DirectCompleteAuthorizeRequest.php 0000604 00000001247 15173176032 0017235 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'; } } sagepay/src/Message/AbstractRequest.php 0000604 00000016635 15173176032 0014211 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; } } sagepay/src/Message/Response.php 0000604 00000005510 15173176032 0012661 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; } } sagepay/src/Message/ServerAuthorizeResponse.php 0000604 00000001211 15173176032 0015735 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; } } sagepay/src/Message/CaptureRequest.php 0000604 00000001242 15173176032 0014035 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; } } sagepay/src/Message/ServerPurchaseRequest.php 0000604 00000000271 15173176032 0015374 0 ustar 00 <?php namespace Omnipay\SagePay\Message; /** * Sage Pay Server Purchase Request */ class ServerPurchaseRequest extends ServerAuthorizeRequest { protected $action = 'PAYMENT'; } sagepay/src/Message/DirectPurchaseRequest.php 0000604 00000000271 15173176032 0015340 0 ustar 00 <?php namespace Omnipay\SagePay\Message; /** * Sage Pay Direct Purchase Request */ class DirectPurchaseRequest extends DirectAuthorizeRequest { protected $action = 'PAYMENT'; } sagepay/src/Message/RefundRequest.php 0000604 00000001652 15173176032 0013662 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; } } sagepay/src/ServerGateway.php 0000604 00000001776 15173176032 0012301 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); } } sagepay/composer.json 0000604 00000001721 15173176032 0010721 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" } } } sagepay/tests/DirectGatewayTest.php 0000604 00000015551 15173176032 0013454 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()); } } sagepay/tests/ServerGatewayTest.php 0000604 00000014715 15173176032 0013511 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(); } } sagepay/tests/Message/ServerCompleteAuthorizeResponseTest.php 0000604 00000007226 15173176032 0020655 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'); } } sagepay/tests/Message/ResponseTest.php 0000604 00000007034 15173176032 0014077 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()); } } sagepay/tests/Message/ServerAuthorizeRequestTest.php 0000604 00000001633 15173176032 0017012 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']); } } sagepay/tests/Message/DirectAuthorizeRequestTest.php 0000604 00000022531 15173176032 0016756 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'); } } sagepay/tests/Message/ServerAuthorizeResponseTest.php 0000604 00000003675 15173176032 0017170 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()); } } sagepay/tests/Message/RefundRequestTest.php 0000604 00000002370 15173176032 0015073 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); } } sagepay/tests/Mock/CaptureFailure.txt 0000604 00000000601 15173176032 0013702 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. sagepay/tests/Mock/ServerPurchaseFailure.txt 0000604 00000000510 15173176032 0015237 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. sagepay/tests/Mock/DirectPurchaseFailure.txt 0000604 00000000634 15173176032 0015212 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. sagepay/tests/Mock/ServerPurchaseSuccess.txt 0000604 00000001024 15173176032 0015261 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} sagepay/tests/Mock/DirectPurchaseSuccess.txt 0000604 00000000760 15173176032 0015233 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 sagepay/tests/Mock/CaptureSuccess.txt 0000604 00000000524 15173176032 0013727 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. sagepay/tests/Mock/DirectPurchase3dSecure.txt 0000604 00000001144 15173176032 0015275 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 sagepay/LICENSE 0000604 00000002047 15173176032 0007206 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. sagepay/.gitignore 0000604 00000000060 15173176032 0010162 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml pin/runtests.sh 0000604 00000001015 15173176032 0007553 0 ustar 00 #!/bin/sh # # Command line runner for unit tests for composer projects # (c) Del 2015 http://www.babel.com.au/ # No Rights Reserved # # # Clean up after any previous test runs # mkdir -p documents rm -rf documents/coverage-html-new rm -f documents/coverage.xml # # Run phpunit # vendor/bin/phpunit --coverage-html documents/coverage-html-new --coverage-clover documents/coverage.xml if [ -d documents/coverage-html-new ]; then rm -rf documents/coverage-html mv documents/coverage-html-new documents/coverage-html fi pin/.travis.yml 0000604 00000000317 15173176032 0007445 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 pin/makedoc.sh 0000604 00000007562 15173176032 0007304 0 ustar 00 #!/bin/sh # # Smart little documentation generator. # GPL/LGPL # (c) Del 2015 http://www.babel.com.au/ # APPNAME='Omnipay Pin Gateway Module' CMDFILE=apigen.cmd.$$ DESTDIR=./documents # # Find apigen, either in the path or as a local phar file # if [ -f apigen.phar ]; then APIGEN="php apigen.phar" else APIGEN=`which apigen` if [ ! -f "$APIGEN" ]; then # Search for phpdoc if apigen is not found. if [ -f phpDocumentor.phar ]; then PHPDOC="php phpDocumentor.phar" else PHPDOC=`which phpdoc` if [ ! -f "$PHPDOC" ]; then echo "Neither apigen nor phpdoc is installed in the path or locally, please install one of them" echo "see http://www.apigen.org/ or http://www.phpdoc.org/" exit 1 fi fi fi fi # # As of version 4 of apigen need to use the generate subcommand # if [ ! -z "$APIGEN" ]; then APIGEN="$APIGEN generate" fi # # Without any arguments this builds the entire system documentation, # making the cache file first if required. # if [ -z "$1" ]; then # # Check to see that the cache has been made. # if [ ! -f dirlist.cache ]; then echo "Making dirlist.cache file" $0 makecache fi # # Build the apigen/phpdoc command in a file. # if [ ! -z "$APIGEN" ]; then echo "$APIGEN --php --tree --title '$APPNAME API Documentation' --destination $DESTDIR/main \\" > $CMDFILE cat dirlist.cache | while read dir; do echo "--source $dir \\" >> $CMDFILE done echo "" >> $CMDFILE elif [ ! -z "$PHPDOC" ]; then echo "$PHPDOC --sourcecode --title '$APPNAME API Documentation' --target $DESTDIR/main --directory \\" > $CMDFILE cat dirlist.cache | while read dir; do echo "${dir},\\" >> $CMDFILE done echo "" >> $CMDFILE else "Neither apigen nor phpdoc are found, how did I get here?" exit 1 fi # # Run the apigen command # rm -rf $DESTDIR/main mkdir -p $DESTDIR/main . ./$CMDFILE /bin/rm -f ./$CMDFILE # # The "makecache" argument causes the script to just make the cache file # elif [ "$1" = "makecache" ]; then echo "Find application source directories" find src -name \*.php -print | \ ( while read file; do grep -q 'class' $file && dirname $file done ) | sort -u | \ grep -v -E 'config|docs|migrations|phpunit|test|Test|views|web' > dirlist.app echo "Find vendor source directories" find vendor -name \*.php -print | \ ( while read file; do grep -q 'class' $file && dirname $file done ) | sort -u | \ grep -v -E 'config|docs|migrations|phpunit|codesniffer|test|Test|views' > dirlist.vendor # # Filter out any vendor directories for which apigen fails # echo "Filter source directories" mkdir -p $DESTDIR/tmp cat dirlist.app dirlist.vendor | while read dir; do if [ ! -z "$APIGEN" ]; then $APIGEN --quiet --title "Test please ignore" \ --source $dir \ --destination $DESTDIR/tmp && ( echo "Including $dir" echo $dir >> dirlist.cache ) || ( echo "Excluding $dir" ) elif [ ! -z "$PHPDOC" ]; then $PHPDOC --quiet --title "Test please ignore" \ --directory $dir \ --target $DESTDIR/tmp && ( echo "Including $dir" echo $dir >> dirlist.cache ) || ( echo "Excluding $dir" ) fi done echo "Documentation cache dirlist.cache built OK" # # Clean up # /bin/rm -rf $DESTDIR/tmp fi pin/LICENSE 0000604 00000002047 15173176032 0006343 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. pin/README.md 0000604 00000003510 15173176032 0006611 0 ustar 00 # Omnipay: Pin Payments **Pin Payments driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-pin) [](https://packagist.org/packages/omnipay/pin) [](https://packagist.org/packages/omnipay/pin) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements [Pin](https://pin.net.au/) 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/pin": "~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: * Pin 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-pin/issues), or better yet, fork the library and submit a pull request. pin/.gitignore 0000604 00000000167 15173176032 0007327 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml .directory /documents/ .idea/ dirlist.app dirlist.cache dirlist.vendor pin/composer.json 0000604 00000001625 15173176032 0010061 0 ustar 00 { "name": "omnipay/pin", "type": "library", "description": "Pin Payments driver for the Omnipay payment processing library", "keywords": [ "gateway", "merchant", "omnipay", "pay", "payment", "pin" ], "homepage": "https://github.com/thephpleague/omnipay-pin", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-pin/contributors" } ], "autoload": { "psr-4": { "Omnipay\\Pin\\" : "src/" } }, "require": { "omnipay/common": "~2.0" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } pin/tests/Message/RefundRequestTest.php 0000604 00000002304 15173176032 0014225 0 ustar 00 <?php namespace Omnipay\Pin\Message; use Omnipay\Tests\TestCase; class RefundRequestTest extends TestCase { public function setUp() { $this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setTransactionReference('ch_bZ3RhJnIUZ8HhfvH8CCvfA') ->setAmount('400.00'); } public function testSendSuccess() { $this->setMockHttpResponse('RefundSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('rf_ERCQy--Ay6o-NKGiUVcKKA', $response->getTransactionReference()); $this->assertSame('Pending', $response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('RefundFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Refund amount is more than your available Pin Payments balance.', $response->getMessage()); } } pin/tests/Message/CaptureResponseTest.php 0000604 00000002065 15173176032 0014557 0 ustar 00 <?php namespace Omnipay\Pin\Message; use Omnipay\Tests\TestCase; class CaptureResponseTest extends TestCase { public function testCaptureSuccess() { $httpResponse = $this->getMockHttpResponse('CaptureSuccess.txt'); $response = new CaptureResponse($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('ch_lfUYEBK14zotCTykezJkfg', $response->getTransactionReference()); $this->assertTrue($response->getCaptured()); } public function testCaptureFailure() { $httpResponse = $this->getMockHttpResponse('CaptureFailure.txt'); $response = new CaptureResponse($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('The authorisation has expired and can not be captured.', $response->getMessage()); $this->assertNull($response->getCaptured()); } } pin/tests/Message/CreateCardRequestTest.php 0000604 00000002636 15173176032 0015007 0 ustar 00 <?php namespace Omnipay\Pin\Message; use Omnipay\Tests\TestCase; class CreateCardRequestTest extends TestCase { public function setUp() { $this->request = new CreateCardRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'card' => $this->getValidCard(), ) ); } public function testDataWithCard() { $card = $this->getValidCard(); $this->request->setCard($card); $data = $this->request->getData(); $this->assertSame($card['number'], $data['number']); } public function testSendSuccess() { $this->setMockHttpResponse('CardSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('card_8LmnNMTYWG4zQZ4YnYQhBg', $response->getCardReference()); $this->assertTrue($response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('CardFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getCardReference()); $this->assertSame('One or more parameters were missing or invalid', $response->getMessage()); } } pin/tests/Message/CreateCustomerRequestTest.php 0000604 00000003300 15173176032 0015724 0 ustar 00 <?php namespace Omnipay\Pin\Message; use Omnipay\Tests\TestCase; class CreateCustomerRequestTest extends TestCase { public function setUp() { $this->request = new CreateCustomerRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'email' => 'roland@pin.net.au', 'card' => $this->getValidCard(), ) ); } public function testDataWithCardReference() { $this->request->setToken('card_abc'); $data = $this->request->getData(); $this->assertSame('card_abc', $data['card_token']); } public function testDataWithCard() { $card = $this->getValidCard(); $this->request->setCard($card); $data = $this->request->getData(); $this->assertSame($card['number'], $data['card']['number']); } public function testSendSuccess() { $this->setMockHttpResponse('CustomerSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('cus_Mb-8S1ZgEbLUUUJ97dfhfQ', $response->getCustomerReference()); $this->assertTrue($response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('CustomerFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getCustomerReference()); $this->assertSame('One or more parameters were missing or invalid', $response->getMessage()); } } pin/tests/Message/CaptureRequestTest.php 0000604 00000002340 15173176032 0014405 0 ustar 00 <?php namespace Omnipay\Pin\Message; use Omnipay\Tests\TestCase; class CaptureRequestTest extends TestCase { public function setUp() { $this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setTransactionReference('ch_bZ3RhJnIUZ8HhfvH8CCvfA') ->setAmount('400.00'); } public function testSendSuccess() { $this->setMockHttpResponse('CaptureSuccess.txt'); $response = $this->request->send(); $data = $response->getData(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('ch_lfUYEBK14zotCTykezJkfg', $response->getTransactionReference()); $this->assertTrue($data['response']['captured']); } public function testSendError() { $this->setMockHttpResponse('CaptureFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('The authorisation has expired and can not be captured.', $response->getMessage()); } } pin/tests/Message/ResponseTest.php 0000604 00000005602 15173176032 0013233 0 ustar 00 <?php namespace Omnipay\Pin\Message; use Omnipay\Tests\TestCase; class ResponseTest extends TestCase { public function testPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_fXIxWf0gj1yFHJcV1W-d-w', $response->getTransactionReference()); $this->assertSame('Success!', $response->getMessage()); } public function testPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('The current resource was deemed invalid.', $response->getMessage()); } public function testCardSuccess() { $httpResponse = $this->getMockHttpResponse('CardSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('card_8LmnNMTYWG4zQZ4YnYQhBg', $response->getCardReference()); $this->assertTrue($response->getMessage()); } public function testCardFailure() { $httpResponse = $this->getMockHttpResponse('CardFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getCardReference()); $this->assertSame('One or more parameters were missing or invalid', $response->getMessage()); } public function testCustomerSuccess() { $httpResponse = $this->getMockHttpResponse('CustomerSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('cus_Mb-8S1ZgEbLUUUJ97dfhfQ', $response->getCustomerReference()); $this->assertTrue($response->getMessage()); } public function testCustomerFailure() { $httpResponse = $this->getMockHttpResponse('CustomerFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getCustomerReference()); $this->assertSame('One or more parameters were missing or invalid', $response->getMessage()); } } pin/tests/Message/PurchaseRequestTest.php 0000604 00000004036 15173176032 0014560 0 ustar 00 <?php namespace Omnipay\Pin\Message; use Omnipay\Tests\TestCase; class PurchaseRequestTest extends TestCase { public function setUp() { $this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '10.00', 'currency' => 'AUD', 'card' => $this->getValidCard(), 'email' => 'roland@pin.net.au', 'description' => 'test charge' ) ); } public function testDataWithCardToken() { $this->request->setToken('card_abc'); $data = $this->request->getData(); $this->assertSame('card_abc', $data['card_token']); } public function testDataWithCustomerToken() { $this->request->setToken('cus_abc'); $data = $this->request->getData(); $this->assertSame('cus_abc', $data['customer_token']); } public function testDataWithCard() { $card = $this->getValidCard(); $this->request->setCard($card); $data = $this->request->getData(); $this->assertSame($card['number'], $data['card']['number']); } public function testSendSuccess() { $this->setMockHttpResponse('PurchaseSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('ch_fXIxWf0gj1yFHJcV1W-d-w', $response->getTransactionReference()); $this->assertSame('Success!', $response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('PurchaseFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('The current resource was deemed invalid.', $response->getMessage()); } } pin/tests/GatewayTest.php 0000604 00000012255 15173176032 0011454 0 ustar 00 <?php namespace Omnipay\Pin; use Omnipay\Tests\GatewayTestCase; class GatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); $this->options = array( 'amount' => '10.00', 'card' => $this->getValidCard(), 'email' => 'roland@pin.net.au', 'description' => 'test charge' ); } public function testPurchaseSuccess() { $this->setMockHttpResponse('PurchaseSuccess.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('ch_fXIxWf0gj1yFHJcV1W-d-w', $response->getTransactionReference()); $this->assertSame('Success!', $response->getMessage()); } public function testPurchaseError() { $this->setMockHttpResponse('PurchaseFailure.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('The current resource was deemed invalid.', $response->getMessage()); } public function testRefundSuccess() { $this->setMockHttpResponse('RefundSuccess.txt'); $response = $this->gateway->refund(array('amount' => '400.00', 'transactionReference' => 'ch_bZ3RhJnIUZ8HhfvH8CCvfA'))->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('rf_ERCQy--Ay6o-NKGiUVcKKA', $response->getTransactionReference()); $this->assertSame('Pending', $response->getMessage()); } public function testRefundError() { $this->setMockHttpResponse('RefundFailure.txt'); $response = $this->gateway->refund(array('amount' => '500.00', 'transactionReference' => 'ch_bZ3RhJnIUZ8HhfvH8CCvfA'))->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('Refund amount is more than your available Pin Payments balance.', $response->getMessage()); } public function testGetCardReferenceSuccess() { $this->setMockHttpResponse('CardSuccess.txt'); $response = $this->gateway->createCard($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('card_8LmnNMTYWG4zQZ4YnYQhBg', $response->getCardReference()); $this->assertTrue($response->getMessage()); } public function testCreateCardError() { $this->setMockHttpResponse('CardFailure.txt'); $response = $this->gateway->createCard($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getCardReference()); $this->assertSame('One or more parameters were missing or invalid', $response->getMessage()); } public function testCreateCustomerSuccess() { $this->setMockHttpResponse('CustomerSuccess.txt'); $response = $this->gateway->createCustomer($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('cus_Mb-8S1ZgEbLUUUJ97dfhfQ', $response->getCustomerReference()); $this->assertTrue($response->getMessage()); } public function testCreateCustomerError() { $this->setMockHttpResponse('CustomerFailure.txt'); $response = $this->gateway->createCustomer($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getCustomerReference()); $this->assertSame('One or more parameters were missing or invalid', $response->getMessage()); } public function testCaptureSuccess() { $this->setMockHttpResponse('CaptureSuccess.txt'); $response = $this->gateway->capture(array('amount' => '400.00', 'transactionReference' => 'ch_bZ3RhJnIUZ8HhfvH8CCvfA'))->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('ch_lfUYEBK14zotCTykezJkfg', $response->getTransactionReference()); $this->assertTrue($response->getCaptured()); } public function testCaptureError() { $this->setMockHttpResponse('CaptureFailure.txt'); $response = $this->gateway->capture(array('amount' => '400.00', 'transactionReference' => 'ch_lfUYEBK14zotCTykezJkfg'))->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('The authorisation has expired and can not be captured.', $response->getMessage()); } } pin/tests/Mock/CustomerSuccess.txt 0000604 00000001704 15173176032 0013263 0 ustar 00 HTTP/1.1 200 OK Cache-Control: max-age=0, private, must-revalidate Content-Type: application/json; charset=utf-8 Date: Fri, 15 Feb 2013 15:42:42 GMT ETag: "e0b6339dc44a19a2901de1447ec94ebb" Server: Apache/2.2.20 (Ubuntu) Status: 200 Strict-Transport-Security: max-age=31536000 Vary: User-Agent X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11 X-Rack-Cache: invalidate, pass X-Request-Id: 6444d2d9467ed2a7ace471522f2d439b X-Runtime: 0.245244 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 584 Connection: keep-alive {"response":{"token":"cus_Mb-8S1ZgEbLUUUJ97dfhfQ","email":"roland@pin.net.au","created_at":"2014-05-16T11:59:13Z","card":{"token":"card_ooPYTNYmvVr8gswiBwE8kQ","scheme":"master","display_number":"XXXX-XXXX-XXXX-0000","expiry_month":5,"expiry_year":2015,"name":"Roland Robot","address_line1":"42 Sevenoaks St","address_line2":"","address_city":"Lathlain","address_postcode":"6454","address_state":"WA","address_country":"Australia"}}} pin/tests/Mock/CaptureSuccess.txt 0000604 00000002426 15173176032 0013067 0 ustar 00 HTTP/1.1 200 OK Cache-Control: max-age=0, private, must-revalidate Content-Type: application/json; charset=utf-8 Date: Fri, 15 Feb 2013 15:42:42 GMT ETag: "e0b6339dc44a19a2901de1447ec94ebb" Server: Apache/2.2.20 (Ubuntu) Status: 200 Strict-Transport-Security: max-age=31536000 Vary: User-Agent X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11 X-Rack-Cache: invalidate, pass X-Request-Id: 6444d2d9467ed2a7ace471522f2d439b X-Runtime: 0.245244 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 584 Connection: keep-alive {"response":{"token":"ch_lfUYEBK14zotCTykezJkfg","success":true,"amount":400,"currency":"USD","description":"test charge","email":"roland@pin.net.au","ip_address":"203.192.1.172","created_at":"2012-06-20T03:10:49Z","status_message":"Success","error_message":null,"card":{"token":"card_pIQJKMs93GsCc9vLSLevbw","scheme":"master","display_number":"XXXX-XXXX-XXXX-0000","expiry_month":6,"expiry_year":2020,"name":"RolandRobot","address_line1":"42 Sevenoaks St","address_line2":null,"address_city":"Lathlain","address_postcode":"6454","address_state":"WA","address_country":"Australia","primary":null},"captured":true,"authorisation_expired":false,"transfer":[],"amount_refunded":0,"total_fees":42,"merchant_entitlement":358,"refund_pending":false,"settlement_currency":"AUD"}} pin/tests/Mock/RefundSuccess.txt 0000604 00000001363 15173176032 0012706 0 ustar 00 HTTP/1.1 200 OK Cache-Control: max-age=0, private, must-revalidate Content-Type: application/json; charset=utf-8 Date: Fri, 15 Feb 2013 15:42:42 GMT ETag: "e0b6339dc44a19a2901de1447ec94ebb" Server: Apache/2.2.20 (Ubuntu) Status: 200 Strict-Transport-Security: max-age=31536000 Vary: User-Agent X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11 X-Rack-Cache: invalidate, pass X-Request-Id: 6444d2d9467ed2a7ace471522f2d439b X-Runtime: 0.245244 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 584 Connection: keep-alive {"response": {"token": "rf_ERCQy--Ay6o-NKGiUVcKKA","success": null,"amount": 400,"currency": "AUD","charge": "ch_bZ3RhJnIUZ8HhfvH8CCvfA","created_at": "2012-10-27T13:00:00Z","error_message": null,"status_message": "Pending"}} pin/tests/Mock/CardFailure.txt 0000604 00000001340 15173176032 0012306 0 ustar 00 HTTP/1.1 200 OK Cache-Control: max-age=0, private, must-revalidate Content-Type: application/json; charset=utf-8 Date: Fri, 15 Feb 2013 15:42:42 GMT ETag: "e0b6339dc44a19a2901de1447ec94ebb" Server: Apache/2.2.20 (Ubuntu) Status: 200 Strict-Transport-Security: max-age=31536000 Vary: User-Agent X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11 X-Rack-Cache: invalidate, pass X-Request-Id: 6444d2d9467ed2a7ace471522f2d439b X-Runtime: 0.245244 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 584 Connection: keep-alive {"error":"invalid_resource","error_description":"One or more parameters were missing or invalid","messages":[{"param":"expiry_month","code":"expiry_month_invalid","message":"Expiry month can't be blank"}]} pin/tests/Mock/PurchaseFailure.txt 0000604 00000001171 15173176032 0013211 0 ustar 00 HTTP/1.1 422 Unprocessable Entity Cache-Control: no-cache Content-Type: application/json; charset=utf-8 Date: Fri, 15 Feb 2013 15:54:18 GMT Server: Apache/2.2.20 (Ubuntu) Status: 422 Strict-Transport-Security: max-age=31536000 Vary: User-Agent X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11 X-Rack-Cache: invalidate, pass X-Request-Id: 293436e475bfc6face410e6ed241efe9 X-Runtime: 0.161746 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 152 Connection: keep-alive {"error":"invalid_resource","error_description":"The current resource was deemed invalid.","messages":[{"code":"invalid","message":"Processing error"}]} pin/tests/Mock/RefundFailure.txt 0000604 00000001135 15173176032 0012662 0 ustar 00 HTTP/1.1 422 Unprocessable Entity Cache-Control: no-cache Content-Type: application/json; charset=utf-8 Date: Fri, 15 Feb 2013 15:54:18 GMT Server: Apache/2.2.20 (Ubuntu) Status: 422 Strict-Transport-Security: max-age=31536000 Vary: User-Agent X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11 X-Rack-Cache: invalidate, pass X-Request-Id: 293436e475bfc6face410e6ed241efe9 X-Runtime: 0.161746 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 152 Connection: keep-alive {"error": "insufficient_pin_balance","error_description": "Refund amount is more than your available Pin Payments balance."} pin/tests/Mock/PurchaseSuccess.txt 0000604 00000002133 15173176032 0013231 0 ustar 00 HTTP/1.1 200 OK Cache-Control: max-age=0, private, must-revalidate Content-Type: application/json; charset=utf-8 Date: Fri, 15 Feb 2013 15:42:42 GMT ETag: "e0b6339dc44a19a2901de1447ec94ebb" Server: Apache/2.2.20 (Ubuntu) Status: 200 Strict-Transport-Security: max-age=31536000 Vary: User-Agent X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11 X-Rack-Cache: invalidate, pass X-Request-Id: 6444d2d9467ed2a7ace471522f2d439b X-Runtime: 0.245244 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 584 Connection: keep-alive {"response":{"token":"ch_fXIxWf0gj1yFHJcV1W-d-w","success":true,"amount":1000,"currency":"USD","description":"first purchase","email":"fads","ip_address":"","created_at":"2013-02-15T15:42:42Z","status_message":"Success!","error_message":null,"card":{"token":"card_vRGOXvw3NSGR59-TSzVEiw","display_number":"XXXX-XXXX-XXXX-0000","scheme":"visa","address_line1":"jkl","address_line2":"jkl","address_city":"jkl","address_postcode":"jkl","address_state":"jkl","address_country":"jkl"},"transfer":[],"amount_refunded":0,"total_fees":null,"merchant_entitlement":null,"refund_pending":false}} pin/tests/Mock/CardSuccess.txt 0000604 00000001562 15173176032 0012335 0 ustar 00 HTTP/1.1 200 OK Cache-Control: max-age=0, private, must-revalidate Content-Type: application/json; charset=utf-8 Date: Fri, 15 Feb 2013 15:42:42 GMT ETag: "e0b6339dc44a19a2901de1447ec94ebb" Server: Apache/2.2.20 (Ubuntu) Status: 200 Strict-Transport-Security: max-age=31536000 Vary: User-Agent X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11 X-Rack-Cache: invalidate, pass X-Request-Id: 6444d2d9467ed2a7ace471522f2d439b X-Runtime: 0.245244 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 584 Connection: keep-alive {"response":{"token":"card_8LmnNMTYWG4zQZ4YnYQhBg","scheme":"master","display_number":"XXXX-XXXX-XXXX-0000","expiry_month":5,"expiry_year":2015,"name":"Roland Robot","address_line1":"42 Sevenoaks St","address_line2":"","address_city":"Lathlain","address_postcode":"6454","address_state":"WA","address_country":"Australia"},"ip_address":"27.32.236.92"} pin/tests/Mock/CaptureFailure.txt 0000604 00000001275 15173176032 0013047 0 ustar 00 HTTP/1.1 400 AUTHORISATION_EXPIRED Cache-Control: max-age=0, private, must-revalidate Content-Type: application/json; charset=utf-8 Date: Fri, 15 Feb 2013 15:42:42 GMT ETag: "e0b6339dc44a19a2901de1447ec94ebb" Server: Apache/2.2.20 (Ubuntu) Status: 200 Strict-Transport-Security: max-age=31536000 Vary: Use-Agent X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11 X-Rack-Cache: invalidate, pass X-Request-Id: 6444d2d9467ed2a7ace471522f2d439b X-Runtime: 0.245244 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 584 Connection: keep-alive {"error":"authorisation_expired","error_description":"The authorisation has expired and can not be captured.","charge_token":"ch_lfUYEBK14zotCTykezJkfg"} pin/tests/Mock/CustomerFailure.txt 0000604 00000001356 15173176032 0013245 0 ustar 00 HTTP/1.1 422 Unprocessable Entity Cache-Control: no-cache Content-Type: application/json; charset=utf-8 Date: Fri, 15 Feb 2013 15:54:18 GMT Server: Apache/2.2.20 (Ubuntu) Status: 422 Strict-Transport-Security: max-age=31536000 Vary: User-Agent X-Powered-By: Phusion Passenger (mod_rails/mod_rack) 3.0.11 X-Rack-Cache: invalidate, pass X-Request-Id: 293436e475bfc6face410e6ed241efe9 X-Runtime: 0.161746 X-UA-Compatible: IE=Edge,chrome=1 Content-Length: 152 Connection: keep-alive {"error":"invalid_resource","error_description":"One or more parameters were missing or invalid","messages":[{"param":"email","code":"email_invalid","message":"Email can't be blank"},{"param":"email","code":"email_invalid","message":"Email is not formatted properly"}]} pin/src/Message/AuthorizeRequest.php 0000604 00000010062 15173176032 0013541 0 ustar 00 <?php /** * Pin Authorize Request */ namespace Omnipay\Pin\Message; /** * Pin Authorize Request * * The charges API allows you to create new credit card charges, and to retrieve * details of previous charges. * * This message creates a new charge and returns its details. This may be a * long-running request. * * Gateway Parameters * * * email Email address of the customer. Obtained from the card data. * * description Description of the item purchased (e.g. "500g of single origin beans"). * * amount Amount to charge in the currency’s base unit (e.g. cents * for AUD, yen for JPY). There is a minimum charge amount for each * currency; refer to the documentation on supported currencies. * * ip_address IP address of the person submitting the payment. * Obtained from getClientIp. * * Optional currency The three-character ISO 4217 currency code of one * of our supported currencies, e.g. AUD or USD. Default value is "AUD". * * Optional capture Whether or not to immediately capture the charge * ("true" or "false"). If capture is false an authorisation is created. * Later you can capture. Authorised charges automatically expire after * 5 days. Default value is "true". * * and one of the following: * * * card The full details of the credit card to be charged (CreditCard object) * * card_token Token of the card to be charged, as returned from the card * tokens API or customer API. * * customer_token Token of the customer to be charged, as returned * from the customers API. * * ### Example * * <code> * // Create a gateway for the Pin REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PinGateway'); * * // Initialise the gateway * $gateway->initialize(array( * 'secretKey' => 'TEST', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Create a credit card object * // This card can be used for testing. * // See https://pin.net.au/docs/api/test-cards for a list of card * // numbers that can be used for testing. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '4200000000000000', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'email' => 'customer@example.com', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do an authorize transaction on the gateway * $transaction = $gateway->authorize(array( * 'description' => 'Your order for widgets', * 'amount' => '10.00', * 'currency' => 'AUD', * 'clientIp' => $_SERVER['REMOTE_ADDR'], * 'card' => $card, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Authorize transaction was successful!\n"; * $sale_id = $response->getTransactionReference(); * echo "Transaction reference = " . $sale_id . "\n"; * } * </code> * * @see \Omnipay\Pin\Gateway * @link https://pin.net.au/docs/api/charges */ class AuthorizeRequest extends PurchaseRequest { /** * Get the Capture flag. * * Returns the capture parameter, which states whether the charge is * just an authorisation or it is captured instantly. By default all * charges are captured. Please note that the return has to be a string * and not a boolean or Pin's API will disregard it and consider it set * to 'true' * * By default for authorize transactions we return "false". * * @return string */ public function getCapture() { $capture = $this->getParameter('capture'); // By default with Pin a transaction is captured. return $capture === true ? 'true' : 'false'; } } pin/src/Message/AbstractRequest.php 0000604 00000006636 15173176032 0013346 0 ustar 00 <?php /** * Pin Abstract REST Request */ namespace Omnipay\Pin\Message; use Guzzle\Http\Message\RequestInterface; /** * Pin Abstract REST Request * * This is the parent class for all Pin REST requests. * * Test modes: * * The API has two endpoint host names: * * * api.pin.net.au (live) * * test-api.pin.net.au (test) * * The live host is for processing live transactions, whereas the test * host can be used for integration testing and development. * * Each endpoint requires a different set of API keys, which can be * found in your account settings. * * Currently this class makes the assumption that if the testMode * flag is set then the Test Endpoint is being used. * * @see \Omnipay\Pin\Gateway * @link https://pin.net.au/docs/api */ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { const API_VERSION = '1'; /** * Test Endpoint URL * * @var string URL */ protected $testEndpoint = 'https://test-api.pin.net.au/'; /** * Live Endpoint URL * * @var string URL */ protected $liveEndpoint = 'https://api.pin.net.au/'; /** * Get secret key * * Calls to the Pin Payments API must be authenticated using HTTP * basic authentication, with your API key as the username, and * a blank string as the password. * * @return string */ public function getSecretKey() { return $this->getParameter('secretKey'); } /** * Set secret key * * Calls to the Pin Payments API must be authenticated using HTTP * basic authentication, with your API key as the username, and * a blank string as the password. * * @param string $value * @return AbstractRequest implements a fluent interface */ public function setSecretKey($value) { return $this->setParameter('secretKey', $value); } /** * Get the request email. * * @return string */ public function getEmail() { return $this->getParameter('email'); } /** * Sets the request email. * * @param string $value * @return AbstractRequest Provides a fluent interface */ public function setEmail($value) { return $this->setParameter('email', $value); } /** * Get API endpoint URL * * @return string */ protected function getEndpoint() { $base = $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; return $base . self::API_VERSION; } /** * Send a request to the gateway. * * @param string $action * @param array $data * @param string $method * * @return HttpResponse */ public function sendRequest($action, $data = null, $method = RequestInterface::POST) { // don't throw exceptions for 4xx errors $this->httpClient->getEventDispatcher()->addListener( 'request.error', function ($event) { if ($event['response']->isClientError()) { $event->stopPropagation(); } } ); // Return the response we get back from Pin Payments return $this->httpClient->createRequest( $method, $this->getEndpoint() . $action, array('Authorization' => 'Basic ' . base64_encode($this->getSecretKey() . ':')), $data )->send(); } } pin/src/Message/CaptureRequest.php 0000604 00000001376 15173176032 0013202 0 ustar 00 <?php /** * Pin Capture Request */ namespace Omnipay\Pin\Message; use Guzzle\Http\Message\RequestInterface; /** * Pin Capture Request */ class CaptureRequest extends AbstractRequest { public function getData() { $this->validate('transactionReference'); // Amount is the only possible optional parameter $amount = $this->getAmountInteger(); return $amount ? array('amount' => $amount) : array(); } public function sendData($data) { $httpResponse = $this->sendRequest( '/charges/' . $this->getTransactionReference() . '/capture', $data, RequestInterface::PUT ); return $this->response = new CaptureResponse($this, $httpResponse->json()); } } pin/src/Message/RefundRequest.php 0000604 00000002753 15173176032 0013022 0 ustar 00 <?php /** * Pin Refund Request */ namespace Omnipay\Pin\Message; /** * Pin Refund Request * * The refunds API allows you to refund a charge, and retrieve the details * of previous refunds. * * This message creates a new refund, and returns its details. * * Example -- this example assumes that the charge has been successful and the * transaction ID is stored in $sale_id. See PurchaseRequest for the first part * of this transaction. * * <code> * // Do a refund transaction on the gateway * $transaction = $gateway->refund(array( * 'transactionReference' => $sale_id, * 'amount' => '10.00', * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Refund transaction was successful!\n"; * $refund_id = $response->getTransactionReference(); * echo "Transaction reference = " . $refund_id . "\n"; * } * </code> * * @see \Omnipay\Pin\Gateway * @link https://pin.net.au/docs/api/refunds#post-refunds */ class RefundRequest extends AbstractRequest { public function getData() { $this->validate('transactionReference', 'amount'); $data = array(); $data['amount'] = $this->getAmountInteger(); return $data; } public function sendData($data) { $httpResponse = $this->sendRequest('/charges/' . $this->getTransactionReference() . '/refunds', $data); return $this->response = new Response($this, $httpResponse->json()); } } pin/src/Message/Response.php 0000604 00000003526 15173176033 0012024 0 ustar 00 <?php /** * Pin Response */ namespace Omnipay\Pin\Message; use Omnipay\Common\Message\AbstractResponse; /** * Pin Response * * This is the response class for all Pin REST requests. * * @see \Omnipay\Pin\Gateway */ class Response extends AbstractResponse { public function isSuccessful() { return !isset($this->data['error']); } public function getTransactionReference() { if (isset($this->data['response']['token'])) { return $this->data['response']['token']; } } /** * Get Card Reference * * This is used after createCard to get the credit card token to be * used in future transactions. * * @return string */ public function getCardReference() { if (isset($this->data['response']['token'])) { return $this->data['response']['token']; } } /** * @deprecated */ public function getCardToken() { return $this->getCardReference(); } /** * Get Customer Reference * * This is used after createCustomer to get the customer token to be * used in future transactions. * * @return string */ public function getCustomerReference() { if (isset($this->data['response']['token'])) { return $this->data['response']['token']; } } /** * @deprecated */ public function getCustomerToken() { return $this->getCustomerReference(); } public function getMessage() { if ($this->isSuccessful()) { if (isset($this->data['response']['status_message'])) { return $this->data['response']['status_message']; } else { return true; } } else { return $this->data['error_description']; } } } pin/src/Message/PurchaseRequest.php 0000604 00000015221 15173176033 0013344 0 ustar 00 <?php /** * Pin Purchase Request */ namespace Omnipay\Pin\Message; /** * Pin Purchase Request * * The charges API allows you to create new credit card charges, and to retrieve * details of previous charges. * * This message creates a new charge and returns its details. This may be a * long-running request. * * Gateway Parameters * * * email Email address of the customer. Obtained from the card data. * * description Description of the item purchased (e.g. "500g of single origin beans"). * * amount Amount to charge in the currency’s base unit (e.g. cents * for AUD, yen for JPY). There is a minimum charge amount for each * currency; refer to the documentation on supported currencies. * * ip_address IP address of the person submitting the payment. * Obtained from getClientIp. * * Optional currency The three-character ISO 4217 currency code of one * of our supported currencies, e.g. AUD or USD. Default value is "AUD". * * Optional capture Whether or not to immediately capture the charge * ("true" or "false"). If capture is false an authorisation is created. * Later you can capture. Authorised charges automatically expire after * 5 days. Default value is "true". * * and one of the following: * * * card The full details of the credit card to be charged (CreditCard object) * * card_token Token of the card to be charged, as returned from the card * tokens API or customer API. * * customer_token Token of the customer to be charged, as returned * from the customers API. * * Example: * * <code> * // Create a gateway for the Pin REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PinGateway'); * * // Initialise the gateway * $gateway->initialize(array( * 'secretKey' => 'TEST', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Create a credit card object * // This card can be used for testing. * // See https://pin.net.au/docs/api/test-cards for a list of card * // numbers that can be used for testing. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '4200000000000000', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'email' => 'customer@example.com', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do a purchase transaction on the gateway * $transaction = $gateway->purchase(array( * 'description' => 'Your order for widgets', * 'amount' => '10.00', * 'currency' => 'AUD', * 'clientIp' => $_SERVER['REMOTE_ADDR'], * 'card' => $card, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Purchase transaction was successful!\n"; * $sale_id = $response->getTransactionReference(); * echo "Transaction reference = " . $sale_id . "\n"; * } * </code> * * @see \Omnipay\Pin\Gateway * @link https://pin.net.au/docs/api/charges */ class PurchaseRequest extends AbstractRequest { public function getData() { $data = array(); $this->validate('amount', 'description'); $data = array(); $data['amount'] = $this->getAmountInteger(); $data['currency'] = strtolower($this->getCurrency()); $data['description'] = $this->getDescription(); $data['ip_address'] = $this->getClientIp(); $data['capture'] = $this->getCapture(); // Token payments if ($token = $this->getToken()) { if (strpos($token, 'card_') !== false) { $data['card_token'] = $token; } else { $data['customer_token'] = $token; } // Supply an email address if provided, but it is not required if ($this->getEmail()) { $data['email'] = $this->getEmail(); } // Card payments } else { $this->validate('card'); $this->getCard()->validate(); // An email address is required if ($this->getCard()->getEmail()) { $data['email'] = $this->getCard()->getEmail(); } elseif ($this->getEmail()) { $data['email'] = $this->getEmail(); } else { $this->validate('email'); } $data['card']['number'] = $this->getCard()->getNumber(); $data['card']['expiry_month'] = $this->getCard()->getExpiryMonth(); $data['card']['expiry_year'] = $this->getCard()->getExpiryYear(); $data['card']['cvc'] = $this->getCard()->getCvv(); $data['card']['name'] = $this->getCard()->getName(); $data['card']['address_line1'] = $this->getCard()->getAddress1(); $data['card']['address_line2'] = $this->getCard()->getAddress2(); $data['card']['address_city'] = $this->getCard()->getCity(); $data['card']['address_postcode'] = $this->getCard()->getPostcode(); $data['card']['address_state'] = $this->getCard()->getState(); $data['card']['address_country'] = $this->getCard()->getCountry(); } return $data; } public function sendData($data) { $httpResponse = $this->sendRequest('/charges', $data); return $this->response = new Response($this, $httpResponse->json()); } /** * Get the Capture flag. * * Returns the capture parameter, which states whether the charge is * just an authorisation or it is captured instantly. By default all * charges are captured. Please note that the return has to be a string * and not a boolean or Pin's API will disregard it and consider it set * to 'true' * * @return string */ public function getCapture() { $capture = $this->getParameter('capture'); // By default with Pin a transaction is captured. return $capture === false ? 'false' : 'true'; } /** * Set the capture flag. * * This flag states whether the charge is just an authorisation or it is * captured instantly. By default all charges are captured. * * @param $value * * @return PurchaseRequest provides a fluent interface */ public function setCapture($value) { return $this->setParameter('capture', $value); } } pin/src/Message/CreateCardRequest.php 0000604 00000006705 15173176033 0013576 0 ustar 00 <?php /** * Pin Create Card Request */ namespace Omnipay\Pin\Message; /** * Pin Create Card Request * * The card tokens API allows you to securely store credit card details * in exchange for a card token. This card token can then be used to * create a single charge with the charges API, or to create multiple * charges over time using the customers API. * * Returned card information contains a member called primary, which * says whether the card is a customer’s primary card. Its value is * true if the card is a customer’s primary card, false if it is a * non-primary card of the customer, and null if it is not associated * with a customer. * * A card token can only be used once, to create either a charge or * a customer. If no charge or customer is created within 1 month, * the token is automatically expired. * * Example: * * <code> * // Create a gateway for the Pin REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PinGateway'); * * // Initialise the gateway * $gateway->initialize(array( * 'secretKey' => 'TEST', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Create a credit card object * // This card can be used for testing. * // See https://pin.net.au/docs/api/test-cards for a list of card * // numbers that can be used for testing. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '4200000000000000', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'email' => 'customer@example.com', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * $response = $gateway->createCard(array( * 'card' => $card, * ))->send(); * if ($response->isSuccessful()) { * // Find the card ID * $card_id = $response->getCardReference(); * } else { * echo "Gateway createCard failed.\n"; * echo "Error message == " . $response->getMessage() . "\n"; * } * </code> * * @link https://pin.net.au/docs/api/cards */ class CreateCardRequest extends AbstractRequest { public function getData() { $data = array(); $this->getCard()->validate(); $data['number'] = $this->getCard()->getNumber(); $data['expiry_month'] = $this->getCard()->getExpiryMonth(); $data['expiry_year'] = $this->getCard()->getExpiryYear(); $data['cvc'] = $this->getCard()->getCvv(); $data['name'] = $this->getCard()->getName(); $data['address_line1'] = $this->getCard()->getAddress1(); $data['address_line2'] = $this->getCard()->getAddress2(); $data['address_city'] = $this->getCard()->getCity(); $data['address_postcode'] = $this->getCard()->getPostcode(); $data['address_state'] = $this->getCard()->getState(); $data['address_country'] = $this->getCard()->getCountry(); return $data; } public function sendData($data) { $httpResponse = $this->sendRequest('/cards', $data); return $this->response = new Response($this, $httpResponse->json()); } } pin/src/Message/CreateCustomerRequest.php 0000604 00000007137 15173176033 0014526 0 ustar 00 <?php /** * Pin Create Customer Request */ namespace Omnipay\Pin\Message; /** * Pin Create Customer Request * * The customers API allows you to store a customer’s email * and credit card details. A customer can then be used with * the charges API to create multiple charges over time. * * Customers can have multiple cards associated with them, * and one will be considered the customer’s primary card. * The card object in returned customer information represents * this primary card. It contains a member called primary, * which says whether the card is a customer’s primary card; * its value will always be true. * * Example: * * <code> * // Create a gateway for the Pin REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PinGateway'); * * // Initialise the gateway * $gateway->initialize(array( * 'secretKey' => 'TEST', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Create a credit card object * // This card can be used for testing. * // See https://pin.net.au/docs/api/test-cards for a list of card * // numbers that can be used for testing. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '4200000000000000', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'email' => 'customer@example.com', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * $response = $gateway->createCustomer(array( * 'card' => $card, * ))->send(); * if ($response->isSuccessful()) { * // Find the customer ID * $customer_id = $response->getCustomerToken(); * } else { * echo "Gateway createCustomer failed.\n"; * echo "Error message == " . $response->getMessage() . "\n"; * } * </code> * * @link https://pin.net.au/docs/api/customers */ class CreateCustomerRequest extends AbstractRequest { public function getData() { $this->validate('email'); $data = array(); $data['email'] = $this->getEmail(); if ($this->getToken()) { $data['card_token'] = $this->getToken(); } else { $this->getCard()->validate(); $data['card']['number'] = $this->getCard()->getNumber(); $data['card']['expiry_month'] = $this->getCard()->getExpiryMonth(); $data['card']['expiry_year'] = $this->getCard()->getExpiryYear(); $data['card']['cvc'] = $this->getCard()->getCvv(); $data['card']['name'] = $this->getCard()->getName(); $data['card']['address_line1'] = $this->getCard()->getAddress1(); $data['card']['address_line2'] = $this->getCard()->getAddress2(); $data['card']['address_city'] = $this->getCard()->getCity(); $data['card']['address_postcode'] = $this->getCard()->getPostcode(); $data['card']['address_state'] = $this->getCard()->getState(); $data['card']['address_country'] = $this->getCard()->getCountry(); } return $data; } public function sendData($data) { $httpResponse = $this->sendRequest('/customers', $data); return $this->response = new Response($this, $httpResponse->json()); } } pin/src/Message/CaptureResponse.php 0000604 00000001155 15173176033 0013344 0 ustar 00 <?php /** * Pin Capture Response */ namespace Omnipay\Pin\Message; /** * Pin Capture Response * * This is the response class for Pin Capture REST requests. * * @see \Omnipay\Pin\Gateway */ class CaptureResponse extends Response { /** * Get Captured value * * This is used after an attempt to capture the charge is made. * If the capture was successful then it will return true. * * @return string */ public function getCaptured() { if (isset($this->data['response']['captured'])) { return $this->data['response']['captured']; } } } pin/src/Gateway.php 0000604 00000014105 15173176033 0010236 0 ustar 00 <?php /** * Pin Gateway */ namespace Omnipay\Pin; use Omnipay\Common\AbstractGateway; /** * Pin Gateway * * Pin Payments is an Australian all-in-one payment system, allowing you * to accept multi-currency credit card payments without a security * deposit or a merchant account. * * ### Example * * <code> * // Create a gateway for the Pin REST Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('PinGateway'); * * // Initialise the gateway * $gateway->initialize(array( * 'secretKey' => 'TEST', * 'testMode' => true, // Or false when you are ready for live transactions * )); * * // Create a credit card object * // This card can be used for testing. * // See https://pin.net.au/docs/api/test-cards for a list of card * // numbers that can be used for testing. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '4200000000000000', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'email' => 'customer@example.com', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do a purchase transaction on the gateway * $transaction = $gateway->purchase(array( * 'description' => 'Your order for widgets', * 'amount' => '10.00', * 'currency' => 'AUD', * 'clientIp' => $_SERVER['REMOTE_ADDR'], * 'card' => $card, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Purchase transaction was successful!\n"; * $sale_id = $response->getTransactionReference(); * echo "Transaction reference = " . $sale_id . "\n"; * } * </code> * * ### Test modes * * The API has two endpoint host names: * * * api.pin.net.au (live) * * test-api.pin.net.au (test) * * The live host is for processing live transactions, whereas the test * host can be used for integration testing and development. * * Each endpoint requires a different set of API keys, which can be * found in your account settings. * * ### Authentication * * Calls to the Pin Payments API must be authenticated using HTTP * basic authentication, with your API key as the username, and * a blank string as the password. * * #### Keys * * Your account has two types of keys: * * * publishable * * secret * * You can find your keys on the account settings page of the dashboard * after you have created an account at pin.net.au and logged in. * * Your secret key can be used with all of the API, and must be kept * secure and secret at all times. You use your secret key from your * server to create charges and refunds. * * Your publishable key can be used from insecure locations (such as * browsers or mobile apps) to create cards with the cards API. This * is the key you use with Pin.js to create secure payment forms in * the browser. * * @see \Omnipay\Common\AbstractGateway * @link https://pin.net.au/docs/api */ class Gateway extends AbstractGateway { public function getName() { return 'Pin'; } public function getDefaultParameters() { return array( 'secretKey' => '', 'testMode' => false, ); } /** * Get secret key * * Calls to the Pin Payments API must be authenticated using HTTP * basic authentication, with your API key as the username, and * a blank string as the password. * * @return string */ public function getSecretKey() { return $this->getParameter('secretKey'); } /** * Set secret key * * Calls to the Pin Payments API must be authenticated using HTTP * basic authentication, with your API key as the username, and * a blank string as the password. * * @param string $value * @return Gateway implements a fluent interface */ public function setSecretKey($value) { return $this->setParameter('secretKey', $value); } /** * Create a purchase request * * @param array $parameters * @return \Omnipay\Pin\Message\PurchaseRequest */ public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\Pin\Message\PurchaseRequest', $parameters); } /** * Create an authorize request * * @param array $parameters * @return \Omnipay\Pin\Message\AuthorizeRequest */ public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\Pin\Message\AuthorizeRequest', $parameters); } /** * Create a capture request * * @param array $parameters * @return \Omnipay\Pin\Message\CaptureRequest */ public function capture(array $parameters = array()) { return $this->createRequest('\Omnipay\Pin\Message\CaptureRequest', $parameters); } /** * Create a refund request * * @param array $parameters * @return \Omnipay\Pin\Message\RefundRequest */ public function refund(array $parameters = array()) { return $this->createRequest('\Omnipay\Pin\Message\RefundRequest', $parameters); } /** * Create a createCustomer request * * @param array $parameters * @return \Omnipay\Pin\Message\CreateCustomerRequest */ public function createCustomer(array $parameters = array()) { return $this->createRequest('\Omnipay\Pin\Message\CreateCustomerRequest', $parameters); } /** * Create a createCard request * * @param array $parameters * @return \Omnipay\Pin\Message\CreateCardRequest */ public function createCard(array $parameters = array()) { return $this->createRequest('\Omnipay\Pin\Message\CreateCardRequest', $parameters); } } pin/phpunit.xml.dist 0000604 00000001512 15173176033 0010506 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> pin/CONTRIBUTING.md 0000604 00000001040 15173176033 0007560 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. migs/LICENSE 0000604 00000002047 15173176033 0006515 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. migs/README.md 0000604 00000003554 15173176033 0006773 0 ustar 00 # Omnipay: MIGS **MasterCard Internet Gateway Service (MIGS) driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-migs) [](https://packagist.org/packages/omnipay/migs) [](https://packagist.org/packages/omnipay/migs) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements MIGS 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/migs": "~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: * Migs_TwoParty * Migs_ThreeParty 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-migs/issues), or better yet, fork the library and submit a pull request. migs/src/TwoPartyGateway.php 0000604 00000002555 15173176033 0012127 0 ustar 00 <?php namespace Omnipay\Migs; use Omnipay\Common\AbstractGateway; /** * MIGS Gateway * * @link http://www.anz.com/australia/business/merchant/pdf/VPC-Dev-Kit-Integration-Notes.pdf */ class TwoPartyGateway extends AbstractGateway { public function getName() { return 'MIGS 2-Party'; } public function getDefaultParameters() { return array( 'merchantId' => '', 'merchantAccessCode' => '', 'secureHash' => '' ); } public function getMerchantId() { return $this->getParameter('merchantId'); } public function setMerchantId($value) { return $this->setParameter('merchantId', $value); } public function getMerchantAccessCode() { return $this->getParameter('merchantAccessCode'); } public function setMerchantAccessCode($value) { return $this->setParameter('merchantAccessCode', $value); } public function getSecureHash() { return $this->getParameter('secureHash'); } public function setSecureHash($value) { return $this->setParameter('secureHash', $value); } public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\Migs\Message\TwoPartyPurchaseRequest', $parameters); } } migs/src/Message/ThreePartyCompletePurchaseRequest.php 0000604 00000001330 15173176033 0017212 0 ustar 00 <?php namespace Omnipay\Migs\Message; use Omnipay\Common\Exception\InvalidRequestException; /** * Migs Complete Purchase Request */ class ThreePartyCompletePurchaseRequest extends AbstractRequest { public function getData() { $data = $this->httpRequest->query->all(); $hash = isset($data['vpc_SecureHash']) ? $data['vpc_SecureHash'] : null; if ($this->calculateHash($data) !== $hash) { throw new InvalidRequestException('Incorrect hash'); } return $data; } public function sendData($data) { return $this->response = new Response($this, $data); } public function getEndpoint() { return $this->endpoint.'vpcpay'; } } migs/src/Message/Response.php 0000604 00000001516 15173176033 0012172 0 ustar 00 <?php namespace Omnipay\Migs\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RequestInterface; /** * Migs Purchase Response */ class Response extends AbstractResponse { public function __construct(RequestInterface $request, $data) { if (!is_array($data)) { parse_str($data, $data); } parent::__construct($request, $data); } public function isSuccessful() { return isset($this->data['vpc_TxnResponseCode']) && "0" === $this->data['vpc_TxnResponseCode']; } public function getTransactionReference() { return isset($this->data['vpc_ReceiptNo']) ? $this->data['vpc_ReceiptNo'] : null; } public function getMessage() { return isset($this->data['vpc_Message']) ? $this->data['vpc_Message'] : null; } } migs/src/Message/ThreePartyPurchaseResponse.php 0000604 00000001615 15173176033 0015675 0 ustar 00 <?php namespace Omnipay\Migs\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RequestInterface; use Omnipay\Common\Message\RedirectResponseInterface; /** * Migs Purchase Response */ class ThreePartyPurchaseResponse extends AbstractResponse implements RedirectResponseInterface { protected $redirectUrl; public function __construct(RequestInterface $request, $data, $redirectUrl) { parent::__construct($request, $data); $this->redirectUrl = $redirectUrl; } public function isSuccessful() { return false; } public function isRedirect() { return true; } public function getRedirectUrl() { return $this->redirectUrl; } public function getRedirectMethod() { return 'GET'; } public function getRedirectData() { return $this->getData(); } } migs/src/Message/ThreePartyPurchaseRequest.php 0000604 00000001276 15173176033 0015532 0 ustar 00 <?php namespace Omnipay\Migs\Message; /** * Migs Purchase Request */ class ThreePartyPurchaseRequest extends AbstractRequest { protected $action = 'pay'; public function getData() { $this->validate('amount', 'returnUrl', 'transactionId'); $data = $this->getBaseData(); $data['vpc_SecureHash'] = $this->calculateHash($data); return $data; } public function sendData($data) { $redirectUrl = $this->getEndpoint().'?'.http_build_query($data); return $this->response = new ThreePartyPurchaseResponse($this, $data, $redirectUrl); } public function getEndpoint() { return $this->endpoint.'vpcpay'; } } migs/src/Message/AbstractRequest.php 0000604 00000003534 15173176033 0013512 0 ustar 00 <?php namespace Omnipay\Migs\Message; /** * GoCardless Abstract Request */ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { protected $endpoint = 'https://migs.mastercard.com.au/'; public function getMerchantId() { return $this->getParameter('merchantId'); } public function setMerchantId($value) { return $this->setParameter('merchantId', $value); } public function getMerchantAccessCode() { return $this->getParameter('merchantAccessCode'); } public function setMerchantAccessCode($value) { return $this->setParameter('merchantAccessCode', $value); } public function getSecureHash() { return $this->getParameter('secureHash'); } public function setSecureHash($value) { return $this->setParameter('secureHash', $value); } protected function getBaseData() { $data = array(); $data['vpc_Merchant'] = $this->getMerchantId(); $data['vpc_AccessCode'] = $this->getMerchantAccessCode(); $data['vpc_Version'] = '1'; $data['vpc_Locale'] = 'en'; $data['vpc_Command'] = $this->action; $data['vpc_Amount'] = $this->getAmountInteger(); $data['vpc_MerchTxnRef'] = $this->getTransactionId(); $data['vpc_OrderInfo'] = $this->getDescription(); $data['vpc_ReturnURL'] = $this->getReturnUrl(); return $data; } public function getEndpoint() { return $this->endpoint; } public function calculateHash($data) { ksort($data); $hash = $this->getSecureHash(); foreach ($data as $k => $v) { if (substr($k, 0, 4) === 'vpc_' && $k !== 'vpc_SecureHash') { $hash .= $v; } } return strtoupper(md5($hash)); } } migs/src/Message/TwoPartyPurchaseRequest.php 0000604 00000001654 15173176033 0015234 0 ustar 00 <?php namespace Omnipay\Migs\Message; /** * Migs Purchase Request */ class TwoPartyPurchaseRequest extends AbstractRequest { protected $action = 'pay'; public function getData() { $this->validate('amount', 'transactionId', 'card'); $this->getCard()->validate(); $data = $this->getBaseData(); $data['vpc_CardNum'] = $this->getCard()->getNumber(); $data['vpc_CardExp'] = $this->getCard()->getExpiryDate('ym'); $data['vpc_CardSecurityCode'] = $this->getCard()->getCvv(); $data['vpc_SecureHash'] = $this->calculateHash($data); return $data; } public function sendData($data) { $httpResponse = $this->httpClient->post($this->getEndpoint(), null, $data)->send(); return $this->response = new Response($this, $httpResponse->getBody()); } public function getEndpoint() { return $this->endpoint.'vpcdps'; } } migs/src/ThreePartyGateway.php 0000604 00000001176 15173176033 0012423 0 ustar 00 <?php namespace Omnipay\Migs; /** * MIGS Gateway * * @link http://www.anz.com/australia/business/merchant/pdf/VPC-Dev-Kit-Integration-Notes.pdf */ class ThreePartyGateway extends TwoPartyGateway { public function getName() { return 'MIGS 3-Party'; } public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\Migs\Message\ThreePartyPurchaseRequest', $parameters); } public function completePurchase(array $parameters = array()) { return $this->createRequest('\Omnipay\Migs\Message\ThreePartyCompletePurchaseRequest', $parameters); } } migs/.gitignore 0000604 00000000060 15173176033 0007471 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml migs/.travis.yml 0000604 00000000317 15173176033 0007617 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 migs/tests/Message/ThreePartyPurchaseRequestTest.php 0000604 00000003632 15173176033 0016743 0 ustar 00 <?php namespace Omnipay\Migs\Message; use Omnipay\Tests\TestCase; class ThreePartyPurchaseRequestTest extends TestCase { public function setUp() { $this->request = new ThreePartyPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); } public function testSignature() { $this->request->initialize( array( 'amount' => '12.00', 'transactionId' => 123, 'returnUrl' => 'https://www.example.com/return', 'merchantId' => '123', 'merchantAccessCode' => '123', 'secureHash' => '123', ) ); $data = $this->request->getData(); $this->assertSame('FC86354CC09D414EF308A6FA8CE4F9BB', $data['vpc_SecureHash']); } public function testPurchase() { $this->request->initialize( array( 'amount' => '12.00', 'transactionId' => 123, 'returnUrl' => 'https://www.example.com/return', 'merchantId' => '123', 'merchantAccessCode' => '123', 'secureHash' => '123', ) ); $response = $this->request->send(); $this->assertInstanceOf('Omnipay\Migs\Message\ThreePartyPurchaseResponse', $response); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertNull($response->getCode()); $this->assertStringStartsWith('https://migs.mastercard.com.au/vpcpay?', $response->getRedirectUrl()); $this->assertSame('GET', $response->getRedirectMethod()); $this->assertArrayHasKey('vpc_SecureHash', $response->getData()); } } migs/tests/Message/TwoPartyPurchaseRequestTest.php 0000604 00000004020 15173176033 0016435 0 ustar 00 <?php namespace Omnipay\Migs\Message; use Omnipay\Tests\TestCase; class TwoPartyPurchaseRequestTest extends TestCase { public function setUp() { $this->request = new TwoPartyPurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); } public function testCalculateHash() { $data = array( 'vpc_Merchant' => '123', 'vpc_AccessCode' => '123', 'vpc_Version' => '1', 'vpc_Locale' => 'en', 'vpc_Command' => 'pay', 'vpc_Amount' => '1200', 'vpc_MerchTxnRef' => '123', 'vpc_OrderInfo' => '', 'vpc_ReturnURL' => 'https://www.example.com/return', 'vpc_CardNum' => '4111111111111111', 'vpc_CardExp' => '1305', 'vpc_CardSecurityCode' => '123', ); $this->request->setSecureHash('123'); $hash = $this->request->calculateHash($data); $this->assertSame('2624B4BABED7CCA98665238D75560600', $hash); } public function testPurchase() { $this->setMockHttpResponse('TwoPartyPurchaseSuccess.txt'); $this->request->initialize( array( 'amount' => '12.00', 'transactionId' => 123, 'card' => $this->getValidCard(), 'merchantId' => '123', 'merchantAccessCode' => '123', 'secureHash' => '123', 'returnUrl' => 'https://www.example.com/return' ) ); $response = $this->request->send(); $this->assertInstanceOf('Omnipay\Migs\Message\Response', $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertEquals('12345', $response->getTransactionReference()); $this->assertSame('Approved', $response->getMessage()); $this->assertNull($response->getCode()); $this->assertArrayHasKey('vpc_SecureHash', $response->getData()); } } migs/tests/Message/ThreePartyPurchaseResponseTest.php 0000604 00000001460 15173176033 0017106 0 ustar 00 <?php namespace Omnipay\Migs\Message; use Omnipay\Tests\TestCase; class ThreePartyPurchaseResponseTest extends TestCase { public function testConstruct() { $data = array('test' => '123'); $response = new ThreePartyPurchaseResponse($this->getMockRequest(), $data, 'https://example.com/'); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertSame($data, $response->getData()); $this->assertSame('https://example.com/', $response->getRedirectUrl()); $this->assertSame('GET', $response->getRedirectMethod()); $this->assertSame($data, $response->getRedirectData()); } } migs/tests/Message/ThreePartyCompletePurchaseRequestTest.php 0000604 00000003410 15173176033 0020426 0 ustar 00 <?php namespace Omnipay\Migs\Message; use Omnipay\Tests\TestCase; class ThreePartyCompletePurchaseRequestTest extends TestCase { public function setUp() { $this->request = new ThreePartyCompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); } public function testThreePartyCompletePurchaseSuccess() { $data = array(); $data['vpc_Message'] = "Approved"; $data['vpc_ReceiptNo'] = "12345"; $data['vpc_TxnResponseCode'] = "0"; $data['vpc_SecureHash'] = "8720B88CA00352B2A5F4D51C64E86BCB"; $response = new Response($this->getMockRequest(), $data); $this->assertInstanceOf('Omnipay\Migs\Message\Response', $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('12345', $response->getTransactionReference()); $this->assertSame('Approved', $response->getMessage()); $this->assertNull($response->getCode()); } public function testThreePartyCompletePurchaseFailure() { $data = array(); $data['vpc_Message'] = "Error"; $data['vpc_ReceiptNo'] = "12345"; $data['vpc_TxnResponseCode'] = "1"; $data['vpc_SecureHash'] = "8720B88CA00352B2A5F4D51C64E86BCB"; $response = new Response($this->getMockRequest(), $data); $this->assertInstanceOf('Omnipay\Migs\Message\Response', $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('12345', $response->getTransactionReference()); $this->assertNotSame('Approved', $response->getMessage()); $this->assertNull($response->getCode()); } } migs/tests/Message/TwoPartyPurchaseResponseTest.php 0000604 00000002463 15173176033 0016614 0 ustar 00 <?php namespace Omnipay\Migs\Message; use Omnipay\Tests\TestCase; class TwoPartyPurchaseResponseTest extends TestCase { public function testTwoPartyPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('TwoPartyPurchaseSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertInstanceOf('Omnipay\Migs\Message\Response', $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('12345', $response->getTransactionReference()); $this->assertSame('Approved', $response->getMessage()); $this->assertNull($response->getCode()); } public function testTwoPartyPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('TwoPartyPurchaseFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->getBody()); $this->assertInstanceOf('Omnipay\Migs\Message\Response', $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('12345', $response->getTransactionReference()); $this->assertSame('Declined', $response->getMessage()); $this->assertNull($response->getCode()); } } migs/tests/Mock/TwoPartyPurchaseFailure.txt 0000604 00000001324 15173176033 0015075 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 05 Apr 2013 13:11:19 GMT Server: Apache Expires: Sun, 15 Jul 1990 00:00:00 GMT Pragma: no-cache Cache-Control: no-cache Content-Length: 469 P3P: CP="NOI DSP COR CURa ADMa TA1a OUR BUS IND UNI COM NAV INT" Content-Type: text/plain;charset=iso-8859-1 vpc_AVSRequestCode=Z&vpc_AVSResultCode=Unsupported&vpc_AcqAVSRespCode=Unsupported&vpc_AcqCSCRespCode=Unsupported&vpc_AcqResponseCode=14&vpc_Amount=1000&vpc_BatchNo=12345&vpc_CSCResultCode=Unsupported&vpc_Card=VC&vpc_Command=pay&vpc_Locale=en&vpc_MerchTxnRef=123&vpc_Merchant=EXAMPLE&vpc_Message=Declined&vpc_OrderInfo=&vpc_ReceiptNo=12345&vpc_SecureHash=71B4E0DE9EACB5FC27C902379737D458&vpc_TransactionNo=12345&vpc_TxnResponseCode=2&vpc_Version=1 migs/tests/Mock/TwoPartyPurchaseSuccess.txt 0000604 00000001352 15173176033 0015117 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 05 Apr 2013 12:29:13 GMT Server: Apache Expires: Sun, 15 Jul 1990 00:00:00 GMT Pragma: no-cache Cache-Control: no-cache Content-Length: 492 P3P: CP="NOI DSP COR CURa ADMa TA1a OUR BUS IND UNI COM NAV INT" Content-Type: text/plain;charset=iso-8859-1 vpc_AVSRequestCode=Z&vpc_AVSResultCode=Unsupported&vpc_AcqAVSRespCode=Unsupported&vpc_AcqCSCRespCode=Unsupported&vpc_AcqResponseCode=00&vpc_Amount=1000&vpc_AuthorizeId=12345&vpc_BatchNo=12345&vpc_CSCResultCode=Unsupported&vpc_Card=VC&vpc_Command=pay&vpc_Locale=en&vpc_MerchTxnRef=123&vpc_Merchant=EXAMPLE&vpc_Message=Approved&vpc_OrderInfo=&vpc_ReceiptNo=12345&vpc_SecureHash=58808781CF7265DEA89EA8B713FAB075&vpc_TransactionNo=12345&vpc_TxnResponseCode=0&vpc_Version=1 migs/tests/TwoPartyGatewayTest.php 0000604 00000002647 15173176033 0013344 0 ustar 00 <?php namespace Omnipay\Migs; use Omnipay\Tests\GatewayTestCase; class TwoPartyGatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new TwoPartyGateway($this->getHttpClient(), $this->getHttpRequest()); $this->gateway->setSecureHash(md5('example')); $this->options = array( 'amount' => '10.00', 'transactionId' => 12345, 'card' => $this->getValidCard(), ); } public function testPurchaseSuccess() { $this->setMockHttpResponse('TwoPartyPurchaseSuccess.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertInstanceOf('\Omnipay\Migs\Message\Response', $response); $this->assertTrue($response->isSuccessful()); $this->assertEquals('12345', $response->getTransactionReference()); $this->assertSame('Approved', $response->getMessage()); } public function testPurchaseFailure() { $this->setMockHttpResponse('TwoPartyPurchaseFailure.txt'); $response = $this->gateway->purchase($this->options)->send(); $this->assertInstanceOf('\Omnipay\Migs\Message\Response', $response); $this->assertFalse($response->isSuccessful()); $this->assertEquals('12345', $response->getTransactionReference()); $this->assertEquals('Declined', $response->getMessage()); } } migs/tests/ThreePartyGatewayTest.php 0000604 00000002032 15173176033 0013626 0 ustar 00 <?php namespace Omnipay\Migs; use Omnipay\Tests\GatewayTestCase; class ThreePartyGatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new ThreePartyGateway($this->getHttpClient(), $this->getHttpRequest()); $this->options = array( 'amount' => '10.00', 'transactionId' => 12345, 'returnUrl' => 'https://www.example.com/return', ); } public function testPurchase() { $request = $this->gateway->purchase(array('amount' => '10.00')); $this->assertInstanceOf('\Omnipay\Migs\Message\ThreePartyPurchaseRequest', $request); $this->assertSame('10.00', $request->getAmount()); } public function testCompletePurchase() { $request = $this->gateway->completePurchase(array('amount' => '10.00')); $this->assertInstanceOf('\Omnipay\Migs\Message\ThreePartyCompletePurchaseRequest', $request); $this->assertSame('10.00', $request->getAmount()); } } migs/phpunit.xml.dist 0000604 00000001512 15173176033 0010657 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> migs/CONTRIBUTING.md 0000604 00000001040 15173176033 0007731 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. migs/composer.json 0000604 00000001701 15173176033 0010226 0 ustar 00 { "name": "omnipay/migs", "type": "library", "description": "MIGS driver for the Omnipay payment processing library", "keywords": [ "gateway", "mastercard internet gateway service", "merchant", "migs", "omnipay", "pay", "payment" ], "homepage": "https://github.com/thephpleague/omnipay-migs", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-migs/contributors" } ], "autoload": { "psr-4": { "Omnipay\\Migs\\" : "src/" } }, "require": { "omnipay/common": "~2.0" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } coinbase/CONTRIBUTING.md 0000604 00000001040 15173176033 0010555 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. coinbase/phpunit.xml.dist 0000604 00000001512 15173176033 0011503 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> coinbase/LICENSE 0000604 00000002042 15173176033 0007334 0 ustar 00 Copyright (c) 2014 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. coinbase/composer.json 0000604 00000001652 15173176033 0011057 0 ustar 00 { "name": "omnipay/coinbase", "type": "library", "description": "Coinbase driver for the Omnipay payment processing library", "keywords": [ "coinbase", "gateway", "merchant", "omnipay", "pay", "payment" ], "homepage": "https://github.com/thephpleague/omnipay-coinbase", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-coinbase/contributors" } ], "autoload": { "psr-4": { "Omnipay\\Coinbase\\" : "src/" } }, "require": { "omnipay/common": "~2.0" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } coinbase/.gitignore 0000604 00000000060 15173176033 0010315 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml coinbase/README.md 0000604 00000003533 15173176033 0007614 0 ustar 00 # Omnipay: Coinbase **Coinbase driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-coinbase) [](https://packagist.org/packages/omnipay/coinbase) [](https://packagist.org/packages/omnipay/coinbase) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements Coinbase 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/coinbase": "~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: * Coinbase 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-coinbase/issues), or better yet, fork the library and submit a pull request. coinbase/tests/GatewayTest.php 0000604 00000002201 15173176033 0012440 0 ustar 00 <?php namespace Omnipay\Coinbase; use Omnipay\Tests\GatewayTestCase; class GatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); } public function testPurchase() { $request = $this->gateway->purchase(array('amount' => '10.00')); $this->assertInstanceOf('Omnipay\Coinbase\Message\PurchaseRequest', $request); $this->assertSame('10.00', $request->getAmount()); } public function testCompletePurchase() { $request = $this->gateway->completePurchase(array('amount' => '10.00')); $this->assertInstanceOf('Omnipay\Coinbase\Message\CompletePurchaseRequest', $request); $this->assertSame('10.00', $request->getAmount()); } public function testFetchTransaction() { $request = $this->gateway->fetchTransaction(array('transactionReference' => 'abc123')); $this->assertInstanceOf('Omnipay\Coinbase\Message\FetchTransactionRequest', $request); $this->assertSame('abc123', $request->getTransactionReference()); } } coinbase/tests/Mock/PurchaseSuccess.txt 0000604 00000002266 15173176033 0014236 0 ustar 00 HTTP/1.1 200 OK Server: cloudflare-nginx Date: Sun, 11 May 2014 21:17:31 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Set-Cookie: __cfduid=d2616ea01666569cafccf501cbea6d2be1399843050822; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.coinbase.com; HttpOnly, request_method=POST; path=/; secure Cache-Control: no-cache, no-store, max-age=0, must-revalidate Etag: "4b486ed3e49c8c0990deed71af7d2c5d" Expires: -1 Pragma: no-cache Status: 200 OK Strict-Transport-Security: max-age=31536000 Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Rack-Cache: invalidate, pass X-Request-Id: 1bfac74c-04d6-4c52-9f4a-d543cdd3875c X-Runtime: 0.109415 X-Ua-Compatible: IE=Edge,chrome=1 CF-RAY: 1291675ba0b00669-SJC {"success":true,"button":{"code":"30dae91b81299066ba126e3858f89fd8","type":"buy_now","style":"buy_now_large","text":"Pay With Bitcoin","name":"Socks","description":"","custom":"","callback_url":null,"success_url":null,"cancel_url":null,"info_url":null,"auto_redirect":false,"price":{"cents":1000,"currency_iso":"USD"},"variable_price":false,"choose_price":false,"include_address":false,"include_email":false}} coinbase/tests/Mock/FetchTransactionFailure.txt 0000604 00000001510 15173176033 0015671 0 ustar 00 HTTP/1.1 200 OK Server: cloudflare-nginx Date: Mon, 12 May 2014 00:32:53 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Set-Cookie: __cfduid=dbd9a9997b37405d3448b2d39cf9222811399854773232; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.coinbase.com; HttpOnly, request_method=GET; path=/; secure Cache-Control: no-cache, no-store, max-age=0, must-revalidate Etag: "79b74a4dbbb350563282c434324082cf" Expires: -1 Pragma: no-cache Status: 200 OK Strict-Transport-Security: max-age=31536000 Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Rack-Cache: miss X-Request-Id: f6eb9aba-981f-441a-a255-3902f7734efc X-Runtime: 0.062876 X-Ua-Compatible: IE=Edge,chrome=1 CF-RAY: 1292858cb7990669-SJC {"success":false,"error":"Order not found with that id"} coinbase/tests/Mock/PurchaseUnauthorized.txt 0000604 00000001466 15173176033 0015310 0 ustar 00 HTTP/1.1 401 Unauthorized Server: cloudflare-nginx Date: Sun, 11 May 2014 21:16:06 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Set-Cookie: __cfduid=d4655ff60ac6d25f4cf1b61d91a2f4c941399842965827; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.coinbase.com; HttpOnly, request_method=POST; path=/; secure Cache-Control: no-cache, no-store, max-age=0, must-revalidate Expires: -1 Pragma: no-cache Status: 401 Unauthorized Strict-Transport-Security: max-age=31536000 Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Rack-Cache: invalidate, pass X-Request-Id: a67ce0e3-fa12-4238-91fd-aa3e82912c8a X-Runtime: 0.053423 X-Ua-Compatible: IE=Edge,chrome=1 CF-RAY: 1291654599e70669-SJC {"error":"ACCESS_SIGNATURE does not validate"} coinbase/tests/Mock/FetchTransactionSuccess.txt 0000604 00000002457 15173176033 0015725 0 ustar 00 HTTP/1.1 200 OK Server: cloudflare-nginx Date: Mon, 12 May 2014 00:32:14 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Set-Cookie: __cfduid=dd39ff662c7fcde30fd149dceb550afdb1399854734458; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.coinbase.com; HttpOnly, request_method=GET; path=/; secure Cache-Control: no-cache, no-store, max-age=0, must-revalidate Etag: "d551971d78d873d05334f1cb97348400" Expires: -1 Pragma: no-cache Status: 200 OK Strict-Transport-Security: max-age=31536000 Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Rack-Cache: miss X-Request-Id: 538d444f-f9cf-48ea-b3f0-b6f46479cc46 X-Runtime: 0.174142 X-Ua-Compatible: IE=Edge,chrome=1 CF-RAY: 1292849a5e6a0669-SJC {"order":{"id":"9XMWP4YG","created_at":"2014-05-11T15:46:54-07:00","status":"completed","total_btc":{"cents":100000,"currency_iso":"BTC"},"total_native":{"cents":100000,"currency_iso":"BTC"},"total_payout":{"cents":0,"currency_iso":"USD"},"custom":null,"receive_address":"1JUHoDocLWReabF1Qc3jL8bB6Zy6Z2xayV","button":{"type":"buy_now","name":"Socks","description":null,"id":"2016572d538165cb1e2a04f9942c9c54"},"refund_address":"1ArFhi7wsDCfZxk88RykW6BE7Cv7nsXmAk","transaction":{"id":"536ffdf55d905debc8000041","hash":null,"confirmations":0}}} coinbase/tests/Mock/PurchaseFailure.txt 0000604 00000002323 15173176033 0014207 0 ustar 00 HTTP/1.1 200 OK Server: cloudflare-nginx Date: Sun, 11 May 2014 21:16:47 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive Set-Cookie: __cfduid=d7dcdb1d9bcf6956196803df5114745281399843007383; expires=Mon, 23-Dec-2019 23:50:00 GMT; path=/; domain=.coinbase.com; HttpOnly, request_method=POST; path=/; secure Cache-Control: no-cache, no-store, max-age=0, must-revalidate Etag: "11a8b7215eb13fb4b06266ac86b7bbf6" Expires: -1 Pragma: no-cache Status: 200 OK Strict-Transport-Security: max-age=31536000 Vary: Accept-Encoding X-Content-Type-Options: nosniff X-Frame-Options: SAMEORIGIN X-Rack-Cache: invalidate, pass X-Request-Id: 0bfa5456-4866-417f-90cd-1d4583863a9f X-Runtime: 0.172405 X-Ua-Compatible: IE=Edge,chrome=1 CF-RAY: 1291664bc8790669-SJC {"success":false,"errors":["Name can't be blank"],"button":{"code":"c777f2ca6e01b8c116b267a053603e62","type":"buy_now","style":"buy_now_large","text":"Pay With Bitcoin","name":"","description":"","custom":"","callback_url":null,"success_url":null,"cancel_url":null,"info_url":null,"auto_redirect":false,"price":{"cents":1000,"currency_iso":"USD"},"variable_price":false,"choose_price":false,"include_address":false,"include_email":false}} coinbase/tests/Message/PurchaseResponseTest.php 0000604 00000003404 15173176033 0015722 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; use Omnipay\Tests\TestCase; class PurchaseResponseTest extends TestCase { public function testSuccess() { $httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt'); $response = new PurchaseResponse($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getMessage()); $this->assertSame('GET', $response->getRedirectMethod()); $this->assertSame('https://coinbase.com/checkouts/30dae91b81299066ba126e3858f89fd8', $response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); $this->assertSame('30dae91b81299066ba126e3858f89fd8', $response->getTransactionReference()); } public function testFailure() { $httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt'); $response = new PurchaseResponse($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame("Name can't be blank", $response->getMessage()); $this->assertNull($response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); $this->assertSame('c777f2ca6e01b8c116b267a053603e62', $response->getTransactionReference()); } public function testEmpty() { $response = new PurchaseResponse($this->getMockRequest(), array()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); } } coinbase/tests/Message/CompletePurchaseRequestTest.php 0000604 00000005257 15173176033 0017255 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; use Omnipay\Tests\TestCase; use Symfony\Component\HttpFoundation\Request as HttpRequest; class CompletePurchaseRequestTest extends TestCase { public function setUp() { $this->httpRequest = $this->getHttpRequest(); $this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->httpRequest); $this->request->initialize( array( 'apiKey' => 'abc123', 'secret' => 'shhh', ) ); } public function testGetDataGet() { $this->httpRequest->query->replace( array('order' => array('id' => '9XMWP4YG')) ); $data = $this->request->getData(); $this->assertSame('9XMWP4YG', $data['id']); } public function testGetDataPost() { // post data is sent as JSON $content = '{"order":{"id":"9XMWP4YG","created_at":"2014-05-11T22:15:41-07:00","status":"completed"}}'; $this->httpRequest = new HttpRequest(array(), array(), array(), array(), array(), array(), $content); $this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->httpRequest); $this->request->initialize( array( 'apiKey' => 'abc123', 'secret' => 'shhh', ) ); $data = $this->request->getData(); $this->assertSame('9XMWP4YG', $data['id']); } /** * @expectedException \Omnipay\Common\Exception\InvalidRequestException * @expectedExceptionMessage Missing Order ID */ public function testGetDataInvalid() { $this->request->getData(); } public function testSendSuccess() { $this->httpRequest->query->replace( array('order' => array('id' => '9XMWP4YG')) ); $this->setMockHttpResponse('FetchTransactionSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('completed', $response->getMessage()); $this->assertSame('9XMWP4YG', $response->getTransactionReference()); } public function testSendFailure() { $this->httpRequest->query->replace( array('order' => array('id' => '9XMWP4YG')) ); $this->setMockHttpResponse('FetchTransactionFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('Order not found with that id', $response->getMessage()); $this->assertNull($response->getTransactionReference()); } } coinbase/tests/Message/AbstractRequestTest.php 0000604 00000001613 15173176033 0015545 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; use Mockery as m; use Omnipay\Tests\TestCase; class AbstractRequestTest extends TestCase { public function setUp() { $this->request = m::mock('\Omnipay\Coinbase\Message\AbstractRequest')->makePartial(); $this->request->initialize(); } public function testGenerateNonce() { // nonce should increment every time $n1 = $this->request->generateNonce(); $n2 = $this->request->generateNonce(); $this->assertGreaterThan($n1, $n2); } public function testGenerateSignature() { $url = 'exampleurl'; $body = 'examplebody'; $nonce = '12345'; $this->request->setSecret('shhh'); $expected = hash_hmac('sha256', '12345exampleurlexamplebody', 'shhh'); $this->assertSame($expected, $this->request->generateSignature($url, $body, $nonce)); } } coinbase/tests/Message/ResponseTest.php 0000604 00000002547 15173176033 0014236 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; use Omnipay\Tests\TestCase; class ResponseTest extends TestCase { public function testSuccess() { $httpResponse = $this->getMockHttpResponse('FetchTransactionSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('completed', $response->getMessage()); $this->assertSame('9XMWP4YG', $response->getTransactionReference()); } public function testFailure() { $httpResponse = $this->getMockHttpResponse('FetchTransactionFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('Order not found with that id', $response->getMessage()); $this->assertNull($response->getTransactionReference()); } public function testEmpty() { $response = new Response($this->getMockRequest(), array()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); } } coinbase/tests/Message/FetchTransactionRequestTest.php 0000604 00000003240 15173176033 0017237 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; use Omnipay\Tests\TestCase; class FetchTransactionRequestTest extends TestCase { public function setUp() { $this->httpRequest = $this->getHttpRequest(); $this->request = new FetchTransactionRequest($this->getHttpClient(), $this->httpRequest); $this->request->initialize( array( 'transactionReference' => '9XMWP4YG', 'apiKey' => 'abc123', 'secret' => 'shhh', ) ); } public function testGetDataGet() { $this->request->initialize(array('transactionReference' => 'abc123')); $data = $this->request->getData(); $this->assertSame('abc123', $data['id']); } public function testSendSuccess() { $this->setMockHttpResponse('FetchTransactionSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('completed', $response->getMessage()); $this->assertSame('9XMWP4YG', $response->getTransactionReference()); } public function testSendFailure() { $this->httpRequest->request->replace( array('order' => array('id' => '9XMWP4YG')) ); $this->setMockHttpResponse('FetchTransactionFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('Order not found with that id', $response->getMessage()); $this->assertNull($response->getTransactionReference()); } } coinbase/tests/Message/PurchaseRequestTest.php 0000604 00000006760 15173176033 0015564 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; use Omnipay\Tests\TestCase; class PurchaseRequestTest extends TestCase { public function setUp() { $this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '10.00', 'currency' => 'USD', 'description' => 'Socks', 'apiKey' => 'abc123', 'secret' => 'shhh', ) ); } public function testGetData() { $this->request->initialize( array( 'accountId' => 'abc123', 'amount' => '0.001', 'currency' => 'BTC', 'description' => 'Socks', 'returnUrl' => 'https://example.com/return', 'cancelUrl' => 'https://example.com/cancel', 'notifyUrl' => 'https://example.com/notify', ) ); $data = $this->request->getData(); $this->assertSame('abc123', $data['account_id']); $this->assertSame('0.00100000', $data['button']['price_string']); $this->assertSame('BTC', $data['button']['price_currency_iso']); $this->assertSame('Socks', $data['button']['name']); $this->assertSame('https://example.com/return', $data['button']['success_url']); $this->assertSame('https://example.com/cancel', $data['button']['cancel_url']); $this->assertSame('https://example.com/notify', $data['button']['callback_url']); } public function testGetDataAccountIdNull() { // empty string must be converted to null $this->request->setAccountId(''); $data = $this->request->getData(); $this->assertNull($data['account_id']); } public function testSendSuccess() { $this->setMockHttpResponse('PurchaseSuccess.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getMessage()); $this->assertSame('GET', $response->getRedirectMethod()); $this->assertSame('https://coinbase.com/checkouts/30dae91b81299066ba126e3858f89fd8', $response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); $this->assertSame('30dae91b81299066ba126e3858f89fd8', $response->getTransactionReference()); } public function testSendFailure() { $this->setMockHttpResponse('PurchaseFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame("Name can't be blank", $response->getMessage()); $this->assertNull($response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); $this->assertSame('c777f2ca6e01b8c116b267a053603e62', $response->getTransactionReference()); } public function testSendUnauthorized() { $this->setMockHttpResponse('PurchaseUnauthorized.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ACCESS_SIGNATURE does not validate', $response->getMessage()); $this->assertNull($response->getRedirectUrl()); $this->assertNull($response->getRedirectData()); $this->assertNull($response->getTransactionReference()); } } coinbase/src/Gateway.php 0000604 00000003753 15173176033 0011242 0 ustar 00 <?php namespace Omnipay\Coinbase; use Omnipay\Common\AbstractGateway; /** * Coinbase Gateway * * @link https://coinbase.com/docs/api/overview */ class Gateway extends AbstractGateway { public function getName() { return 'Coinbase'; } public function getDefaultParameters() { return array( 'apiKey' => '', 'secret' => '', 'accountId' => '', ); } public function getApiKey() { return $this->getParameter('apiKey'); } public function setApiKey($value) { return $this->setParameter('apiKey', $value); } public function getSecret() { return $this->getParameter('secret'); } public function setSecret($value) { return $this->setParameter('secret', $value); } public function getAccountId() { return $this->getParameter('accountId'); } public function setAccountId($value) { return $this->setParameter('accountId', $value); } /** * @param array $parameters * @return \Omnipay\Coinbase\Message\PurchaseRequest */ public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\Coinbase\Message\PurchaseRequest', $parameters); } /** * @param array $parameters * @return \Omnipay\Coinbase\Message\CompletePurchaseRequest */ public function completePurchase(array $parameters = array()) { return $this->createRequest('\Omnipay\Coinbase\Message\CompletePurchaseRequest', $parameters); } /** * @param array $parameters * @return \Omnipay\Coinbase\Message\FetchTransactionRequest */ public function fetchTransaction(array $parameters = array()) { return $this->createRequest('\Omnipay\Coinbase\Message\FetchTransactionRequest', $parameters); } } coinbase/src/Message/FetchTransactionRequest.php 0000604 00000001062 15173176033 0016024 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; /** * Coinbase Fetch Transaction Request * * @method \Omnipay\Coinbase\Message\Response send() */ class FetchTransactionRequest extends AbstractRequest { public function getData() { $this->validate('transactionReference'); return array('id' => $this->getTransactionReference()); } public function sendData($data) { $httpResponse = $this->sendRequest('GET', '/orders/'.$data['id']); return $this->response = new Response($this, $httpResponse->json()); } } coinbase/src/Message/PurchaseResponse.php 0000604 00000001710 15173176033 0014505 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; use Omnipay\Common\Message\RedirectResponseInterface; /** * Coinbase Purchase Response */ class PurchaseResponse extends Response implements RedirectResponseInterface { protected $redirectEndpoint = 'https://coinbase.com/checkouts'; public function isSuccessful() { return false; } public function isRedirect() { return isset($this->data['success']) && $this->data['success']; } public function getRedirectMethod() { return 'GET'; } public function getRedirectUrl() { if ($this->isRedirect()) { return $this->redirectEndpoint.'/'.$this->getTransactionReference(); } } public function getRedirectData() { return null; } public function getTransactionReference() { if (isset($this->data['button']['code'])) { return $this->data['button']['code']; } } } coinbase/src/Message/PurchaseRequest.php 0000604 00000002011 15173176033 0014332 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; /** * Coinbase Purchase Request * * @method \Omnipay\Coinbase\Message\PurchaseResponse send() */ class PurchaseRequest extends AbstractRequest { public function getData() { $this->validate('amount', 'currency', 'description'); $data = array(); $data['account_id'] = $this->getAccountId() ?: null; $data['button'] = array(); $data['button']['name'] = $this->getDescription(); $data['button']['price_string'] = $this->getAmount(); $data['button']['price_currency_iso'] = $this->getCurrency(); $data['button']['success_url'] = $this->getReturnUrl(); $data['button']['cancel_url'] = $this->getCancelUrl(); $data['button']['callback_url'] = $this->getNotifyUrl(); return $data; } public function sendData($data) { $httpResponse = $this->sendRequest('POST', '/buttons', $data); return $this->response = new PurchaseResponse($this, $httpResponse->json()); } } coinbase/src/Message/CompletePurchaseRequest.php 0000604 00000001472 15173176033 0016035 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; use Omnipay\Common\Exception\InvalidRequestException; /** * Coinbase Complete Purchase Request * * @method \Omnipay\Coinbase\Message\Response send() */ class CompletePurchaseRequest extends FetchTransactionRequest { public function getData() { // check GET $order = $this->httpRequest->query->get('order'); // check JSON POST data if (!$order && $this->httpRequest->getContent()) { $content = json_decode($this->httpRequest->getContent(), true); if (isset($content['order'])) { $order = $content['order']; } } if (empty($order['id'])) { throw new InvalidRequestException('Missing Order ID'); } return array('id' => $order['id']); } } coinbase/src/Message/AbstractRequest.php 0000604 00000004134 15173176033 0014333 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; /** * Coinbase Abstract Request * * @method \Omnipay\Coinbase\Message\Response send() */ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { protected $endpoint = 'https://api.coinbase.com/v1'; public function getApiKey() { return $this->getParameter('apiKey'); } public function setApiKey($value) { return $this->setParameter('apiKey', $value); } public function getSecret() { return $this->getParameter('secret'); } public function setSecret($value) { return $this->setParameter('secret', $value); } public function getAccountId() { return $this->getParameter('accountId'); } public function setAccountId($value) { return $this->setParameter('accountId', $value); } public function sendRequest($method, $action, $data = null) { // don't throw exceptions for 4xx errors $this->httpClient->getEventDispatcher()->addListener( 'request.error', function ($event) { if ($event['response']->isClientError()) { $event->stopPropagation(); } } ); $nonce = $this->generateNonce(); $url = $this->endpoint.$action; $body = $data ? http_build_query($data) : null; $httpRequest = $this->httpClient->createRequest($method, $url, null, $body); $httpRequest->setHeader('Content-Type', 'application/x-www-form-urlencoded'); $httpRequest->setHeader('ACCESS_KEY', $this->getApiKey()); $httpRequest->setHeader('ACCESS_SIGNATURE', $this->generateSignature($url, $body, $nonce)); $httpRequest->setHeader('ACCESS_NONCE', $nonce); return $httpRequest->send(); } public function generateNonce() { return sprintf('%0.0f', round(microtime(true) * 1000000)); } public function generateSignature($url, $body, $nonce) { $message = $nonce.$url.$body; return hash_hmac('sha256', $message, $this->getSecret()); } } coinbase/src/Message/Response.php 0000604 00000001520 15173176033 0013011 0 ustar 00 <?php namespace Omnipay\Coinbase\Message; use Omnipay\Common\Message\AbstractResponse; /** * Coinbase Response */ class Response extends AbstractResponse { public function isSuccessful() { return isset($this->data['order']['status']) && 'completed' === $this->data['order']['status']; } public function getMessage() { if (isset($this->data['error'])) { return $this->data['error']; } elseif (isset($this->data['errors'])) { return implode(', ', $this->data['errors']); } elseif (isset($this->data['order']['status'])) { return $this->data['order']['status']; } } public function getTransactionReference() { if (isset($this->data['order']['id'])) { return $this->data['order']['id']; } } } coinbase/.travis.yml 0000604 00000000317 15173176033 0010443 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 manual/.travis.yml 0000604 00000000317 15173176033 0010135 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 manual/CONTRIBUTING.md 0000604 00000001040 15173176033 0010247 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. manual/tests/GatewayTest.php 0000604 00000002244 15173176033 0012141 0 ustar 00 <?php namespace Omnipay\Manual; use Omnipay\Tests\GatewayTestCase; class GatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); $this->options = array( 'amount' => 1000 ); } public function testAuthorize() { $response = $this->gateway->authorize($this->options)->send(); $this->assertInstanceOf('\Omnipay\Manual\Message\Response', $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testCapture() { $response = $this->gateway->capture($this->options)->send(); $this->assertInstanceOf('\Omnipay\Manual\Message\Response', $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); } } manual/src/Gateway.php 0000604 00000001311 15173176033 0010720 0 ustar 00 <?php namespace Omnipay\Manual; use Omnipay\Common\AbstractGateway; /** * Manual Gateway * * This gateway is useful for processing check or direct debit payments. It simply * authorizes every payment. */ class Gateway extends AbstractGateway { public function getName() { return 'Manual'; } public function getDefaultParameters() { return array(); } public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\Manual\Message\Request', $parameters); } public function capture(array $parameters = array()) { return $this->createRequest('\Omnipay\Manual\Message\Request', $parameters); } } manual/src/Message/Response.php 0000604 00000000343 15173176033 0012505 0 ustar 00 <?php namespace Omnipay\Manual\Message; use Omnipay\Common\Message\AbstractResponse; /** * Manual Response */ class Response extends AbstractResponse { public function isSuccessful() { return true; } } manual/src/Message/Request.php 0000604 00000000576 15173176033 0012347 0 ustar 00 <?php namespace Omnipay\Manual\Message; use Omnipay\Common\Message\AbstractRequest; /** * Manual Request */ class Request extends AbstractRequest { public function getData() { $this->validate('amount'); return $this->getParameters(); } public function sendData($data) { return $this->response = new Response($this, $data); } } manual/LICENSE 0000604 00000002047 15173176033 0007033 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. manual/phpunit.xml.dist 0000604 00000001512 15173176033 0011175 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> manual/composer.json 0000604 00000001636 15173176033 0010553 0 ustar 00 { "name": "omnipay/manual", "type": "library", "description": "Manual driver for the Omnipay payment processing library", "keywords": [ "gateway", "manual", "merchant", "omnipay", "pay", "payment" ], "homepage": "https://github.com/thephpleague/omnipay-manual", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-manual/contributors" } ], "autoload": { "psr-4": { "Omnipay\\Manual\\" : "src/" } }, "require": { "omnipay/common": "~2.0" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } manual/README.md 0000604 00000003503 15173176033 0007303 0 ustar 00 # Omnipay: Manual **Manual driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-manual) [](https://packagist.org/packages/omnipay/manual) [](https://packagist.org/packages/omnipay/manual) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements Manual 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/manual": "~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: * Manual 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-manual/issues), or better yet, fork the library and submit a pull request. manual/.gitignore 0000604 00000000060 15173176033 0010007 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml stripe/.travis.yml 0000604 00000000317 15173176033 0010166 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 stripe/composer.json 0000604 00000001636 15173176033 0010604 0 ustar 00 { "name": "omnipay/stripe", "type": "library", "description": "Stripe driver for the Omnipay payment processing library", "keywords": [ "gateway", "merchant", "omnipay", "pay", "payment", "stripe" ], "homepage": "https://github.com/thephpleague/omnipay-stripe", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-stripe/contributors" } ], "autoload": { "psr-4": { "Omnipay\\Stripe\\" : "src/" } }, "require": { "omnipay/common": "~2.0" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } stripe/runtests.sh 0000604 00000001015 15173176033 0010274 0 ustar 00 #!/bin/sh # # Command line runner for unit tests for composer projects # (c) Del 2015 http://www.babel.com.au/ # No Rights Reserved # # # Clean up after any previous test runs # mkdir -p documents rm -rf documents/coverage-html-new rm -f documents/coverage.xml # # Run phpunit # vendor/bin/phpunit --coverage-html documents/coverage-html-new --coverage-clover documents/coverage.xml if [ -d documents/coverage-html-new ]; then rm -rf documents/coverage-html mv documents/coverage-html-new documents/coverage-html fi stripe/README.md 0000604 00000007336 15173176033 0007344 0 ustar 00 # Omnipay: Stripe **Stripe driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-stripe) [](https://packagist.org/packages/omnipay/stripe) [](https://packagist.org/packages/omnipay/stripe) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements Stripe 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/stripe": "~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: * [Stripe](https://stripe.com/) For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) repository. ### Stripe.js The Stripe integration is fairly straight forward. Essentially you just pass a `token` field through to Stripe instead of the regular credit card data. Start by following the standard Stripe JS guide here: [https://stripe.com/docs/tutorials/forms](https://stripe.com/docs/tutorials/forms) After that you will have a `stripeToken` field which will be submitted to your server. Simply pass this through to the gateway as `token`, instead of the usual `card` array: ```php $token = $_POST['stripeToken']; $response = $gateway->purchase(['amount' => '10.00', 'currency' => 'USD', 'token' => $token])->send(); ``` ### Stripe Connect Stripe connect applications can charge an additional fee on top of Stripe's fees for charges they make on behalf of their users. To do this you need to specify an additional `transactionFee` parameter as part of an authorize or purchase request. When a charge is refunded the transaction fee is refunded with an amount proportional to the amount of the charge refunded and by default this will come from your connected user's Stripe account effectively leaving them out of pocket. To refund from your (the applications) Stripe account instead you can pass a ``refundApplicationFee`` parameter with a boolean value of true as part of a refund request. Note: making requests with Stripe Connect specific parameters can only be made using the OAuth access token you received as part of the authorization process. Read more on Stripe Connect [here](https://stripe.com/docs/connect). ## Test Mode Stripe accounts have test-mode API keys as well as live-mode API keys. These keys can be active at the same time. Data created with test-mode credentials will never hit the credit card networks and will never cost anyone money. Unlike some gateways, there is no test mode endpoint separate to the live mode endpoint, the Stripe API endpoint is the same for test and for live. ## 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 announcements, 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-stripe/issues), or better yet, fork the library and submit a pull request. stripe/tests/Mock/CreateCardFailure.txt 0000604 00000000631 15173176033 0014155 0 ustar 00 HTTP/1.1 402 Payment Required Server: nginx Date: Tue, 26 Feb 2013 16:17:02 GMT Content-Type: application/json;charset=utf-8 Content-Length: 139 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "error": { "message": "You must provide an integer value for 'exp_year'.", "type": "card_error", "param": "exp_year" } } stripe/tests/Mock/FetchBalanceTransactionSuccess.txt 0000604 00000002146 15173176033 0016711 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Wed, 24 Jul 2013 07:14:02 GMT Content-Type: application/json;charset=utf-8 Content-Length: 1092 Connection: keep-alive Access-Control-Allow-Credentials: true Access-Control-Max-Age: 300 Cache-Control: no-cache, no-store { "id": "txn_1044bu4CmsDZ3Zk6BGg97VUU", "object": "balance_transaction", "amount": 4013, "available_on": 1401235200, "created": 1400651717, "currency": "eur", "description": "Test #4", "fee": 226, "fee_details": [ { "amount": 80, "application": null, "currency": "chf", "description": "Stripe currency conversion fee", "type": "stripe_fee" }, { "amount": 146, "application": null, "currency": "chf", "description": "Stripe processing fees", "type": "stripe_fee" } ], "net": 3787, "source": "ch_1044bu4CmsDZ3Zk6HkSkVsxd", "sourced_transfers": { "object": "list", "data": [ ], "has_more": false, "total_count": 0, "url": "/v1/transfers?source_transaction=ch_1044bu4CmsDZ3Zk6HkSkVsxd" }, "status": "available", "type": "charge" } stripe/tests/Mock/RefundSuccess.txt 0000604 00000000077 15173176033 0013430 0 ustar 00 HTTP/1.1 200 OK {"id":"ch_12RgN9L7XhO9mI","object": "charge"} stripe/tests/Mock/UpdateCustomerFailure.txt 0000604 00000000612 15173176033 0015123 0 ustar 00 HTTP/1.1 404 Not Found Server: nginx Date: Tue, 26 Feb 2013 16:32:51 GMT Content-Type: application/json;charset=utf-8 Content-Length: 131 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "error": { "type": "invalid_request_error", "message": "No such customer: cus_1MZeNih5LdKxDq", "param": "id" } } stripe/tests/Mock/FetchTokenFailure.txt 0000604 00000000611 15173176033 0014210 0 ustar 00 HTTP/1.1 404 Not Found Server: nginx Date: Wed, 24 Jul 2013 13:40:31 GMT Content-Type: application/json;charset=utf-8 Content-Length: 132 Connection: keep-alive Access-Control-Allow-Credentials: true Access-Control-Max-Age: 300 Cache-Control: no-cache, no-store { "error": { "type": "invalid_request_error", "message": "No such token: tok_15Kuns2eZvKYlo2CDt9wRdzS", "param": "id" } } stripe/tests/Mock/DeleteCardFailure.txt 0000604 00000000612 15173176033 0014153 0 ustar 00 HTTP/1.1 404 Not Found Server: nginx Date: Tue, 26 Feb 2013 16:32:51 GMT Content-Type: application/json;charset=utf-8 Content-Length: 131 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "error": { "type": "invalid_request_error", "message": "No such customer: cus_1MZeNih5LdKxDq", "param": "id" } } stripe/tests/Mock/DeleteCustomerSuccess.txt 0000604 00000000463 15173176033 0015130 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Tue, 26 Feb 2013 16:33:08 GMT Content-Type: application/json;charset=utf-8 Content-Length: 52 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "deleted": true, "id": "cus_1MZSEtqSghKx99" } stripe/tests/Mock/PurchaseSuccess.txt 0000604 00000002537 15173176033 0013762 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Fri, 15 Feb 2013 18:25:28 GMT Content-Type: application/json;charset=utf-8 Content-Length: 995 Connection: keep-alive Cache-Control: no-cache, no-store Access-Control-Allow-Credentials: true Access-Control-Max-Age: 300 { "id": "ch_1IU9gcUiNASROd", "object": "charge", "created": 1360952728, "livemode": false, "paid": true, "amount": 1000, "currency": "usd", "refunded": false, "fee": 59, "fee_details": [ { "amount": 59, "currency": "usd", "type": "stripe_fee", "description": "Stripe processing fees", "application": null, "amount_refunded": 0 } ], "source": { "id": "card_16n3EU2baUhq7QENSrstkoN0", "object": "card", "address_city": "", "address_country": "", "address_line1": "", "address_line1_check": null, "address_line2": "", "address_state": "", "address_zip": "", "address_zip_check": null, "brand": "Visa", "country": "US", "customer": null, "cvc_check": "pass", "dynamic_last4": null, "exp_month": 6, "exp_year": 2016, "funding": "credit", "last4": "4242", "metadata": { }, "name": "", "tokenization_method": null }, "failure_message": null, "amount_refunded": 0, "customer": null, "invoice": null, "description": "first purchase", "dispute": null } stripe/tests/Mock/CaptureFailure.txt 0000604 00000000610 15173176033 0013560 0 ustar 00 HTTP/1.1 400 Bad Request Server: nginx Date: Sun, 05 May 2013 08:52:09 GMT Content-Type: application/json;charset=utf-8 Content-Length: 127 Connection: keep-alive Cache-Control: no-cache, no-store Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true { "error": { "type": "invalid_request_error", "message": "Charge ch_1lvgjcQgrNWUuZ has already been captured." } } stripe/tests/Mock/UpdateCardFailure.txt 0000604 00000000612 15173176033 0014173 0 ustar 00 HTTP/1.1 404 Not Found Server: nginx Date: Tue, 26 Feb 2013 16:32:51 GMT Content-Type: application/json;charset=utf-8 Content-Length: 131 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "error": { "type": "invalid_request_error", "message": "No such customer: cus_1MZeNih5LdKxDq", "param": "id" } } stripe/tests/Mock/VoidSuccess.txt 0000604 00000000077 15173176033 0013106 0 ustar 00 HTTP/1.1 200 OK {"id":"ch_12RgN9L7XhO9mI","object": "charge"} stripe/tests/Mock/CreateCustomerSuccess.txt 0000604 00000001725 15173176033 0015133 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Tue, 26 Feb 2013 16:11:12 GMT Content-Type: application/json;charset=utf-8 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "object": "customer", "created": 1361895072, "id": "cus_1MZSEtqSghKx99", "livemode": false, "description": "fdsa", "default_card": "card_15WhVwIobxWFFmzdQ3QBSwNi", "active_card": { "object": "card", "last4": "4242", "type": "Visa", "exp_month": 9, "exp_year": 2019, "fingerprint": "dfB0t0avO0bWr9eY", "country": "US", "name": "fdjsk fdjksl", "address_line1": "", "address_line2": "", "address_city": "", "address_state": "", "address_zip": "", "address_country": "", "cvc_check": "pass", "address_line1_check": "pass", "address_zip_check": "pass" }, "email": null, "delinquent": false, "subscription": null, "discount": null, "account_balance": 0 } stripe/tests/Mock/PurchaseWithSourceSuccess.txt 0000604 00000001534 15173176033 0015773 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Fri, 15 Feb 2013 18:25:28 GMT Content-Type: application/json;charset=utf-8 Content-Length: 995 Connection: keep-alive Cache-Control: no-cache, no-store Access-Control-Allow-Credentials: true Access-Control-Max-Age: 300 { "id": "ch_1IU9gcUiNASROd", "object": "charge", "created": 1360952728, "livemode": false, "paid": true, "amount": 1000, "currency": "usd", "refunded": false, "fee": 59, "fee_details": [ { "amount": 59, "currency": "usd", "type": "stripe_fee", "description": "Stripe processing fees", "application": null, "amount_refunded": 0 } ], "source": { "id": "card_15WgqxIobxWFFmzdk5V9z3g9" }, "failure_message": null, "amount_refunded": 0, "customer": null, "invoice": null, "description": "first purchase", "dispute": null } stripe/tests/Mock/FetchTransactionFailure.txt 0000604 00000000622 15173176033 0015417 0 ustar 00 HTTP/1.1 404 Not Found Server: nginx Date: Wed, 24 Jul 2013 13:40:31 GMT Content-Type: application/json;charset=utf-8 Content-Length: 132 Connection: keep-alive Access-Control-Allow-Credentials: true Access-Control-Max-Age: 300 Cache-Control: no-cache, no-store { "error": { "type": "invalid_request_error", "message": "No such charge: ch_29yrvk84GVDsq9fake", "param": "id" } } stripe/tests/Mock/CaptureSuccess.txt 0000604 00000002345 15173176033 0013610 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Sun, 05 May 2013 08:51:15 GMT Content-Type: application/json;charset=utf-8 Content-Length: 997 Connection: keep-alive Cache-Control: no-cache, no-store Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true { "id": "ch_1lvgjcQgrNWUuZ", "object": "charge", "created": 1367743707, "livemode": false, "paid": true, "amount": 1000, "currency": "usd", "refunded": false, "fee": 59, "fee_details": [ { "amount": 59, "currency": "usd", "type": "stripe_fee", "description": "Stripe processing fees", "application": null, "amount_refunded": 0 } ], "card": { "object": "card", "last4": "4242", "type": "Visa", "exp_month": 9, "exp_year": 2015, "fingerprint": "dfB0t0avO0bWr9eY", "country": "US", "name": "fdsa asdf", "address_line1": "", "address_line2": "", "address_city": "", "address_state": "", "address_zip": "", "address_country": "", "cvc_check": "pass", "address_line1_check": "pass", "address_zip_check": "pass" }, "captured": true, "failure_message": null, "amount_refunded": 0, "customer": null, "invoice": null, "description": "", "dispute": null } stripe/tests/Mock/DeleteCustomerFailure.txt 0000604 00000000612 15173176033 0015103 0 ustar 00 HTTP/1.1 404 Not Found Server: nginx Date: Tue, 26 Feb 2013 16:32:51 GMT Content-Type: application/json;charset=utf-8 Content-Length: 131 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "error": { "type": "invalid_request_error", "message": "No such customer: cus_1MZeNih5LdKxDq", "param": "id" } } stripe/tests/Mock/DeleteCardSuccess.txt 0000604 00000000463 15173176033 0014200 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Tue, 26 Feb 2013 16:33:08 GMT Content-Type: application/json;charset=utf-8 Content-Length: 52 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "deleted": true, "id": "cus_1MZSEtqSghKx99" } stripe/tests/Mock/PurchaseFailure.txt 0000604 00000000645 15173176033 0013737 0 ustar 00 HTTP/1.1 402 Payment Required Server: nginx Date: Fri, 15 Feb 2013 18:26:37 GMT Content-Type: application/json;charset=utf-8 Content-Length: 151 Connection: keep-alive Cache-Control: no-cache, no-store Access-Control-Allow-Credentials: true Access-Control-Max-Age: 300 { "error": { "message": "Your card was declined", "type": "card_error", "code": "card_declined", "charge": "ch_1IUAZQWFYrPooM" } } stripe/tests/Mock/FetchTransactionSuccess.txt 0000604 00000002407 15173176033 0015443 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Wed, 24 Jul 2013 07:14:02 GMT Content-Type: application/json;charset=utf-8 Content-Length: 1092 Connection: keep-alive Access-Control-Allow-Credentials: true Access-Control-Max-Age: 300 Cache-Control: no-cache, no-store { "id": "ch_29yrvk84GVDsq9", "object": "charge", "created": 1373290882, "livemode": false, "paid": true, "amount": 4200, "currency": "gbp", "refunded": false, "fee": 152, "fee_details": [ { "amount": 152, "currency": "gbp", "type": "stripe_fee", "description": "Stripe processing fees", "application": null, "amount_refunded": 0 } ], "card": { "object": "card", "last4": "4242", "type": "Visa", "exp_month": 5, "exp_year": 2015, "fingerprint": "o7bnpaR6swBKn5O7", "customer": null, "country": "US", "name": "John Doe", "address_line1": "", "address_line2": "", "address_city": "", "address_state": "", "address_zip": "", "address_country": "", "cvc_check": "pass", "address_line1_check": "pass", "address_zip_check": "pass" }, "captured": true, "failure_message": null, "failure_code": null, "amount_refunded": 0, "customer": null, "invoice": null, "description": "A12BCD/2", "dispute": null } stripe/tests/Mock/CreateCustomerFailure.txt 0000604 00000000631 15173176033 0015105 0 ustar 00 HTTP/1.1 402 Payment Required Server: nginx Date: Tue, 26 Feb 2013 16:17:02 GMT Content-Type: application/json;charset=utf-8 Content-Length: 139 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "error": { "message": "You must provide an integer value for 'exp_year'.", "type": "card_error", "param": "exp_year" } } stripe/tests/Mock/VoidFailure.txt 0000604 00000000135 15173176033 0013060 0 ustar 00 HTTP/1.1 200 OK {"error":{"message":"Charge ch_12RgN9L7XhO9mI has already been refunded."}} stripe/tests/Mock/UpdateCardSuccess.txt 0000604 00000001003 15173176033 0014207 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Tue, 26 Feb 2013 16:11:12 GMT Content-Type: application/json;charset=utf-8 Content-Length: 694 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "object": "customer", "created": 1365771516, "id": "cus_1MZeNih5LdKxDq", "livemode": false, "description": "fdsa", "active_card": null, "email": null, "delinquent": false, "subscription": null, "discount": null, "account_balance": 0 } stripe/tests/Mock/RefundFailure.txt 0000604 00000000135 15173176033 0013402 0 ustar 00 HTTP/1.1 200 OK {"error":{"message":"Charge ch_12RgN9L7XhO9mI has already been refunded."}} stripe/tests/Mock/FetchBalanceTransactionFailure.txt 0000604 00000000636 15173176033 0016672 0 ustar 00 HTTP/1.1 404 Not Found Server: nginx Date: Wed, 24 Jul 2013 13:40:31 GMT Content-Type: application/json;charset=utf-8 Content-Length: 132 Connection: keep-alive Access-Control-Allow-Credentials: true Access-Control-Max-Age: 300 Cache-Control: no-cache, no-store { "error": { "type": "invalid_request_error", "message": "No such balance: txn_1044bu4CmsDZ3Zk6BGg97VUUfake", "param": "id" } } stripe/tests/Mock/CreateCardSuccess.txt 0000604 00000001526 15173176033 0014202 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Tue, 26 Feb 2013 16:11:12 GMT Content-Type: application/json;charset=utf-8 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "id": "card_15WgqxIobxWFFmzdk5V9z3g9", "object": "card", "last4": "4444", "brand": "MasterCard", "funding": "credit", "exp_month": 1, "exp_year": 2020, "fingerprint": "JM5ri11gcDo8UgkV", "country": "US", "name": "Another Customer", "address_line1": "1 Downa Creek Road", "address_line2": "", "address_city": "Upper Swan", "address_state": "WA", "address_zip": "6999", "address_country": "AU", "cvc_check": "pass", "address_line1_check": "pass", "address_zip_check": "pass", "dynamic_last4": null, "customer": "cus_5i75ZdvSgIgLdW" } stripe/tests/Mock/UpdateCustomerSuccess.txt 0000604 00000001003 15173176033 0015137 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Tue, 26 Feb 2013 16:11:12 GMT Content-Type: application/json;charset=utf-8 Content-Length: 694 Connection: keep-alive Access-Control-Max-Age: 300 Access-Control-Allow-Credentials: true Cache-Control: no-cache, no-store { "object": "customer", "created": 1365771516, "id": "cus_1MZeNih5LdKxDq", "livemode": false, "description": "fdsa", "active_card": null, "email": null, "delinquent": false, "subscription": null, "discount": null, "account_balance": 0 } stripe/tests/Mock/FetchTokenSuccess.txt 0000604 00000001661 15173176033 0014237 0 ustar 00 HTTP/1.1 200 OK Server: nginx Date: Wed, 24 Jul 2013 07:14:02 GMT Content-Type: application/json;charset=utf-8 Content-Length: 1092 Connection: keep-alive Access-Control-Allow-Credentials: true Access-Control-Max-Age: 300 Cache-Control: no-cache, no-store { "id": "tok_15Kuns2eZvKYlo2CDt9wRdzS", "livemode": false, "created": 1421255976, "used": false, "object": "token", "type": "card", "card": { "id": "card_15Kuns2eZvKYlo2CugO37SA3", "object": "card", "last4": "4242", "brand": "Visa", "funding": "credit", "exp_month": 8, "exp_year": 2016, "fingerprint": "Xt5EWLLDS7FJjR1c", "country": "US", "name": null, "address_line1": null, "address_line2": null, "address_city": null, "address_state": null, "address_zip": null, "address_country": null, "cvc_check": null, "address_line1_check": null, "address_zip_check": null, "dynamic_last4": null } } stripe/tests/GatewayTest.php 0000604 00000007276 15173176033 0012204 0 ustar 00 <?php namespace Omnipay\Stripe; use Omnipay\Tests\GatewayTestCase; class GatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); } public function testAuthorize() { $request = $this->gateway->authorize(array('amount' => '10.00')); $this->assertInstanceOf('Omnipay\Stripe\Message\AuthorizeRequest', $request); $this->assertSame('10.00', $request->getAmount()); } public function testCapture() { $request = $this->gateway->capture(array('amount' => '10.00')); $this->assertInstanceOf('Omnipay\Stripe\Message\CaptureRequest', $request); $this->assertSame('10.00', $request->getAmount()); } public function testPurchase() { $request = $this->gateway->purchase(array('amount' => '10.00')); $this->assertInstanceOf('Omnipay\Stripe\Message\PurchaseRequest', $request); $this->assertSame('10.00', $request->getAmount()); } public function testRefund() { $request = $this->gateway->refund(array('amount' => '10.00')); $this->assertInstanceOf('Omnipay\Stripe\Message\RefundRequest', $request); $this->assertSame('10.00', $request->getAmount()); } public function testVoid() { $request = $this->gateway->void(); $this->assertInstanceOf('Omnipay\Stripe\Message\VoidRequest', $request); } public function testFetchTransaction() { $request = $this->gateway->fetchTransaction(array()); $this->assertInstanceOf('Omnipay\Stripe\Message\FetchTransactionRequest', $request); } public function testFetchToken() { $request = $this->gateway->fetchToken(array()); $this->assertInstanceOf('Omnipay\Stripe\Message\FetchTokenRequest', $request); } public function testCreateCard() { $request = $this->gateway->createCard(array('description' => 'foo')); $this->assertInstanceOf('Omnipay\Stripe\Message\CreateCardRequest', $request); $this->assertSame('foo', $request->getDescription()); } public function testUpdateCard() { $request = $this->gateway->updateCard(array('cardReference' => 'cus_1MZSEtqSghKx99')); $this->assertInstanceOf('Omnipay\Stripe\Message\UpdateCardRequest', $request); $this->assertSame('cus_1MZSEtqSghKx99', $request->getCardReference()); } public function testDeleteCard() { $request = $this->gateway->deleteCard(array('cardReference' => 'cus_1MZSEtqSghKx99')); $this->assertInstanceOf('Omnipay\Stripe\Message\DeleteCardRequest', $request); $this->assertSame('cus_1MZSEtqSghKx99', $request->getCardReference()); } public function testCreateCustomer() { $request = $this->gateway->createCustomer(array('description' => 'foo@foo.com')); $this->assertInstanceOf('Omnipay\Stripe\Message\CreateCustomerRequest', $request); $this->assertSame('foo@foo.com', $request->getDescription()); } public function testUpdateCustomer() { $request = $this->gateway->updateCustomer(array('customerReference' => 'cus_1MZSEtqSghKx99')); $this->assertInstanceOf('Omnipay\Stripe\Message\UpdateCustomerRequest', $request); $this->assertSame('cus_1MZSEtqSghKx99', $request->getCustomerReference()); } public function testDeleteCustomer() { $request = $this->gateway->deleteCustomer(array('customerReference' => 'cus_1MZSEtqSghKx99')); $this->assertInstanceOf('Omnipay\Stripe\Message\DeleteCustomerRequest', $request); $this->assertSame('cus_1MZSEtqSghKx99', $request->getCustomerReference()); } } stripe/tests/Message/UpdateCustomerRequestTest.php 0000604 00000003535 15173176033 0016476 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class UpdateCustomerRequestTest extends TestCase { public function setUp() { $this->request = new UpdateCustomerRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setCustomerReference('cus_1MZSEtqSghKx99'); } public function testEndpoint() { $this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99', $this->request->getEndpoint()); } public function testDataWithToken() { $this->request->setToken('xyz'); $data = $this->request->getData(); $this->assertSame('xyz', $data['card']); } public function testDataWithCard() { $card = $this->getValidCard(); $this->request->setCard($card); $data = $this->request->getData(); $this->assertSame($card['number'], $data['card']['number']); } public function testSendSuccess() { $this->setMockHttpResponse('UpdateCustomerSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('cus_1MZeNih5LdKxDq', $response->getCustomerReference()); $this->assertNull($response->getMessage()); } public function testSendFailure() { $this->setMockHttpResponse('UpdateCustomerFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCustomerReference()); $this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage()); } } stripe/tests/Message/AuthorizeRequestTest.php 0000604 00000007623 15173176033 0015506 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class AuthorizeRequestTest extends TestCase { public function setUp() { $this->request = new AuthorizeRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '12.00', 'currency' => 'USD', 'card' => $this->getValidCard(), 'description' => 'Order #42', 'metadata' => array( 'foo' => 'bar', ), 'applicationFee' => '1.00' ) ); } public function testGetData() { $data = $this->request->getData(); $this->assertSame(1200, $data['amount']); $this->assertSame('usd', $data['currency']); $this->assertSame('Order #42', $data['description']); $this->assertSame('false', $data['capture']); $this->assertSame(array('foo' => 'bar'), $data['metadata']); $this->assertSame(100, $data['application_fee']); } /** * @expectedException \Omnipay\Common\Exception\InvalidRequestException * @expectedExceptionMessage The source parameter is required */ public function testCardRequired() { $this->request->setCard(null); $this->request->getData(); } public function testDataWithCustomerReference() { $this->request->setCard(null); $this->request->setCustomerReference('abc'); $data = $this->request->getData(); $this->assertSame('abc', $data['customer']); } public function testDataWithCardReference() { $this->request->setCustomerReference('abc'); $this->request->setCardReference('xyz'); $data = $this->request->getData(); $this->assertSame('abc', $data['customer']); $this->assertSame('xyz', $data['source']); } public function testDataWithStatementDescriptor() { $this->request->setStatementDescriptor('OMNIPAY'); $data = $this->request->getData(); $this->assertSame('OMNIPAY', $data['statement_descriptor']); } public function testDataWithSourceAndDestination() { $this->request->setSource('abc'); $this->request->setDestination('xyz'); $data = $this->request->getData(); $this->assertSame('abc', $data['source']); $this->assertSame('xyz', $data['destination']); } public function testDataWithToken() { $this->request->setCustomerReference('abc'); $this->request->setToken('xyz'); $data = $this->request->getData(); $this->assertSame('abc', $data['customer']); $this->assertSame('xyz', $data['source']); } public function testDataWithCard() { $card = $this->getValidCard(); $this->request->setCard($card); $data = $this->request->getData(); $this->assertSame($card['number'], $data['source']['number']); } public function testSendSuccess() { $this->setMockHttpResponse('PurchaseSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference()); $this->assertSame('card_16n3EU2baUhq7QENSrstkoN0', $response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('PurchaseFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_1IUAZQWFYrPooM', $response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('Your card was declined', $response->getMessage()); } } stripe/tests/Message/ResponseTest.php 0000604 00000020205 15173176033 0013750 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class ResponseTest extends TestCase { public function testPurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('PurchaseSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference()); $this->assertSame('card_16n3EU2baUhq7QENSrstkoN0', $response->getCardReference()); $this->assertNull($response->getMessage()); $this->assertInternalType('array', $response->getSource()); } public function testPurchaseWithSourceSuccess() { $httpResponse = $this->getMockHttpResponse('PurchaseWithSourceSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference()); $this->assertSame('card_15WgqxIobxWFFmzdk5V9z3g9', $response->getCardReference()); $this->assertNull($response->getMessage()); } public function testPurchaseFailure() { $httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_1IUAZQWFYrPooM', $response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('Your card was declined', $response->getMessage()); $this->assertNull($response->getSource()); } public function testCreateCustomerSuccess() { $httpResponse = $this->getMockHttpResponse('CreateCustomerSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('cus_1MZSEtqSghKx99', $response->getCustomerReference()); $this->assertNull($response->getMessage()); } public function testCreateCustomerFailure() { $httpResponse = $this->getMockHttpResponse('CreateCustomerFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCustomerReference()); $this->assertSame('You must provide an integer value for \'exp_year\'.', $response->getMessage()); } public function testUpdateCustomerSuccess() { $httpResponse = $this->getMockHttpResponse('UpdateCustomerSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('cus_1MZeNih5LdKxDq', $response->getCustomerReference()); $this->assertNull($response->getMessage()); } public function testUpdateCustomerFailure() { $httpResponse = $this->getMockHttpResponse('UpdateCustomerFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCustomerReference()); $this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage()); } public function testDeleteCustomerSuccess() { $httpResponse = $this->getMockHttpResponse('DeleteCustomerSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCustomerReference()); $this->assertNull($response->getMessage()); } public function testDeleteCustomerFailure() { $httpResponse = $this->getMockHttpResponse('DeleteCustomerFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCustomerReference()); $this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage()); } public function testCreateCardSuccess() { $httpResponse = $this->getMockHttpResponse('CreateCardSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('card_15WgqxIobxWFFmzdk5V9z3g9', $response->getCardReference()); $this->assertNull($response->getMessage()); } public function testCreateCardFailure() { $httpResponse = $this->getMockHttpResponse('CreateCardFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('You must provide an integer value for \'exp_year\'.', $response->getMessage()); } public function testUpdateCardSuccess() { $httpResponse = $this->getMockHttpResponse('UpdateCardSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('cus_1MZeNih5LdKxDq', $response->getCardReference()); $this->assertNull($response->getMessage()); } public function testUpdateCardFailure() { $httpResponse = $this->getMockHttpResponse('UpdateCardFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage()); } public function testDeleteCardSuccess() { $httpResponse = $this->getMockHttpResponse('DeleteCardSuccess.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertNull($response->getMessage()); } public function testDeleteCardFailure() { $httpResponse = $this->getMockHttpResponse('DeleteCardFailure.txt'); $response = new Response($this->getMockRequest(), $httpResponse->json()); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage()); } } stripe/tests/Message/DeleteCardRequestTest.php 0000604 00000003425 15173176033 0015524 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class DeleteCardRequestTest extends TestCase { public function setUp() { $this->request = new DeleteCardRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setCardReference('cus_1MZSEtqSghKx99'); } public function testEndpoint() { $this->request->setCustomerReference(''); $this->request->setCardReference('cus_1MZSEtqSghKx99'); $this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99', $this->request->getEndpoint()); $this->request->setCustomerReference('cus_1MZSEtqSghKx99'); $this->request->setCardReference('card_15Wg7vIobxWFFmzdvC5fVY67'); $this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99/cards/card_15Wg7vIobxWFFmzdvC5fVY67', $this->request->getEndpoint()); } public function testSendSuccess() { $this->setMockHttpResponse('DeleteCardSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendFailure() { $this->setMockHttpResponse('DeleteCardFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage()); } } stripe/tests/Message/RefundRequestTest.php 0000604 00000003420 15173176033 0014746 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class RefundRequestTest extends TestCase { public function setUp() { $this->request = new RefundRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setTransactionReference('ch_12RgN9L7XhO9mI') ->setAmount('10.00')->setRefundApplicationFee(true); } public function testEndpoint() { $this->assertSame('https://api.stripe.com/v1/charges/ch_12RgN9L7XhO9mI/refund', $this->request->getEndpoint()); } public function testAmount() { $data = $this->request->getData(); $this->assertSame(1000, $data['amount']); } public function testRefundApplicationFee() { $data = $this->request->getData(); $this->assertEquals("true", $data['refund_application_fee']); } public function testSendSuccess() { $this->setMockHttpResponse('RefundSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_12RgN9L7XhO9mI', $response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('RefundFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('Charge ch_12RgN9L7XhO9mI has already been refunded.', $response->getMessage()); } } stripe/tests/Message/CreateCardRequestTest.php 0000604 00000005566 15173176033 0015535 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class CreateCardRequestTest extends TestCase { public function setUp() { $this->request = new CreateCardRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setCard($this->getValidCard()); } public function testEndpoint() { $this->request->setCustomerReference(''); $this->assertSame('https://api.stripe.com/v1/customers', $this->request->getEndpoint()); $this->request->setCustomerReference('cus_1MZSEtqSghKx99'); $this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99/cards', $this->request->getEndpoint()); } /** * @expectedException \Omnipay\Common\Exception\InvalidRequestException * @expectedExceptionMessage The source parameter is required */ public function testCard() { $this->request->setCard(null); $this->request->getData(); } public function testDataWithToken() { $this->request->setToken('xyz'); $data = $this->request->getData(); $this->assertSame('xyz', $data['source']); } public function testDataWithCardReference() { $this->request->setCard(null); $this->request->setCardReference('xyz'); $data = $this->request->getData(); $this->assertSame('xyz', $data['source']); } public function testDataWithSource() { $this->request->setCard(null); $this->request->setSource('xyz'); $data = $this->request->getData(); $this->assertSame('xyz', $data['source']); } public function testDataWithCard() { $card = $this->getValidCard(); $this->request->setCard($card); $data = $this->request->getData(); $this->assertSame($card['number'], $data['source']['number']); } public function testSendSuccess() { $this->setMockHttpResponse('CreateCardSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('cus_5i75ZdvSgIgLdW', $response->getCustomerReference()); $this->assertSame('card_15WgqxIobxWFFmzdk5V9z3g9', $response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendFailure() { $this->setMockHttpResponse('CreateCardFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('You must provide an integer value for \'exp_year\'.', $response->getMessage()); } } stripe/tests/Message/FetchTransactionTest.php 0000604 00000002653 15173176033 0015420 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class FetchTransactionRequestTest extends TestCase { public function setUp() { $this->request = new FetchTransactionRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setTransactionReference('ch_29yrvk84GVDsq9'); } public function testEndpoint() { $this->assertSame('https://api.stripe.com/v1/charges/ch_29yrvk84GVDsq9', $this->request->getEndpoint()); } public function testSendSuccess() { $this->setMockHttpResponse('FetchTransactionSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_29yrvk84GVDsq9', $response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('FetchTransactionFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('No such charge: ch_29yrvk84GVDsq9fake', $response->getMessage()); } } stripe/tests/Message/VoidRequestTest.php 0000604 00000003151 15173176033 0014425 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class VoidRequestTest extends TestCase { public function setUp() { $this->request = new VoidRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setTransactionReference('ch_12RgN9L7XhO9mI') ->setRefundApplicationFee(true); } public function testEndpoint() { $this->assertSame('https://api.stripe.com/v1/charges/ch_12RgN9L7XhO9mI/refund', $this->request->getEndpoint()); } public function testRefundApplicationFee() { $data = $this->request->getData(); $this->assertEquals("true", $data['refund_application_fee']); } public function testSendSuccess() { $this->setMockHttpResponse('VoidSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_12RgN9L7XhO9mI', $response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('VoidFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('Charge ch_12RgN9L7XhO9mI has already been refunded.', $response->getMessage()); } } stripe/tests/Message/PurchaseRequestTest.php 0000604 00000004052 15173176033 0015277 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class PurchaseRequestTest extends TestCase { public function setUp() { $this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->initialize( array( 'amount' => '10.00', 'currency' => 'USD', 'card' => $this->getValidCard(), ) ); } public function testCaptureIsTrue() { $data = $this->request->getData(); $this->assertSame('true', $data['capture']); } public function testSendSuccess() { $this->setMockHttpResponse('PurchaseSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference()); $this->assertSame('card_16n3EU2baUhq7QENSrstkoN0', $response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendWithSourceSuccess() { $this->setMockHttpResponse('PurchaseWithSourceSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_1IU9gcUiNASROd', $response->getTransactionReference()); $this->assertSame('card_15WgqxIobxWFFmzdk5V9z3g9', $response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('PurchaseFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_1IUAZQWFYrPooM', $response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('Your card was declined', $response->getMessage()); } } stripe/tests/Message/FetchBalanceTransactionTest.php 0000604 00000003021 15173176033 0016654 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class FetchBalanceTransactionRequestTest extends TestCase { public function setUp() { $this->request = new FetchBalanceTransactionRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setBalanceTransactionReference('txn_1044bu4CmsDZ3Zk6BGg97VUU'); } public function testEndpoint() { $this->assertSame('https://api.stripe.com/v1/balance/history/txn_1044bu4CmsDZ3Zk6BGg97VUU', $this->request->getEndpoint()); } public function testSendSuccess() { $this->setMockHttpResponse('FetchBalanceTransactionSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('txn_1044bu4CmsDZ3Zk6BGg97VUU', $response->getBalanceTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('FetchBalanceTransactionFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getBalanceTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('No such balance: txn_1044bu4CmsDZ3Zk6BGg97VUUfake', $response->getMessage()); } } stripe/tests/Message/FetchTokenRequestTest.php 0000604 00000002720 15173176033 0015557 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class FetchTokenRequestTest extends TestCase { /** * @var FetchTokenRequest */ private $request; public function setUp() { $this->request = new FetchTokenRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setToken('tok_15Kuns2eZvKYlo2CDt9wRdzS'); } public function testEndpoint() { $this->assertSame('https://api.stripe.com/v1/tokens/tok_15Kuns2eZvKYlo2CDt9wRdzS', $this->request->getEndpoint()); } public function testSendSuccess() { $this->setMockHttpResponse('FetchTokenSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('tok_15Kuns2eZvKYlo2CDt9wRdzS', $response->getToken()); $this->assertInternalType('array', $response->getCard()); $this->assertNull($response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('FetchTokenFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getToken()); $this->assertNull($response->getCard()); $this->assertSame('No such token: tok_15Kuns2eZvKYlo2CDt9wRdzS', $response->getMessage()); } } stripe/tests/Message/CreateCustomerRequestTest.php 0000604 00000003644 15173176033 0016460 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class CreateCustomerRequestTest extends TestCase { public function setUp() { $this->request = new CreateCustomerRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setCard($this->getValidCard()); } public function testEndpoint() { $this->assertSame('https://api.stripe.com/v1/customers', $this->request->getEndpoint()); } public function testDataWithToken() { $this->request->setToken('xyz'); $data = $this->request->getData(); $this->assertSame('xyz', $data['card']); } public function testDataWithCard() { $card = $this->getValidCard(); $this->request->setCard($card); $data = $this->request->getData(); $this->assertSame($card['number'], $data['card']['number']); } public function testSendSuccess() { $this->setMockHttpResponse('CreateCustomerSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('cus_1MZSEtqSghKx99', $response->getCustomerReference()); $this->assertSame('card_15WhVwIobxWFFmzdQ3QBSwNi', $response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendFailure() { $this->setMockHttpResponse('CreateCustomerFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('You must provide an integer value for \'exp_year\'.', $response->getMessage()); } } stripe/tests/Message/AbstractRequestTest.php 0000604 00000003216 15173176033 0015271 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Mockery; use Omnipay\Tests\TestCase; class AbstractRequestTest extends TestCase { public function setUp() { $this->request = Mockery::mock('\Omnipay\Stripe\Message\AbstractRequest')->makePartial(); $this->request->initialize(); } public function testCardReference() { $this->assertSame($this->request, $this->request->setCardReference('abc123')); $this->assertSame('abc123', $this->request->getCardReference()); } public function testCardToken() { $this->assertSame($this->request, $this->request->setToken('abc123')); $this->assertSame('abc123', $this->request->getToken()); } public function testSource() { $this->assertSame($this->request, $this->request->setSource('abc123')); $this->assertSame('abc123', $this->request->getSource()); } public function testCardData() { $card = $this->getValidCard(); $this->request->setCard($card); $data = $this->request->getCardData(); $this->assertSame($card['number'], $data['number']); $this->assertSame($card['cvv'], $data['cvc']); } public function testCardDataEmptyCvv() { $card = $this->getValidCard(); $card['cvv'] = ''; $this->request->setCard($card); $data = $this->request->getCardData(); $this->assertTrue(empty($data['cvv'])); } public function testMetadata() { $this->assertSame($this->request, $this->request->setMetadata(array('foo' => 'bar'))); $this->assertSame(array('foo' => 'bar'), $this->request->getMetadata()); } } stripe/tests/Message/DeleteCustomerRequestTest.php 0000604 00000002630 15173176033 0016451 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class DeleteCustomerRequestTest extends TestCase { public function setUp() { $this->request = new DeleteCustomerRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setCustomerReference('cus_1MZSEtqSghKx99'); } public function testEndpoint() { $this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99', $this->request->getEndpoint()); } public function testSendSuccess() { $this->setMockHttpResponse('DeleteCustomerSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCustomerReference()); $this->assertNull($response->getMessage()); } public function testSendFailure() { $this->setMockHttpResponse('DeleteCustomerFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCustomerReference()); $this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage()); } } stripe/tests/Message/CaptureRequestTest.php 0000604 00000003244 15173176033 0015132 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class CaptureRequestTest extends TestCase { public function setUp() { $this->request = new CaptureRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setTransactionReference('foo'); } public function testEndpoint() { $this->assertSame('https://api.stripe.com/v1/charges/foo/capture', $this->request->getEndpoint()); } public function testAmount() { // defualt is no amount $this->assertArrayNotHasKey('amount', $this->request->getData()); $this->request->setAmount('10.00'); $data = $this->request->getData(); $this->assertSame(1000, $data['amount']); } public function testSendSuccess() { $this->setMockHttpResponse('CaptureSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('ch_1lvgjcQgrNWUuZ', $response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendError() { $this->setMockHttpResponse('CaptureFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('Charge ch_1lvgjcQgrNWUuZ has already been captured.', $response->getMessage()); } } stripe/tests/Message/UpdateCardRequestTest.php 0000604 00000004316 15173176033 0015544 0 ustar 00 <?php namespace Omnipay\Stripe\Message; use Omnipay\Tests\TestCase; class UpdateCardRequestTest extends TestCase { public function setUp() { $this->request = new UpdateCardRequest($this->getHttpClient(), $this->getHttpRequest()); $this->request->setCustomerReference('cus_1MZSEtqSghKx99'); $this->request->setCardReference('card_15Wg7vIobxWFFmzdvC5fVY67'); } public function testEndpoint() { $this->assertSame('https://api.stripe.com/v1/customers/cus_1MZSEtqSghKx99/cards/card_15Wg7vIobxWFFmzdvC5fVY67', $this->request->getEndpoint()); } public function testDataWithToken() { $this->request->setToken('xyz'); $data = $this->request->getData(); $this->assertSame('xyz', $data['source']); } public function testDataWithSource() { $this->request->setSource('xyz'); $data = $this->request->getData(); $this->assertSame('xyz', $data['source']); } public function testDataWithCard() { $card = $this->getValidCard(); $this->request->setCard($card); $data = $this->request->getData(); $this->assertSame($card['billingAddress1'], $data['source']['address_line1']); $this->assertSame($card['number'], $data['source']['number']); } public function testSendSuccess() { $this->setMockHttpResponse('UpdateCardSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('cus_1MZeNih5LdKxDq', $response->getCardReference()); $this->assertNull($response->getMessage()); } public function testSendFailure() { $this->setMockHttpResponse('UpdateCardFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getCardReference()); $this->assertSame('No such customer: cus_1MZeNih5LdKxDq', $response->getMessage()); } } stripe/.gitignore 0000604 00000000122 15173176033 0010037 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml .directory /dirlist.* /documents/ stripe/src/Message/UpdateCustomerRequest.php 0000604 00000004154 15173176033 0015261 0 ustar 00 <?php /** * Stripe Update Customer Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Update Customer Request. * * Customer objects allow you to perform recurring charges and * track multiple charges that are associated with the same customer. * The API allows you to create, delete, and update your customers. * You can retrieve individual customers as well as a list of all of * your customers. * * This request updates the specified customer by setting the values * of the parameters passed. Any parameters not provided will be left * unchanged. For example, if you pass the card parameter, that becomes * the customer's active card to be used for all charges in the future, * and the customer email address is updated to the email address * on the card. When you update a customer to a new valid card: for * each of the customer's current subscriptions, if the subscription * is in the `past_due` state, then the latest unpaid, unclosed * invoice for the subscription will be retried (note that this retry * will not count as an automatic retry, and will not affect the next * regularly scheduled payment for the invoice). (Note also that no * invoices pertaining to subscriptions in the `unpaid` state, or * invoices pertaining to canceled subscriptions, will be retried as * a result of updating the customer's card.) * * This request accepts mostly the same arguments as the customer * creation call. * * @link https://stripe.com/docs/api#update_customer */ class UpdateCustomerRequest extends AbstractRequest { public function getData() { $this->validate('customerReference'); $data = array(); $data['description'] = $this->getDescription(); if ($this->getToken()) { $data['card'] = $this->getToken(); } elseif ($this->getCard()) { $this->getCard()->validate(); $data['card'] = $this->getCardData(); $data['email'] = $this->getCard()->getEmail(); } return $data; } public function getEndpoint() { return $this->endpoint.'/customers/'.$this->getCustomerReference(); } } stripe/src/Message/UpdateCardRequest.php 0000604 00000005621 15173176033 0014331 0 ustar 00 <?php /** * Stripe Update Credit Card Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Update Credit Card Request. * * If you need to update only some card details, like the billing * address or expiration date, you can do so without having to re-enter * the full card details. Stripe also works directly with card networks * so that your customers can continue using your service without * interruption. * * When you update a card, Stripe will automatically validate the card. * * This requires both a customerReference and a cardReference. * * @link https://stripe.com/docs/api#update_card */ class UpdateCardRequest extends AbstractRequest { public function getData() { $this->validate('cardReference'); $this->validate('customerReference'); $data = array(); $data['description'] = $this->getDescription(); if ($this->getSource()) { $data['source'] = $this->getSource(); } elseif ($this->getToken()) { $data['source'] = $this->getToken(); } elseif ($this->getCard()) { $data['source'] = $this->getCardData(); $data['email'] = $this->getCard()->getEmail(); } return $data; } public function getEndpoint() { return $this->endpoint.'/customers/'.$this->getCustomerReference(). '/cards/'.$this->getCardReference(); } /** * Get the card data. * * This request uses a slightly different format for card data to * the other requests and does not require the card data to be * complete in full (or valid). * * @return array */ protected function getCardData() { $data = array(); $card = $this->getCard(); if (!empty($card)) { if ($card->getExpiryMonth()) { $data['exp_month'] = $card->getExpiryMonth(); } if ($card->getExpiryYear()) { $data['exp_year'] = $card->getExpiryYear(); } if ($card->getName()) { $data['name'] = $card->getName(); } if ($card->getNumber()) { $data['number'] = $card->getNumber(); } if ($card->getAddress1()) { $data['address_line1'] = $card->getAddress1(); } if ($card->getAddress2()) { $data['address_line2'] = $card->getAddress2(); } if ($card->getCity()) { $data['address_city'] = $card->getCity(); } if ($card->getPostcode()) { $data['address_zip'] = $card->getPostcode(); } if ($card->getState()) { $data['address_state'] = $card->getState(); } if ($card->getCountry()) { $data['address_country'] = $card->getCountry(); } } return $data; } } stripe/src/Message/CaptureRequest.php 0000604 00000002305 15173176033 0013714 0 ustar 00 <?php /** * Stripe Capture Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Capture Request. * * Use this request to capture and process a previously created authorization. * * Example -- note this example assumes that the authorization has been successful * and that the authorization ID returned from the authorization is held in $auth_id. * See AuthorizeRequest for the first part of this example transaction: * * <code> * // Once the transaction has been authorized, we can capture it for final payment. * $transaction = $gateway->capture(array( * 'amount' => '10.00', * 'currency' => 'AUD', * )); * $transaction->setTransactionReference($auth_id); * $response = $transaction->send(); * </code> * * @see AuthorizeRequest */ class CaptureRequest extends AbstractRequest { public function getData() { $this->validate('transactionReference'); $data = array(); if ($amount = $this->getAmountInteger()) { $data['amount'] = $amount; } return $data; } public function getEndpoint() { return $this->endpoint.'/charges/'.$this->getTransactionReference().'/capture'; } } stripe/src/Message/DeleteCardRequest.php 0000604 00000003535 15173176033 0014313 0 ustar 00 <?php /** * Stripe Delete Credit Card Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Delete Credit Card Request. * * This is normally used to delete a credit card from an existing * customer. * * You can delete cards from a customer or recipient. If you delete a * card that is currently the default card on a customer or recipient, * the most recently added card will be used as the new default. If you * delete the last remaining card on a customer or recipient, the * default_card attribute on the card's owner will become null. * * Note that for cards belonging to customers, you may want to prevent * customers on paid subscriptions from deleting all cards on file so * that there is at least one default card for the next invoice payment * attempt. * * In deference to the previous incarnation of this gateway, where * all CreateCard requests added a new customer and the customer ID * was used as the card ID, if a cardReference is passed in but no * customerReference then we assume that the cardReference is in fact * a customerReference and delete the customer. This might be * dangerous but it's the best way to ensure backwards compatibility. * * @link https://stripe.com/docs/api#delete_card */ class DeleteCardRequest extends AbstractRequest { public function getData() { $this->validate('cardReference'); return; } public function getHttpMethod() { return 'DELETE'; } public function getEndpoint() { if ($this->getCustomerReference()) { // Delete a card from a customer return $this->endpoint.'/customers/'. $this->getCustomerReference().'/cards/'. $this->getCardReference(); } // Delete the customer. Oops? return $this->endpoint.'/customers/'.$this->getCardReference(); } } stripe/src/Message/FetchTokenRequest.php 0000604 00000002277 15173176033 0014353 0 ustar 00 <?php /** * Stripe Fetch Token Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Fetch Token Request. * * Often you want to be able to charge credit cards or send payments * to bank accounts without having to hold sensitive card information * on your own servers. Stripe.js makes this easy in the browser, but * you can use the same technique in other environments with our token API. * * Tokens can be created with your publishable API key, which can safely * be embedded in downloadable applications like iPhone and Android apps. * You can then use a token anywhere in our API that a card or bank account * is accepted. Note that tokens are not meant to be stored or used more * than once—to store these details for use later, you should create * Customer or Recipient objects. * * @link https://stripe.com/docs/api#tokens */ class FetchTokenRequest extends AbstractRequest { public function getData() { $this->validate('token'); $data = array(); return $data; } public function getEndpoint() { return $this->endpoint.'/tokens/'.$this->getToken(); } public function getHttpMethod() { return 'GET'; } } stripe/src/Message/Response.php 0000604 00000010154 15173176033 0012537 0 ustar 00 <?php /** * Stripe Response. */ namespace Omnipay\Stripe\Message; use Omnipay\Common\Message\AbstractResponse; /** * Stripe Response. * * This is the response class for all Stripe requests. * * @see \Omnipay\Stripe\Gateway */ class Response extends AbstractResponse { /** * Is the transaction successful? * * @return bool */ public function isSuccessful() { return !isset($this->data['error']); } /** * Get the transaction reference. * * @return string|null */ public function getTransactionReference() { if (isset($this->data['object']) && 'charge' === $this->data['object']) { return $this->data['id']; } if (isset($this->data['error']) && isset($this->data['error']['charge'])) { return $this->data['error']['charge']; } return; } /** * Get the balance transaction reference. * * @return string|null */ public function getBalanceTransactionReference() { if (isset($this->data['object']) && 'charge' === $this->data['object']) { return $this->data['balance_transaction']; } if (isset($this->data['object']) && 'balance_transaction' === $this->data['object']) { return $this->data['id']; } if (isset($this->data['error']) && isset($this->data['error']['charge'])) { return $this->data['error']['charge']; } return null; } /** * Get a customer reference, for createCustomer requests. * * @return string|null */ public function getCustomerReference() { if (isset($this->data['object']) && 'customer' === $this->data['object']) { return $this->data['id']; } if (isset($this->data['object']) && 'card' === $this->data['object']) { if (!empty($this->data['customer'])) { return $this->data['customer']; } } return; } /** * Get a card reference, for createCard or createCustomer requests. * * @return string|null */ public function getCardReference() { if (isset($this->data['object']) && 'customer' === $this->data['object']) { if (!empty($this->data['default_card'])) { return $this->data['default_card']; } if (!empty($this->data['id'])) { return $this->data['id']; } } if (isset($this->data['object']) && 'card' === $this->data['object']) { if (!empty($this->data['id'])) { return $this->data['id']; } } if (isset($this->data['object']) && 'charge' === $this->data['object']) { if (! empty($this->data['source'])) { if (! empty($this->data['source']['id'])) { return $this->data['source']['id']; } } } return; } /** * Get a token, for createCard requests. * * @return string|null */ public function getToken() { if (isset($this->data['object']) && 'token' === $this->data['object']) { return $this->data['id']; } return; } /** * Get the card data from the response. * * @return array|null */ public function getCard() { if (isset($this->data['card'])) { return $this->data['card']; } return; } /** * Get the card data from the response of purchaseRequest. * * @return array|null */ public function getSource() { if (isset($this->data['source']) && $this->data['source']['object'] == 'card') { return $this->data['source']; } else { return; } } /** * Get the error message from the response. * * Returns null if the request was successful. * * @return string|null */ public function getMessage() { if (!$this->isSuccessful()) { return $this->data['error']['message']; } return; } } stripe/src/Message/CreateCardRequest.php 0000604 00000007244 15173176033 0014315 0 ustar 00 <?php /** * Stripe Create Credit Card Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Create Credit Card Request. * * In the stripe system, creating a credit card requires passing * a customer ID. The card is then added to the customer's account. * If the customer has no default card then the newly added * card becomes the customer's default card. * * This call can be used to create a new customer or add a card * to an existing customer. If a customerReference is passed in then * a card is added to an existing customer. If there is no * customerReference passed in then a new customer is created. The * response in that case will then contain both a customer token * and a card token, and is essentially the same as CreateCustomerRequest * * Example. This example assumes that you have already created a * customer, and that the customer reference is stored in $customer_id. * See CreateCustomerRequest for the first part of this transaction. * * <code> * // Create a credit card object * // This card can be used for testing. * // The CreditCard object is also used for creating customers. * $new_card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '5555555555554444', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '456', * 'email' => 'customer@example.com', * 'billingAddress1' => '1 Lower Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Upper Swan', * 'billingPostcode' => '6999', * 'billingState' => 'WA', * )); * * // Do a create card transaction on the gateway * $response = $gateway->createCard(array( * 'card' => $new_card, * 'customerReference' => $customer_id, * ))->send(); * if ($response->isSuccessful()) { * echo "Gateway createCard was successful.\n"; * // Find the card ID * $card_id = $response->getCardReference(); * echo "Card ID = " . $card_id . "\n"; * } * </code> * * @see CreateCustomerRequest * @link https://stripe.com/docs/api#create_card */ class CreateCardRequest extends AbstractRequest { public function getData() { $data = array(); // Only set the description if we are creating a new customer. if (!$this->getCustomerReference()) { $data['description'] = $this->getDescription(); } if ($this->getSource()) { $data['source'] = $this->getSource(); } elseif ($this->getCardReference()) { $data['source'] = $this->getCardReference(); } elseif ($this->getToken()) { $data['source'] = $this->getToken(); } elseif ($this->getCard()) { $this->getCard()->validate(); $data['source'] = $this->getCardData(); // Only set the email address if we are creating a new customer. if (!$this->getCustomerReference()) { $data['email'] = $this->getCard()->getEmail(); } } else { // one of token or card is required $this->validate('source'); } return $data; } public function getEndpoint() { if ($this->getCustomerReference()) { // Create a new card on an existing customer return $this->endpoint.'/customers/'. $this->getCustomerReference().'/cards'; } // Create a new customer and card return $this->endpoint.'/customers'; } } stripe/src/Message/PurchaseRequest.php 0000604 00000004643 15173176033 0014072 0 ustar 00 <?php /** * Stripe Purchase Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Purchase Request. * * To charge a credit card, you create a new charge object. If your API key * is in test mode, the supplied card won't actually be charged, though * everything else will occur as if in live mode. (Stripe assumes that the * charge would have completed successfully). * * Example: * * <code> * // Create a gateway for the Stripe Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('Stripe'); * * // Initialise the gateway * $gateway->initialize(array( * 'apiKey' => 'MyApiKey', * )); * * // Create a credit card object * // This card can be used for testing. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '4242424242424242', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'email' => 'customer@example.com', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do a purchase transaction on the gateway * $transaction = $gateway->purchase(array( * 'amount' => '10.00', * 'currency' => 'USD', * 'description' => 'This is a test purchase transaction.', * 'card' => $card, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Purchase transaction was successful!\n"; * $sale_id = $response->getTransactionReference(); * echo "Transaction reference = " . $sale_id . "\n"; * } * </code> * * Because a purchase request in Stripe looks similar to an * Authorize request, this class simply extends the AuthorizeRequest * class and over-rides the getData method setting capture = true. * * @see \Omnipay\Stripe\Gateway * @link https://stripe.com/docs/api#charges */ class PurchaseRequest extends AuthorizeRequest { public function getData() { $data = parent::getData(); $data['capture'] = 'true'; return $data; } } stripe/src/Message/RefundRequest.php 0000604 00000006116 15173176033 0013540 0 ustar 00 <?php /** * Stripe Refund Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Refund Request. * * When you create a new refund, you must specify a * charge to create it on. * * Creating a new refund will refund a charge that has * previously been created but not yet refunded. Funds will * be refunded to the credit or debit card that was originally * charged. The fees you were originally charged are also * refunded. * * You can optionally refund only part of a charge. You can * do so as many times as you wish until the entire charge * has been refunded. * * Once entirely refunded, a charge can't be refunded again. * This method will return an error when called on an * already-refunded charge, or when trying to refund more * money than is left on a charge. * * Example -- note this example assumes that the purchase has been successful * and that the transaction ID returned from the purchase is held in $sale_id. * See PurchaseRequest for the first part of this example transaction: * * <code> * // Do a refund transaction on the gateway * $transaction = $gateway->refund(array( * 'amount' => '10.00', * 'transactionReference' => $sale_id, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Refund transaction was successful!\n"; * $refund_id = $response->getTransactionReference(); * echo "Transaction reference = " . $refund_id . "\n"; * } * </code> * * @see PurchaseRequest * @see Omnipay\Stripe\Gateway * @link https://stripe.com/docs/api#create_refund */ class RefundRequest extends AbstractRequest { /** * @return bool Whether the application fee should be refunded */ public function getRefundApplicationFee() { return $this->getParameter('refundApplicationFee'); } /** * Whether to refund the application fee associated with a charge. * * From the {@link https://stripe.com/docs/api#create_refund Stripe docs}: * Boolean indicating whether the application fee should be refunded * when refunding this charge. If a full charge refund is given, the * full application fee will be refunded. Else, the application fee * will be refunded with an amount proportional to the amount of the * charge refunded. An application fee can only be refunded by the * application that created the charge. * * @param bool $value Whether the application fee should be refunded * * @return AbstractRequest */ public function setRefundApplicationFee($value) { return $this->setParameter('refundApplicationFee', $value); } public function getData() { $this->validate('transactionReference', 'amount'); $data = array(); $data['amount'] = $this->getAmountInteger(); if ($this->getRefundApplicationFee()) { $data['refund_application_fee'] = 'true'; } return $data; } public function getEndpoint() { return $this->endpoint.'/charges/'.$this->getTransactionReference().'/refund'; } } stripe/src/Message/VoidRequest.php 0000604 00000002416 15173176033 0013215 0 ustar 00 <?php /** * Stripe Void Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Void Request. * * Stripe does not support voiding, per se, but * we treat it as a full refund. * * See RefundRequest for additional information * * Example -- note this example assumes that the purchase has been successful * and that the transaction ID returned from the purchase is held in $sale_id. * See PurchaseRequest for the first part of this example transaction: * * <code> * // Do a void transaction on the gateway * $transaction = $gateway->void(array( * 'transactionReference' => $sale_id, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Void transaction was successful!\n"; * $void_id = $response->getTransactionReference(); * echo "Transaction reference = " . $void_id . "\n"; * } * </code> * * @see RefundRequest * @see Omnipay\Stripe\Gateway * @link https://stripe.com/docs/api#create_refund */ class VoidRequest extends RefundRequest { public function getData() { $this->validate('transactionReference'); $data = array(); if ($this->getRefundApplicationFee()) { $data['refund_application_fee'] = 'true'; } return $data; } } stripe/src/Message/CreateCustomerRequest.php 0000604 00000005127 15173176033 0015243 0 ustar 00 <?php /** * Stripe Create Customer Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Create Customer Request. * * Customer objects allow you to perform recurring charges and * track multiple charges that are associated with the same customer. * The API allows you to create, delete, and update your customers. * You can retrieve individual customers as well as a list of all of * your customers. * * Example: * * <code> * // Create a gateway for the Stripe Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('Stripe'); * * // Initialise the gateway * $gateway->initialize(array( * 'apiKey' => 'MyApiKey', * )); * * // Create a credit card object * // This card can be used for testing. * // The CreditCard object is also used for creating customers. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '4242424242424242', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'email' => 'customer@example.com', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do a create customer transaction on the gateway * $response = $gateway->createCustomer(array( * 'card' => $card, * ))->send(); * if ($response->isSuccessful()) { * echo "Gateway createCustomer was successful.\n"; * // Find the customer ID * $customer_id = $response->getCustomerReference(); * echo "Customer ID = " . $customer_id . "\n"; * // Find the card ID * $card_id = $response->getCardReference(); * echo "Card ID = " . $card_id . "\n"; * } * </code> * * @link https://stripe.com/docs/api#customers */ class CreateCustomerRequest extends AbstractRequest { public function getData() { $data = array(); $data['description'] = $this->getDescription(); if ($this->getToken()) { $data['card'] = $this->getToken(); } elseif ($this->getCard()) { $data['card'] = $this->getCardData(); $data['email'] = $this->getCard()->getEmail(); } return $data; } public function getEndpoint() { return $this->endpoint.'/customers'; } } stripe/src/Message/AuthorizeRequest.php 0000604 00000013564 15173176033 0014274 0 ustar 00 <?php /** * Stripe Authorize Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Authorize Request. * * An Authorize request is similar to a purchase request but the * charge issues an authorization (or pre-authorization), and no money * is transferred. The transaction will need to be captured later * in order to effect payment. Uncaptured charges expire in 7 days. * * Either a customerReference or a card is required. If a customerReference * is passed in then the cardReference must be the reference of a card * assigned to the customer. Otherwise, if you do not pass a customer ID, * the card you provide must either be a token, like the ones returned by * Stripe.js, or a dictionary containing a user's credit card details. * * IN OTHER WORDS: You cannot just pass a card reference into this request, * you must also provide a customer reference if you want to use a stored * card. * * Example: * * <code> * // Create a gateway for the Stripe Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('Stripe'); * * // Initialise the gateway * $gateway->initialize(array( * 'apiKey' => 'MyApiKey', * )); * * // Create a credit card object * // This card can be used for testing. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '4242424242424242', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'email' => 'customer@example.com', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do an authorize transaction on the gateway * $transaction = $gateway->authorize(array( * 'amount' => '10.00', * 'currency' => 'USD', * 'description' => 'This is a test authorize transaction.', * 'card' => $card, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Authorize transaction was successful!\n"; * $sale_id = $response->getTransactionReference(); * echo "Transaction reference = " . $sale_id . "\n"; * } * </code> * * @see \Omnipay\Stripe\Gateway * @link https://stripe.com/docs/api#charges */ class AuthorizeRequest extends AbstractRequest { /** * @return mixed */ public function getDestination() { return $this->getParameter('destination'); } /** * @param string $value * * @return AbstractRequest provides a fluent interface. */ public function setDestination($value) { return $this->setParameter('destination', $value); } /** * @return mixedgi */ public function getSource() { return $this->getParameter('source'); } /** * @param string $value * * @return AbstractRequest provides a fluent interface. */ public function setSource($value) { return $this->setParameter('source', $value); } /** * @return float */ public function getApplicationFee() { return $this->getParameter('applicationFee'); } /** * @return int */ public function getApplicationFeeInteger() { return (int) round($this->getApplicationFee() * pow(10, $this->getCurrencyDecimalPlaces())); } /** * @param string $value * * @return AbstractRequest provides a fluent interface. */ public function setApplicationFee($value) { return $this->setParameter('applicationFee', $value); } public function getStatementDescriptor() { return $this->getParameter('statementDescriptor'); } public function setStatementDescriptor($value) { $value = str_replace(array('<', '>', '"', '\''), '', $value); return $this->setParameter('statementDescriptor', $value); } public function getData() { $this->validate('amount', 'currency'); $data = array(); $data['amount'] = $this->getAmountInteger(); $data['currency'] = strtolower($this->getCurrency()); $data['description'] = $this->getDescription(); $data['metadata'] = $this->getMetadata(); $data['capture'] = 'false'; if ($this->getStatementDescriptor()) { $data['statement_descriptor'] = $this->getStatementDescriptor(); } if ($this->getDestination()) { $data['destination'] = $this->getDestination(); } if ($this->getApplicationFee()) { $data['application_fee'] = $this->getApplicationFeeInteger(); } if ($this->getSource()) { $data['source'] = $this->getSource(); } elseif ($this->getCardReference()) { $data['source'] = $this->getCardReference(); if ($this->getCustomerReference()) { $data['customer'] = $this->getCustomerReference(); } } elseif ($this->getToken()) { $data['source'] = $this->getToken(); if ($this->getCustomerReference()) { $data['customer'] = $this->getCustomerReference(); } } elseif ($this->getCard()) { $data['source'] = $this->getCardData(); } elseif ($this->getCustomerReference()) { $data['customer'] = $this->getCustomerReference(); } else { // one of cardReference, token, or card is required $this->validate('source'); } return $data; } public function getEndpoint() { return $this->endpoint.'/charges'; } } stripe/src/Message/DeleteCustomerRequest.php 0000604 00000001237 15173176033 0015240 0 ustar 00 <?php /** * Stripe Delete Customer Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Delete Customer Request. * * Permanently deletes a customer. It cannot be undone. Also immediately * cancels any active subscriptions on the customer. * * @link https://stripe.com/docs/api#delete_customer */ class DeleteCustomerRequest extends AbstractRequest { public function getData() { $this->validate('customerReference'); return; } public function getHttpMethod() { return 'DELETE'; } public function getEndpoint() { return $this->endpoint.'/customers/'.$this->getCustomerReference(); } } stripe/src/Message/FetchTransactionRequest.php 0000604 00000002317 15173176033 0015553 0 ustar 00 <?php /** * Stripe Fetch Transaction Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Fetch Transaction Request. * * Example -- note this example assumes that the purchase has been successful * and that the transaction ID returned from the purchase is held in $sale_id. * See PurchaseRequest for the first part of this example transaction: * * <code> * // Fetch the transaction so that details can be found for refund, etc. * $transaction = $gateway->fetchTransaction(); * $transaction->setTransactionReference($sale_id); * $response = $transaction->send(); * $data = $response->getData(); * echo "Gateway fetchTransaction response data == " . print_r($data, true) . "\n"; * </code> * * @see PurchaseRequest * @see Omnipay\Stripe\Gateway * @link https://stripe.com/docs/api#retrieve_charge */ class FetchTransactionRequest extends AbstractRequest { public function getData() { $this->validate('transactionReference'); $data = array(); return $data; } public function getEndpoint() { return $this->endpoint.'/charges/'.$this->getTransactionReference(); } public function getHttpMethod() { return 'GET'; } } stripe/src/Message/AbstractRequest.php 0000604 00000011750 15173176033 0014060 0 ustar 00 <?php /** * Stripe Abstract Request. */ namespace Omnipay\Stripe\Message; /** * Stripe Abstract Request. * * This is the parent class for all Stripe requests. * * Test modes: * * Stripe accounts have test-mode API keys as well as live-mode * API keys. These keys can be active at the same time. Data * created with test-mode credentials will never hit the credit * card networks and will never cost anyone money. * * Unlike some gateways, there is no test mode endpoint separate * to the live mode endpoint, the Stripe API endpoint is the same * for test and for live. * * Setting the testMode flag on this gateway has no effect. To * use test mode just use your test mode API key. * * You can use any of the cards listed at https://stripe.com/docs/testing * for testing. * * @see \Omnipay\Stripe\Gateway * @link https://stripe.com/docs/api * * @method \Omnipay\Stripe\Message\Response send() */ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { /** * Live or Test Endpoint URL. * * @var string URL */ protected $endpoint = 'https://api.stripe.com/v1'; /** * Get the gateway API Key. * * @return string */ public function getApiKey() { return $this->getParameter('apiKey'); } /** * Set the gateway API Key. * * @return AbstractRequest provides a fluent interface. */ public function setApiKey($value) { return $this->setParameter('apiKey', $value); } /** * @deprecated */ public function getCardToken() { return $this->getCardReference(); } /** * @deprecated */ public function setCardToken($value) { return $this->setCardReference($value); } /** * Get the customer reference. * * @return string */ public function getCustomerReference() { return $this->getParameter('customerReference'); } /** * Set the customer reference. * * Used when calling CreateCard on an existing customer. If this * parameter is not set then a new customer is created. * * @return AbstractRequest provides a fluent interface. */ public function setCustomerReference($value) { return $this->setParameter('customerReference', $value); } public function getMetadata() { return $this->getParameter('metadata'); } public function setMetadata($value) { return $this->setParameter('metadata', $value); } abstract public function getEndpoint(); /** * Get HTTP Method. * * This is nearly always POST but can be over-ridden in sub classes. * * @return string */ public function getHttpMethod() { return 'POST'; } public function sendData($data) { // don't throw exceptions for 4xx errors $this->httpClient->getEventDispatcher()->addListener( 'request.error', function ($event) { if ($event['response']->isClientError()) { $event->stopPropagation(); } } ); $httpRequest = $this->httpClient->createRequest( $this->getHttpMethod(), $this->getEndpoint(), null, $data ); $httpResponse = $httpRequest ->setHeader('Authorization', 'Basic '.base64_encode($this->getApiKey().':')) ->send(); return $this->response = new Response($this, $httpResponse->json()); } /** * @return mixed */ public function getSource() { return $this->getParameter('source'); } /** * @param $value * * @return AbstractRequest provides a fluent interface. */ public function setSource($value) { return $this->setParameter('source', $value); } /** * Get the card data. * * Because the stripe gateway uses a common format for passing * card data to the API, this function can be called to get the * data from the associated card object in the format that the * API requires. * * @return array */ protected function getCardData() { $card = $this->getCard(); $card->validate(); $data = array(); $data['object'] = 'card'; $data['number'] = $card->getNumber(); $data['exp_month'] = $card->getExpiryMonth(); $data['exp_year'] = $card->getExpiryYear(); if ($card->getCvv()) { $data['cvc'] = $card->getCvv(); } $data['name'] = $card->getName(); $data['address_line1'] = $card->getAddress1(); $data['address_line2'] = $card->getAddress2(); $data['address_city'] = $card->getCity(); $data['address_zip'] = $card->getPostcode(); $data['address_state'] = $card->getState(); $data['address_country'] = $card->getCountry(); $data['email'] = $card->getEmail(); return $data; } } stripe/src/Message/FetchBalanceTransactionRequest.php 0000604 00000003373 15173176033 0017024 0 ustar 00 <?php /** * Stripe Fetch Transaction Request */ namespace Omnipay\Stripe\Message; /** * Stripe Fetch Balance Request * * Example -- note this example assumes that the purchase has been successful * and that the transaction balance ID returned from the purchase is held in $balanceTransactionId. * See PurchaseRequest for the first part of this example transaction: * * <code> * // Fetch the balance to get information about the payment. * $balance = $gateway->fetchBalanceTransaction(); * $balance->setBalanceTransactionReference($balance_transaction_id); * $response = $balance->send(); * $data = $response->getData(); * echo "Gateway fetchBalance response data == " . print_r($data, true) . "\n"; * </code> * * @see PurchaseRequest * @see Omnipay\Stripe\Gateway * @link https://stripe.com/docs/api#retrieve_balance_transaction */ class FetchBalanceTransactionRequest extends AbstractRequest { /** * Get the transaction balance reference * * @return string */ public function getBalanceTransactionReference() { return $this->getParameter('balanceTransactionReference'); } /** * Set the transaction balance reference * * @return AbstractRequest provides a fluent interface. */ public function setBalanceTransactionReference($value) { return $this->setParameter('balanceTransactionReference', $value); } public function getData() { $this->validate('balanceTransactionReference'); $data = array(); return $data; } public function getEndpoint() { return $this->endpoint.'/balance/history/'.$this->getBalanceTransactionReference(); } public function getHttpMethod() { return 'GET'; } } stripe/src/Gateway.php 0000604 00000036662 15173176033 0010772 0 ustar 00 <?php /** * Stripe Gateway. */ namespace Omnipay\Stripe; use Omnipay\Common\AbstractGateway; /** * Stripe Gateway. * * Example: * * <code> * // Create a gateway for the Stripe Gateway * // (routes to GatewayFactory::create) * $gateway = Omnipay::create('Stripe'); * * // Initialise the gateway * $gateway->initialize(array( * 'apiKey' => 'MyApiKey', * )); * * // Create a credit card object * // This card can be used for testing. * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '4242424242424242', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'email' => 'customer@example.com', * 'billingAddress1' => '1 Scrubby Creek Road', * 'billingCountry' => 'AU', * 'billingCity' => 'Scrubby Creek', * 'billingPostcode' => '4999', * 'billingState' => 'QLD', * )); * * // Do a purchase transaction on the gateway * $transaction = $gateway->purchase(array( * 'amount' => '10.00', * 'currency' => 'USD', * 'card' => $card, * )); * $response = $transaction->send(); * if ($response->isSuccessful()) { * echo "Purchase transaction was successful!\n"; * $sale_id = $response->getTransactionReference(); * echo "Transaction reference = " . $sale_id . "\n"; * * $balance_transaction_id = $response->getBalanceTransactionReference(); * echo "Balance Transaction reference = " . $balance_transaction_id . "\n"; * } * </code> * * Test modes: * * Stripe accounts have test-mode API keys as well as live-mode * API keys. These keys can be active at the same time. Data * created with test-mode credentials will never hit the credit * card networks and will never cost anyone money. * * Unlike some gateways, there is no test mode endpoint separate * to the live mode endpoint, the Stripe API endpoint is the same * for test and for live. * * Setting the testMode flag on this gateway has no effect. To * use test mode just use your test mode API key. * * You can use any of the cards listed at https://stripe.com/docs/testing * for testing. * * Authentication: * * Authentication is by means of a single secret API key set as * the apiKey parameter when creating the gateway object. * * @see \Omnipay\Common\AbstractGateway * @see \Omnipay\Stripe\Message\AbstractRequest * @link https://stripe.com/docs/api */ class Gateway extends AbstractGateway { public function getName() { return 'Stripe'; } /** * Get the gateway parameters. * * @return array */ public function getDefaultParameters() { return array( 'apiKey' => '', ); } /** * Get the gateway API Key. * * Authentication is by means of a single secret API key set as * the apiKey parameter when creating the gateway object. * * @return string */ public function getApiKey() { return $this->getParameter('apiKey'); } /** * Set the gateway API Key. * * Authentication is by means of a single secret API key set as * the apiKey parameter when creating the gateway object. * * Stripe accounts have test-mode API keys as well as live-mode * API keys. These keys can be active at the same time. Data * created with test-mode credentials will never hit the credit * card networks and will never cost anyone money. * * Unlike some gateways, there is no test mode endpoint separate * to the live mode endpoint, the Stripe API endpoint is the same * for test and for live. * * Setting the testMode flag on this gateway has no effect. To * use test mode just use your test mode API key. * * @param string $value * * @return Gateway provides a fluent interface. */ public function setApiKey($value) { return $this->setParameter('apiKey', $value); } /** * Authorize Request. * * An Authorize request is similar to a purchase request but the * charge issues an authorization (or pre-authorization), and no money * is transferred. The transaction will need to be captured later * in order to effect payment. Uncaptured charges expire in 7 days. * * Either a customerReference or a card is required. If a customerReference * is passed in then the cardReference must be the reference of a card * assigned to the customer. Otherwise, if you do not pass a customer ID, * the card you provide must either be a token, like the ones returned by * Stripe.js, or a dictionary containing a user's credit card details. * * IN OTHER WORDS: You cannot just pass a card reference into this request, * you must also provide a customer reference if you want to use a stored * card. * * @param array $parameters * * @return \Omnipay\Stripe\Message\AuthorizeRequest */ public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\AuthorizeRequest', $parameters); } /** * Capture Request. * * Use this request to capture and process a previously created authorization. * * @param array $parameters * * @return \Omnipay\Stripe\Message\CaptureRequest */ public function capture(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\CaptureRequest', $parameters); } /** * Purchase request. * * To charge a credit card, you create a new charge object. If your API key * is in test mode, the supplied card won't actually be charged, though * everything else will occur as if in live mode. (Stripe assumes that the * charge would have completed successfully). * * Either a customerReference or a card is required. If a customerReference * is passed in then the cardReference must be the reference of a card * assigned to the customer. Otherwise, if you do not pass a customer ID, * the card you provide must either be a token, like the ones returned by * Stripe.js, or a dictionary containing a user's credit card details. * * IN OTHER WORDS: You cannot just pass a card reference into this request, * you must also provide a customer reference if you want to use a stored * card. * * @param array $parameters * * @return \Omnipay\Stripe\Message\PurchaseRequest */ public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\PurchaseRequest', $parameters); } /** * Refund Request. * * When you create a new refund, you must specify a * charge to create it on. * * Creating a new refund will refund a charge that has * previously been created but not yet refunded. Funds will * be refunded to the credit or debit card that was originally * charged. The fees you were originally charged are also * refunded. * * @param array $parameters * * @return \Omnipay\Stripe\Message\RefundRequest */ public function refund(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\RefundRequest', $parameters); } /** * Fetch Transaction Request. * * @param array $parameters * * @return \Omnipay\Stripe\Message\VoidRequest */ public function void(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\VoidRequest', $parameters); } /** * @param array $parameters * * @return \Omnipay\Stripe\Message\FetchTransactionRequest */ public function fetchTransaction(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\FetchTransactionRequest', $parameters); } /** * @param array $parameters * @return \Omnipay\Stripe\Message\FetchBalanceTransactionRequest */ public function fetchBalanceTransaction(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\FetchBalanceTransactionRequest', $parameters); } // // Cards // @link https://stripe.com/docs/api#cards // /** * Create Card. * * This call can be used to create a new customer or add a card * to an existing customer. If a customerReference is passed in then * a card is added to an existing customer. If there is no * customerReference passed in then a new customer is created. The * response in that case will then contain both a customer token * and a card token, and is essentially the same as CreateCustomerRequest * * @param array $parameters * * @return \Omnipay\Stripe\Message\CreateCardRequest */ public function createCard(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\CreateCardRequest', $parameters); } /** * Update Card. * * If you need to update only some card details, like the billing * address or expiration date, you can do so without having to re-enter * the full card details. Stripe also works directly with card networks * so that your customers can continue using your service without * interruption. * * When you update a card, Stripe will automatically validate the card. * * This requires both a customerReference and a cardReference. * * @link https://stripe.com/docs/api#update_card * * @param array $parameters * * @return \Omnipay\Stripe\Message\UpdateCardRequest */ public function updateCard(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\UpdateCardRequest', $parameters); } /** * Delete a card. * * This is normally used to delete a credit card from an existing * customer. * * You can delete cards from a customer or recipient. If you delete a * card that is currently the default card on a customer or recipient, * the most recently added card will be used as the new default. If you * delete the last remaining card on a customer or recipient, the * default_card attribute on the card's owner will become null. * * Note that for cards belonging to customers, you may want to prevent * customers on paid subscriptions from deleting all cards on file so * that there is at least one default card for the next invoice payment * attempt. * * In deference to the previous incarnation of this gateway, where * all CreateCard requests added a new customer and the customer ID * was used as the card ID, if a cardReference is passed in but no * customerReference then we assume that the cardReference is in fact * a customerReference and delete the customer. This might be * dangerous but it's the best way to ensure backwards compatibility. * * @param array $parameters * * @return \Omnipay\Stripe\Message\DeleteCardRequest */ public function deleteCard(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\DeleteCardRequest', $parameters); } // // Customers // link: https://stripe.com/docs/api#customers // /** * Create Customer. * * Customer objects allow you to perform recurring charges and * track multiple charges that are associated with the same customer. * The API allows you to create, delete, and update your customers. * You can retrieve individual customers as well as a list of all of * your customers. * * @param array $parameters * * @return \Omnipay\Stripe\Message\CreateCustomerRequest */ public function createCustomer(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\CreateCustomerRequest', $parameters); } /** * Update Customer. * * This request updates the specified customer by setting the values * of the parameters passed. Any parameters not provided will be left * unchanged. For example, if you pass the card parameter, that becomes * the customer's active card to be used for all charges in the future, * and the customer email address is updated to the email address * on the card. When you update a customer to a new valid card: for * each of the customer's current subscriptions, if the subscription * is in the `past_due` state, then the latest unpaid, unclosed * invoice for the subscription will be retried (note that this retry * will not count as an automatic retry, and will not affect the next * regularly scheduled payment for the invoice). (Note also that no * invoices pertaining to subscriptions in the `unpaid` state, or * invoices pertaining to canceled subscriptions, will be retried as * a result of updating the customer's card.) * * This request accepts mostly the same arguments as the customer * creation call. * * @param array $parameters * * @return \Omnipay\Stripe\Message\CreateCustomerRequest */ public function updateCustomer(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\UpdateCustomerRequest', $parameters); } /** * Delete a customer. * * Permanently deletes a customer. It cannot be undone. Also immediately * cancels any active subscriptions on the customer. * * @param array $parameters * * @return \Omnipay\Stripe\Message\DeleteCustomerRequest */ public function deleteCustomer(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\DeleteCustomerRequest', $parameters); } // // Tokens // @link https://stripe.com/docs/api#tokens // // This gateway does not currently have a CreateToken message. In // any case tokens are probably not what you are looking for because // they are single use. You probably want to create a Customer or // Card reference instead. This function is left here for further // expansion. // /** * Stripe Fetch Token Request. * * Often you want to be able to charge credit cards or send payments * to bank accounts without having to hold sensitive card information * on your own servers. Stripe.js makes this easy in the browser, but * you can use the same technique in other environments with our token API. * * Tokens can be created with your publishable API key, which can safely * be embedded in downloadable applications like iPhone and Android apps. * You can then use a token anywhere in our API that a card or bank account * is accepted. Note that tokens are not meant to be stored or used more * than once—to store these details for use later, you should create * Customer or Recipient objects. * * @param array $parameters * * @return \Omnipay\Stripe\Message\FetchTokenRequest */ public function fetchToken(array $parameters = array()) { return $this->createRequest('\Omnipay\Stripe\Message\FetchTokenRequest', $parameters); } } stripe/LICENSE 0000604 00000002047 15173176033 0007064 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. stripe/makedoc.sh 0000604 00000007565 15173176033 0010030 0 ustar 00 #!/bin/sh # # Smart little documentation generator. # GPL/LGPL # (c) Del 2015 http://www.babel.com.au/ # APPNAME='Omnipay Stripe Gateway Module' CMDFILE=apigen.cmd.$$ DESTDIR=./documents # # Find apigen, either in the path or as a local phar file # if [ -f apigen.phar ]; then APIGEN="php apigen.phar" else APIGEN=`which apigen` if [ ! -f "$APIGEN" ]; then # Search for phpdoc if apigen is not found. if [ -f phpDocumentor.phar ]; then PHPDOC="php phpDocumentor.phar" else PHPDOC=`which phpdoc` if [ ! -f "$PHPDOC" ]; then echo "Neither apigen nor phpdoc is installed in the path or locally, please install one of them" echo "see http://www.apigen.org/ or http://www.phpdoc.org/" exit 1 fi fi fi fi # # As of version 4 of apigen need to use the generate subcommand # if [ ! -z "$APIGEN" ]; then APIGEN="$APIGEN generate" fi # # Without any arguments this builds the entire system documentation, # making the cache file first if required. # if [ -z "$1" ]; then # # Check to see that the cache has been made. # if [ ! -f dirlist.cache ]; then echo "Making dirlist.cache file" $0 makecache fi # # Build the apigen/phpdoc command in a file. # if [ ! -z "$APIGEN" ]; then echo "$APIGEN --php --tree --title '$APPNAME API Documentation' --destination $DESTDIR/main \\" > $CMDFILE cat dirlist.cache | while read dir; do echo "--source $dir \\" >> $CMDFILE done echo "" >> $CMDFILE elif [ ! -z "$PHPDOC" ]; then echo "$PHPDOC --sourcecode --title '$APPNAME API Documentation' --target $DESTDIR/main --directory \\" > $CMDFILE cat dirlist.cache | while read dir; do echo "${dir},\\" >> $CMDFILE done echo "" >> $CMDFILE else "Neither apigen nor phpdoc are found, how did I get here?" exit 1 fi # # Run the apigen command # rm -rf $DESTDIR/main mkdir -p $DESTDIR/main . ./$CMDFILE /bin/rm -f ./$CMDFILE # # The "makecache" argument causes the script to just make the cache file # elif [ "$1" = "makecache" ]; then echo "Find application source directories" find src -name \*.php -print | \ ( while read file; do grep -q 'class' $file && dirname $file done ) | sort -u | \ grep -v -E 'config|docs|migrations|phpunit|test|Test|views|web' > dirlist.app echo "Find vendor source directories" find vendor -name \*.php -print | \ ( while read file; do grep -q 'class' $file && dirname $file done ) | sort -u | \ grep -v -E 'config|docs|migrations|phpunit|codesniffer|test|Test|views' > dirlist.vendor # # Filter out any vendor directories for which apigen fails # echo "Filter source directories" mkdir -p $DESTDIR/tmp cat dirlist.app dirlist.vendor | while read dir; do if [ ! -z "$APIGEN" ]; then $APIGEN --quiet --title "Test please ignore" \ --source $dir \ --destination $DESTDIR/tmp && ( echo "Including $dir" echo $dir >> dirlist.cache ) || ( echo "Excluding $dir" ) elif [ ! -z "$PHPDOC" ]; then $PHPDOC --quiet --title "Test please ignore" \ --directory $dir \ --target $DESTDIR/tmp && ( echo "Including $dir" echo $dir >> dirlist.cache ) || ( echo "Excluding $dir" ) fi done echo "Documentation cache dirlist.cache built OK" # # Clean up # /bin/rm -rf $DESTDIR/tmp fi stripe/phpunit.xml.dist 0000604 00000001512 15173176033 0011226 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> stripe/CONTRIBUTING.md 0000604 00000001040 15173176033 0010300 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. multisafepay/tests/Mock/RestFetchIssuersSuccess.txt 0000604 00000001124 15173176034 0016642 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 05 Feb 2016 09:18:54 GMT Server: Apache Vary: Accept-Encoding Content-Length: 214 Content-Type: application/json; charset=UTF-8; {"success":true,"data":[{"code":"0031","description":"ABN AMRO"},{"code":"0751","description":"SNS Bank"},{"code":"0721","description":"ING"},{"code":"0021","description":"Rabobank"},{"code":"0761","description":"ASN Bank"},{"code":"0771","description":"Regio Bank"},{"code":"0511","description":"Triodos Bank"},{"code":"0161","description":"Van Lanschot Bankiers"},{"code":"0801","description":"Knab"},{"code":4371,"description":"Bunq"}]} multisafepay/tests/Mock/RestFetchPaymentMethodsSuccess.txt 0000604 00000000663 15173176034 0020155 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 05 Feb 2016 10:25:42 GMT Server: Apache Vary: Accept-Encoding Content-Length: 52 Content-Type: application/json; charset=UTF-8; {"success":true,"data":[{"id":"BANKTRANS","description":"Wire Transfer"},{"id":"MAESTRO","description":"Maestro"},{"id":"VISA","description":"Visa"},{"id":"WALLET","description":"MultiSafepay"},{"id":"IDEAL","description":"iDEAL"},{"id":"MASTERCARD","description":"MasterCard"}]} multisafepay/tests/Mock/RestPurchaseSuccess.txt 0000604 00000000440 15173176034 0016005 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 05 Feb 2016 09:18:54 GMT Server: Apache Vary: Accept-Encoding Content-Length: 131 Content-Type: application/json; charset=UTF-8; {"success":true,"data":{"order_id":"TEST-TRANS-1","payment_url":"https:\/\/testpay.multisafepay.com\/pay\/?order_id=TEST-TRANS-1"}} multisafepay/tests/Mock/XmlFetchIssuersSuccess.txt 0000604 00000001743 15173176034 0016474 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 11 Jul 2013 13:21:39 GMT Server: Apache/2.2.16 (Debian) X-Powered-By: PHP/5.3.3-7+squeeze14 Vary: Accept-Encoding Content-Length: 810 Content-Type: text/xml <?xml version="1.0" encoding="UTF-8"?> <idealissuers result="ok"><issuers><issuer><code>0031</code><description>ABN AMRO</description></issuer><issuer><code>0751</code><description>SNS Bank</description></issuer><issuer><code>0721</code><description>ING</description></issuer><issuer><code>0021</code><description>Rabobank</description></issuer><issuer><code>0091</code><description>Friesland Bank</description></issuer><issuer><code>0761</code><description>ASN Bank</description></issuer><issuer><code>0771</code><description>SNS Regio Bank</description></issuer><issuer><code>0511</code><description>Triodos Bank</description></issuer><issuer><code>0161</code><description>Van Lanschot Bankiers</description></issuer><issuer><code>0801</code><description>Knab</description></issuer></issuers></idealissuers> multisafepay/tests/Mock/XmlCompletePurchaseSuccess.txt 0000604 00000002107 15173176034 0017323 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 11 Jul 2013 10:34:48 GMT Server: Apache/2.2.22 (FreeBSD) mod_ssl/2.2.22 OpenSSL/0.9.8q DAV/2 Content-Length: 931 Content-Type: text/xml <?xml version="1.0" encoding="UTF-8"?> <status result="ok"><ewallet><id>2087325</id><status>completed</status><fastcheckout>NO</fastcheckout><created>20130711123308</created><modified>20130711123317</modified><reasoncode/><reason/></ewallet><customer><amount>10000</amount><currency>EUR</currency><account/><locale>en_US</locale><firstname/><lastname/><address1/><address2/><housenumber/><zipcode/><city/><state/><country/><countryname/><phone1/><phone2/><email>tester@example.com</email></customer><customer-delivery/><transaction><id>123456</id><currency>EUR</currency><amount>10000</amount><description>desc</description><var1/><var2/><var3/><items/></transaction><paymentdetails><type>IDEAL</type><accountid>213698412</accountid><accountholdername>Hr E G H Küppers en/of Mw M J Küppers an nog een lange consumername</accountholdername><externaltransactionid>0050000075107095</externaltransactionid></paymentdetails></status> multisafepay/tests/Mock/XmlPurchaseSuccess.txt 0000604 00000000644 15173176034 0015636 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 11 Jul 2013 09:52:27 GMT Server: Apache/2.2.22 (FreeBSD) mod_ssl/2.2.22 OpenSSL/0.9.8q DAV/2 Content-Length: 256 Content-Type: text/xml <?xml version="1.0" encoding="UTF-8"?> <redirecttransaction result="ok"><transaction><id>123456</id><payment_url>https://testpay.multisafepay.com/pay/?transaction=1373536347Hz4sFtg7WgMulO5q123456&lang=</payment_url></transaction></redirecttransaction> multisafepay/tests/Mock/XmlFetchPaymentMethodsSuccess.txt 0000604 00000001204 15173176034 0017770 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 11 Jul 2013 12:31:26 GMT Server: Apache/2.2.16 (Debian) X-Powered-By: PHP/5.3.3-7+squeeze14 Vary: Accept-Encoding Content-Length: 459 Content-Type: text/xml <?xml version="1.0" encoding="UTF-8"?> <gateways result="ok"><gateways><gateway><id>VISA</id><description>Visa CreditCards</description></gateway><gateway><id>WALLET</id><description>MultiSafepay</description></gateway><gateway><id>IDEAL</id><description>iDEAL</description></gateway><gateway><id>BANKTRANS</id><description>Bank Transfer</description></gateway><gateway><id>MASTERCARD</id><description>MasterCard</description></gateway></gateways></gateways> multisafepay/tests/Mock/RestInvalidApiKeyFailure.txt 0000604 00000000350 15173176034 0016703 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 05 Feb 2016 10:11:02 GMT Server: Apache Vary: Accept-Encoding Content-Length: 95 Content-Type: application/json; charset=UTF-8; {"success":false,"data":{},"error_code":1032,"error_info":"Invalid API key"} multisafepay/tests/Mock/XmlFetchPaymentMethodsFailure.txt 0000604 00000000536 15173176034 0017756 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 11 Jul 2013 12:32:27 GMT Server: Apache/2.2.16 (Debian) X-Powered-By: PHP/5.3.3-7+squeeze14 Vary: Accept-Encoding Content-Length: 165 Content-Type: text/xml <?xml version="1.0" encoding="UTF-8"?> <gateways result="error"><error><code>1005</code><description>Invalid merchant security code</description></error></gateways> multisafepay/tests/Mock/XmlPurchaseFailure.txt 0000604 00000000571 15173176034 0015614 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 11 Jul 2013 10:06:38 GMT Server: Apache/2.2.22 (FreeBSD) mod_ssl/2.2.22 OpenSSL/0.9.8q DAV/2 Content-Length: 213 Content-Type: text/xml <?xml version="1.0" encoding="UTF-8"?> <redirecttransaction result="error"><error><code>1001</code><description>Invalid amount</description></error><transaction><id>123456</id></transaction></redirecttransaction> multisafepay/tests/Mock/RestPurchaseInvalidAmount.txt 0000604 00000000347 15173176034 0017155 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 05 Feb 2016 10:11:02 GMT Server: Apache Vary: Accept-Encoding Content-Length: 75 Content-Type: application/json; charset=UTF-8; {"success":false,"data":{},"error_code":1001,"error_info":"Invalid amount"} multisafepay/tests/Mock/XmlCompletePurchaseFailure.txt 0000604 00000000475 15173176034 0017310 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 11 Jul 2013 10:36:27 GMT Server: Apache/2.2.22 (FreeBSD) mod_ssl/2.2.22 OpenSSL/0.9.8q DAV/2 Content-Length: 153 Content-Type: text/xml <?xml version="1.0" encoding="UTF-8"?> <status result="error"><error><code>1016</code><description>Back-end: missing data</description></error></status> multisafepay/tests/Mock/RestFetchIssuersFailure.txt 0000604 00000000341 15173176034 0016621 0 ustar 00 HTTP/1.1 200 OK Date: Fri, 05 Feb 2016 10:11:02 GMT Server: Apache Vary: Accept-Encoding Content-Length: 88 Content-Type: application/json; charset=UTF-8; {"success":false,"data":{},"error_code":404,"error_info":"Not found"} multisafepay/tests/Mock/XmlFetchIssuersFailure.txt 0000604 00000000546 15173176034 0016453 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 11 Jul 2013 13:22:17 GMT Server: Apache/2.2.16 (Debian) X-Powered-By: PHP/5.3.3-7+squeeze14 Vary: Accept-Encoding Content-Length: 173 Content-Type: text/xml <?xml version="1.0" encoding="UTF-8"?> <idealissuers result="error"><error><code>1005</code><description>Invalid merchant security code</description></error></idealissuers> multisafepay/tests/RestGatewayTest.php 0000604 00000003076 15173176034 0014232 0 ustar 00 <?php namespace Omnipay\MultiSafepay; use Omnipay\Tests\GatewayTestCase; class RestGatewayTest extends GatewayTestCase { /** * @var Gateway */ protected $gateway; /** * @{inheritdoc} */ protected function setUp() { parent::setUp(); $this->gateway = new RestGateway( $this->getHttpClient(), $this->getHttpRequest() ); $this->gateway->setApiKey('123456789'); } public function testFetchPaymentMethodsRequest() { $request = $this->gateway->fetchPaymentMethods( array('country' => 'NL') ); $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestFetchPaymentMethodsRequest', $request); $this->assertEquals('NL', $request->getCountry()); } public function testFetchIssuersRequest() { $request = $this->gateway->fetchIssuers(); $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestFetchIssuersRequest', $request); } public function testPurchaseRequest() { $request = $this->gateway->purchase(array('amount' => 10.00)); $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestPurchaseRequest', $request); $this->assertEquals($request->getAmount(), 10.00); } public function testCompletePurchaseRequest() { $request = $this->gateway->completePurchase(array('amount' => 10.00)); $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestCompletePurchaseRequest', $request); $this->assertEquals($request->getAmount(), 10.00); } } multisafepay/tests/Message/RestPurchaseRequestTest.php 0000604 00000006502 15173176034 0017335 0 ustar 00 <?php namespace Omnipay\MultiSafepay\Message; use Omnipay\Tests\TestCase; class RestPurchaseRequestTest extends TestCase { /** * @var PurchaseRequest */ private $request; protected function setUp() { $this->request = new RestPurchaseRequest( $this->getHttpClient(), $this->getHttpRequest() ); $this->request->initialize( array( 'apiKey' => '123456789', 'amount' => 10.00, 'currency' => 'eur', 'description' => 'Test transaction', 'cancel_url' => 'http://localhost/cancel', 'notify_url' => 'http://localhost/notify', 'return_url' => 'http://localhost/return', 'close_window' => false, 'days_active' => 3, 'send_mail' => true, 'gateway' => 'IDEAL', 'google_analytics_code' => '123456789', 'manual' => false, 'transactionId' => 'TEST-TRANS-1', 'type' => 'redirect', 'var1' => 'extra data 1', 'var2' => 'extra data 2', 'var3' => 'extra data 3', ) ); } public function testSendSuccess() { $this->setMockHttpResponse('RestPurchaseSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertEquals( 'https://testpay.multisafepay.com/pay/?order_id=TEST-TRANS-1', $response->getRedirectUrl() ); $this->assertEquals('TEST-TRANS-1', $response->getTransactionId()); } public function testInvalidAmount() { $this->setMockHttpResponse('RestPurchaseInvalidAmount.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertEquals('Invalid amount', $response->getMessage()); $this->assertEquals(1001, $response->getCode()); } public function testDataIntegrity() { $this->assertEquals('123456789', $this->request->getGoogleAnalyticsCode()); $this->assertEquals('EUR', $this->request->getCurrency()); $this->assertEquals('extra data 1', $this->request->getVar1()); $this->assertEquals('extra data 2', $this->request->getVar2()); $this->assertEquals('extra data 3', $this->request->getVar3()); $this->assertEquals('http://localhost/cancel', $this->request->getCancelUrl()); $this->assertEquals('http://localhost/notify', $this->request->getNotifyUrl()); $this->assertEquals('http://localhost/return', $this->request->getReturnUrl()); $this->assertEquals('IDEAL', $this->request->getGateway()); $this->assertEquals('redirect', $this->request->getType()); $this->assertEquals('Test transaction', $this->request->getDescription()); $this->assertEquals('TEST-TRANS-1', $this->request->getTransactionId()); $this->assertEquals(10.00, $this->request->getAmount()); $this->assertEquals(3, $this->request->getDaysActive()); $this->assertFalse($this->request->getCloseWindow()); $this->assertFalse($this->request->getManual()); $this->assertTrue($this->request->getSendMail()); } } multisafepay/tests/Message/XmlFetchPaymentMethodsRequestTest.php 0000604 00000004747 15173176034 0021332 0 ustar 00 <?php namespace Omnipay\MultiSafepay\Message; use Omnipay\Tests\TestCase; class XmlFetchPaymentMethodsRequestTest extends TestCase { /** * @var FetchPaymentMethodsRequest */ private $request; protected function setUp() { $this->request = new FetchPaymentMethodsRequest( $this->getHttpClient(), $this->getHttpRequest() ); $this->request->initialize(array( 'accountId' => '111111', 'siteId' => '222222', 'siteCode' => '333333', 'country' => 'NL', )); } /** * @dataProvider paymentMethodsProvider */ public function testSendSuccess($expected) { $this->setMockHttpResponse('XmlFetchPaymentMethodsSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals($expected, $response->getPaymentMethods()); } public function testSendFailure() { $this->setMockHttpResponse('XmlFetchPaymentMethodsFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertEquals('Invalid merchant security code', $response->getMessage()); $this->assertEquals(1005, $response->getCode()); } /** * @dataProvider dataProvider */ public function testGetData($xml) { $data = $this->request->getData(); $this->assertInstanceOf('SimpleXMLElement', $data); // Just so the provider remains readable... $dom = dom_import_simplexml($data)->ownerDocument; $dom->formatOutput = true; $this->assertEquals($xml, $dom->saveXML()); } public function paymentMethodsProvider() { return array( array( array( 'VISA' => 'Visa CreditCards', 'WALLET' => 'MultiSafepay', 'IDEAL' => 'iDEAL', 'BANKTRANS' => 'Bank Transfer', 'MASTERCARD' => 'MasterCard', ), ), ); } public function dataProvider() { $xml = <<<EOF <?xml version="1.0" encoding="UTF-8"?> <gateways ua="Omnipay"> <merchant> <account>111111</account> <site_id>222222</site_id> <site_secure_code>333333</site_secure_code> </merchant> <customer> <country>NL</country> </customer> </gateways> EOF; return array( array($xml), ); } } multisafepay/tests/Message/XmlCompletePurchaseRequestTest.php 0000604 00000005764 15173176034 0020662 0 ustar 00 <?php namespace Omnipay\MultiSafepay\Message; use Omnipay\Tests\TestCase; class XmlCompletePurchaseRequestTest extends TestCase { /** * @var CompletePurchaseRequest */ private $request; protected function setUp() { $this->request = new CompletePurchaseRequest( $this->getHttpClient(), $this->getHttpRequest() ); $this->request->initialize(array( 'accountId' => '111111', 'siteId' => '222222', 'siteCode' => '333333', 'notifyUrl' => 'http://localhost/notify', 'cancelUrl' => 'http://localhost/cancel', 'returnUrl' => 'http://localhost/return', 'gateway' => 'IDEAL', 'issuer' => 'issuer', 'transactionId' => '123456', 'currency' => 'EUR', 'amount' => '100.00', 'description' => 'desc', 'extraData1' => 'extra 1', 'extraData2' => 'extra 2', 'extraData3' => 'extra 3', 'language' => 'a language', 'clientIp' => '127.0.0.1', 'googleAnalyticsCode' => 'analytics code', 'card' => array( 'email' => 'something@example.com', 'firstName' => 'first name', 'lastName' => 'last name', 'address1' => 'address 1', 'address2' => 'address 2', 'postcode' => '1000', 'city' => 'a city', 'country' => 'a country', 'phone' => 'phone number', ) )); } public function testSendSuccess() { $this->setMockHttpResponse('XmlCompletePurchaseSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('123456', $response->getTransactionReference()); } public function testSendFailure() { $this->setMockHttpResponse('XmlCompletePurchaseFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertEquals('Back-end: missing data', $response->getMessage()); $this->assertEquals(1016, $response->getCode()); } /** * @dataProvider dataProvider */ public function testGetData($xml) { $data = $this->request->getData(); $this->assertInstanceOf('SimpleXMLElement', $data); // Just so the provider remains readable... $dom = dom_import_simplexml($data)->ownerDocument; $dom->formatOutput = true; $this->assertEquals($xml, $dom->saveXML()); } public function dataProvider() { $xml = <<<EOF <?xml version="1.0" encoding="UTF-8"?> <status ua="Omnipay"> <merchant> <account>111111</account> <site_id>222222</site_id> <site_secure_code>333333</site_secure_code> </merchant> <transaction> <id>123456</id> </transaction> </status> EOF; return array( array($xml), ); } } multisafepay/tests/Message/XmlPurchaseRequestTest.php 0000604 00000021463 15173176034 0017163 0 ustar 00 <?php namespace Omnipay\MultiSafepay\Message; use Omnipay\Tests\TestCase; use ReflectionMethod; class XmlPurchaseRequestTest extends TestCase { /** * @var PurchaseRequest */ private $request; protected function setUp() { $this->request = new PurchaseRequest( $this->getHttpClient(), $this->getHttpRequest() ); $this->request->initialize(array( 'accountId' => '111111', 'siteId' => '222222', 'siteCode' => '333333', 'notifyUrl' => 'http://localhost/notify', 'cancelUrl' => 'http://localhost/cancel', 'returnUrl' => 'http://localhost/return', 'gateway' => 'IDEAL', 'issuer' => 'issuer', 'transactionId' => '123456', 'currency' => 'EUR', 'amount' => '100.00', 'description' => 'desc', 'extraData1' => 'extra 1', 'extraData2' => 'extra 2', 'extraData3' => 'extra 3', 'language' => 'a language', 'items' => array( array('name' => 'item 1', 'quantity' => 1), array('name' => 'item 2', 'quantity' => 2) ), 'clientIp' => '127.0.0.1', 'googleAnalyticsCode' => 'analytics code', 'card' => array( 'email' => 'something@example.com', 'firstName' => 'first name', 'lastName' => 'last name', 'address1' => 'address 1', 'address2' => 'address 2', 'postcode' => '1000', 'city' => 'a city', 'country' => 'a country', 'phone' => 'phone number', ) )); } public function testSendSuccess() { $this->setMockHttpResponse('XmlPurchaseSuccess.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertEquals( 'https://testpay.multisafepay.com/pay/?transaction=1373536347Hz4sFtg7WgMulO5q123456&lang=', $response->getRedirectUrl() ); $this->assertEquals('123456', $response->getTransactionReference()); } public function testSendFailure() { $this->setMockHttpResponse('XmlPurchaseFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertEquals('Invalid amount', $response->getMessage()); $this->assertEquals(1001, $response->getCode()); } /** * @dataProvider allDataProvider */ public function testGetData($xml) { $data = $this->request->getData(); $this->assertInstanceOf('SimpleXMLElement', $data); // Just so the provider remains readable... $dom = dom_import_simplexml($data)->ownerDocument; $dom->formatOutput = true; $this->assertEquals($xml, $dom->saveXML()); } /** * @dataProvider noIssuerDataProvider */ public function testGetDataWithNonIDEALGatewayDoesNotSetIssuer($xml) { $this->request->setGateway('another'); $data = $this->request->getData(); $this->assertInstanceOf('SimpleXMLElement', $data); // Just so the provider remains readable... $dom = dom_import_simplexml($data)->ownerDocument; $dom->formatOutput = true; $this->assertEquals($xml, $dom->saveXML()); } /** * @dataProvider specialCharsDataProvider */ public function testGetDataWithUrlsWithSpecialChars($xml) { $this->request->setReturnUrl('http://localhost/?one=1&two=2'); $this->request->setCancelUrl('http://localhost/?one=1&two=2'); $this->request->setNotifyUrl('http://localhost/?one=1&two=2'); $data = $this->request->getData(); $this->assertInstanceOf('SimpleXMLElement', $data); // Just so the provider remains readable... $dom = dom_import_simplexml($data)->ownerDocument; $dom->formatOutput = true; $this->assertEquals($xml, $dom->saveXML()); } /** * @covers \Omnipay\MultiSafepay\Message\PurchaseRequest::generateSignature() */ public function testGenerateSignature() { $method = new ReflectionMethod('\Omnipay\MultiSafepay\Message\PurchaseRequest', 'generateSignature'); $method->setAccessible(true); $signature = $method->invoke($this->request); $this->assertEquals('ad447bab87b8597853432c891e341db1', $signature); } public function allDataProvider() { $xml = <<<EOF <?xml version="1.0" encoding="UTF-8"?> <directtransaction ua="Omnipay"> <merchant> <account>111111</account> <site_id>222222</site_id> <site_secure_code>333333</site_secure_code> <notification_url>http://localhost/notify</notification_url> <cancel_url>http://localhost/cancel</cancel_url> <redirect_url>http://localhost/return</redirect_url> </merchant> <customer> <ipaddress>127.0.0.1</ipaddress> <locale>a language</locale> <email>something@example.com</email> <firstname>first name</firstname> <lastname>last name</lastname> <address1>address 1</address1> <address2>address 2</address2> <zipcode>1000</zipcode> <city>a city</city> <country>a country</country> <phone>phone number</phone> </customer> <google_analytics>analytics code</google_analytics> <transaction> <id>123456</id> <currency>EUR</currency> <amount>10000</amount> <description>desc</description> <var1>extra 1</var1> <var2>extra 2</var2> <var3>extra 3</var3> <gateway>IDEAL</gateway> <items><ul><li>1 x item 1</li><li>2 x item 2</li></ul></items> </transaction> <gatewayinfo> <issuerid>issuer</issuerid> </gatewayinfo> <signature>ad447bab87b8597853432c891e341db1</signature> </directtransaction> EOF; return array( array($xml), ); } public function noIssuerDataProvider() { $xml = <<<EOF <?xml version="1.0" encoding="UTF-8"?> <redirecttransaction ua="Omnipay"> <merchant> <account>111111</account> <site_id>222222</site_id> <site_secure_code>333333</site_secure_code> <notification_url>http://localhost/notify</notification_url> <cancel_url>http://localhost/cancel</cancel_url> <redirect_url>http://localhost/return</redirect_url> </merchant> <customer> <ipaddress>127.0.0.1</ipaddress> <locale>a language</locale> <email>something@example.com</email> <firstname>first name</firstname> <lastname>last name</lastname> <address1>address 1</address1> <address2>address 2</address2> <zipcode>1000</zipcode> <city>a city</city> <country>a country</country> <phone>phone number</phone> </customer> <google_analytics>analytics code</google_analytics> <transaction> <id>123456</id> <currency>EUR</currency> <amount>10000</amount> <description>desc</description> <var1>extra 1</var1> <var2>extra 2</var2> <var3>extra 3</var3> <gateway>another</gateway> <items><ul><li>1 x item 1</li><li>2 x item 2</li></ul></items> </transaction> <signature>ad447bab87b8597853432c891e341db1</signature> </redirecttransaction> EOF; return array( array($xml), ); } public function specialCharsDataProvider() { $xml = <<<EOF <?xml version="1.0" encoding="UTF-8"?> <directtransaction ua="Omnipay"> <merchant> <account>111111</account> <site_id>222222</site_id> <site_secure_code>333333</site_secure_code> <notification_url>http://localhost/?one=1&two=2</notification_url> <cancel_url>http://localhost/?one=1&two=2</cancel_url> <redirect_url>http://localhost/?one=1&two=2</redirect_url> </merchant> <customer> <ipaddress>127.0.0.1</ipaddress> <locale>a language</locale> <email>something@example.com</email> <firstname>first name</firstname> <lastname>last name</lastname> <address1>address 1</address1> <address2>address 2</address2> <zipcode>1000</zipcode> <city>a city</city> <country>a country</country> <phone>phone number</phone> </customer> <google_analytics>analytics code</google_analytics> <transaction> <id>123456</id> <currency>EUR</currency> <amount>10000</amount> <description>desc</description> <var1>extra 1</var1> <var2>extra 2</var2> <var3>extra 3</var3> <gateway>IDEAL</gateway> <items><ul><li>1 x item 1</li><li>2 x item 2</li></ul></items> </transaction> <gatewayinfo> <issuerid>issuer</issuerid> </gatewayinfo> <signature>ad447bab87b8597853432c891e341db1</signature> </directtransaction> EOF; return array( array($xml), ); } } multisafepay/tests/Message/RestFetchPaymentMethodsRequestTest.php 0000604 00000002137 15173176034 0021476 0 ustar 00 <?php namespace Omnipay\MultiSafepay\Message; use Omnipay\Tests\TestCase; class RestFetchPaymentMethodsRequestTest extends TestCase { /** * @var FetchPaymentMethodsRequest */ private $request; protected function setUp() { $this->request = new RestFetchPaymentMethodsRequest( $this->getHttpClient(), $this->getHttpRequest() ); $this->request->initialize( array( 'api_key' => '123456789', 'country' => 'NL' ) ); } public function testSendSuccess() { $this->setMockHttpResponse('RestFetchPaymentMethodsSuccess.txt'); $response = $this->request->send(); $paymentMethods = $response->getPaymentMethods(); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertInternalType('array', $paymentMethods); $this->assertContainsOnlyInstancesOf('Omnipay\Common\PaymentMethod', $paymentMethods); } } multisafepay/tests/Message/RestFetchIssuersRequestTest.php 0000604 00000003202 15173176034 0020164 0 ustar 00 <?php namespace Omnipay\MultiSafepay\Message; use Omnipay\Tests\TestCase; class RestFetchIssuersRequestTest extends TestCase { /** * @var FetchIssuersRequest */ private $request; protected function setUp() { $this->request = new RestFetchIssuersRequest( $this->getHttpClient(), $this->getHttpRequest() ); $this->request->initialize( array( 'api_key' => '123456789', 'paymentMethod' => 'IDEAL' ) ); } public function testSendSuccess() { $this->setMockHttpResponse('RestFetchIssuersSuccess.txt'); $response = $this->request->send(); $issuers = $response->getIssuers(); $this->assertContainsOnlyInstancesOf('Omnipay\Common\Issuer', $issuers); $this->assertFalse($response->isRedirect()); $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestFetchIssuersResponse', $response); $this->assertInternalType('array', $issuers); $this->assertNull($response->getTransactionReference()); $this->assertTrue($response->isSuccessful()); } public function testIssuerNotFound() { $this->setMockHttpResponse('RestFetchIssuersFailure.txt'); $response = $this->request->send(); $this->assertEquals('Not found', $response->getMessage()); $this->assertEquals(404, $response->getCode()); $this->assertFalse($response->isRedirect()); $this->assertFalse($response->isSuccessful()); $this->assertInstanceOf('Omnipay\MultiSafepay\Message\RestFetchIssuersResponse', $response); } } multisafepay/tests/Message/XmlAbstractRequestTest.php 0000604 00000002011 15173176034 0017140 0 ustar 00 <?php namespace Omnipay\MultiSafepay\Message; use Mockery as m; use Omnipay\Tests\TestCase; use ReflectionMethod; class XmlAbstractRequestTest extends TestCase { /** * @var AbstractRequest */ private $request; protected function setUp() { $this->request = m::mock('\Omnipay\MultiSafepay\Message\AbstractRequest')->makePartial(); } /** * @covers \Omnipay\MultiSafepay\Message\AbstractRequest::getHeaders() */ public function testUserAgentHeaderMustNotBeSet() { $method = new ReflectionMethod('\Omnipay\MultiSafepay\Message\AbstractRequest', 'getHeaders'); $method->setAccessible(true); $headers = $method->invoke($this->request); $this->assertArrayHasKey( 'User-Agent', $headers, 'Omitting User-Agent header not allowed because then Guzzle will set it and cause 403 Forbidden on the gateway' ); $this->assertEquals('Omnipay', $headers['User-Agent'], 'User-Agent header set'); } } multisafepay/tests/Message/XmlFetchIssuersRequestTest.php 0000604 00000005053 15173176034 0020015 0 ustar 00 <?php namespace Omnipay\MultiSafepay\Message; use Omnipay\Tests\TestCase; class XmlFetchIssuersRequestTest extends TestCase { /** * @var FetchIssuersRequest */ private $request; protected function setUp() { $this->request = new FetchIssuersRequest( $this->getHttpClient(), $this->getHttpRequest() ); $this->request->initialize(array( 'accountId' => '111111', 'siteId' => '222222', 'siteCode' => '333333', )); } /** * @dataProvider issuersProvider */ public function testSendSuccess($expected) { $this->setMockHttpResponse('XmlFetchIssuersSuccess.txt'); $response = $this->request->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals($expected, $response->getIssuers()); } public function testSendFailure() { $this->setMockHttpResponse('XmlFetchIssuersFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertEquals('Invalid merchant security code', $response->getMessage()); $this->assertEquals(1005, $response->getCode()); } /** * @dataProvider dataProvider */ public function testGetData($xml) { $data = $this->request->getData(); $this->assertInstanceOf('SimpleXMLElement', $data); // Just so the provider remains readable... $dom = dom_import_simplexml($data)->ownerDocument; $dom->formatOutput = true; $this->assertEquals($xml, $dom->saveXML()); } public function issuersProvider() { return array( array( array( '0031' => 'ABN AMRO', '0751' => 'SNS Bank', '0721' => 'ING', '0021' => 'Rabobank', '0091' => 'Friesland Bank', '0761' => 'ASN Bank', '0771' => 'SNS Regio Bank', '0511' => 'Triodos Bank', '0161' => 'Van Lanschot Bankiers', '0801' => 'Knab', ), ), ); } public function dataProvider() { $xml = <<<EOF <?xml version="1.0" encoding="UTF-8"?> <idealissuers ua="Omnipay"> <merchant> <account>111111</account> <site_id>222222</site_id> <site_secure_code>333333</site_secure_code> </merchant> </idealissuers> EOF; return array( array($xml), ); } } multisafepay/tests/XmlGatewayTest.php 0000604 00000014300 15173176034 0014045 0 ustar 00 <?php /** * MultiSafepay Xml Gateway Test. */ namespace Omnipay\MultiSafepay; use Omnipay\Common\CreditCard; use Omnipay\Tests\GatewayTestCase; /** * MultiSafepay Xml Gateway Test. */ class XmlGatewayTest extends GatewayTestCase { /** * @var Gateway */ protected $gateway; /** * @var array */ protected $options; /** * @{inheritdoc} */ protected function setUp() { parent::setUp(); $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); $this->gateway->setAccountId('111111'); $this->gateway->setSiteId('222222'); $this->gateway->setSiteCode('333333'); $this->options = array( 'notifyUrl' => 'http://localhost/notify', 'cancelUrl' => 'http://localhost/cancel', 'returnUrl' => 'http://localhost/return', 'gateway' => 'IDEAL', 'issuer' => 'issuer', 'transactionId' => '123456', 'currency' => 'EUR', 'amount' => '100.00', 'description' => 'desc', 'extraData1' => 'extra 1', 'extraData2' => 'extra 2', 'extraData3' => 'extra 3', 'language' => 'a language', 'clientIp' => '127.0.0.1', 'googleAnalyticsCode' => 'analytics code', 'card' => array( 'email' => 'something@example.com', 'firstName' => 'first name', 'lastName' => 'last name', 'address1' => 'address 1', 'address2' => 'address 2', 'postcode' => '1000', 'city' => 'a city', 'country' => 'a country', 'phone' => 'phone number', ) ); } public function testFetchPaymentMethods() { /** @var \Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest $request */ $request = $this->gateway->fetchPaymentMethods(array('country' => 'NL')); $this->assertInstanceOf('Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest', $request); $this->assertEquals('NL', $request->getCountry()); } public function testFetchIssuers() { /** @var \Omnipay\MultiSafepay\Message\FetchIssuersRequest $request */ $request = $this->gateway->fetchIssuers(); $this->assertInstanceOf('Omnipay\MultiSafepay\Message\FetchIssuersRequest', $request); } public function testPurchase() { /** @var \Omnipay\MultiSafepay\Message\PurchaseRequest $request */ $request = $this->gateway->purchase($this->options); /** @var CreditCard $card */ $card = $request->getCard(); $this->assertInstanceOf('Omnipay\MultiSafepay\Message\PurchaseRequest', $request); $this->assertSame('http://localhost/notify', $request->getNotifyUrl()); $this->assertSame('http://localhost/cancel', $request->getCancelUrl()); $this->assertSame('http://localhost/return', $request->getReturnUrl()); $this->assertSame('IDEAL', $request->getGateway()); $this->assertSame('issuer', $request->getIssuer()); $this->assertSame('123456', $request->getTransactionId()); $this->assertSame('EUR', $request->getCurrency()); $this->assertSame('100.00', $request->getAmount()); $this->assertSame('desc', $request->getDescription()); $this->assertSame('extra 1', $request->getExtraData1()); $this->assertSame('extra 2', $request->getExtraData2()); $this->assertSame('extra 3', $request->getExtraData3()); $this->assertSame('a language', $request->getLanguage()); $this->assertSame('analytics code', $request->getGoogleAnalyticsCode()); $this->assertSame('127.0.0.1', $request->getClientIp()); $this->assertSame('something@example.com', $card->getEmail()); $this->assertSame('first name', $card->getFirstName()); $this->assertSame('last name', $card->getLastName()); $this->assertSame('address 1', $card->getAddress1()); $this->assertSame('address 2', $card->getAddress2()); $this->assertSame('1000', $card->getPostcode()); $this->assertSame('a city', $card->getCity()); $this->assertSame('a country', $card->getCountry()); $this->assertSame('phone number', $card->getPhone()); } public function testCompletePurchase() { /** @var \Omnipay\MultiSafepay\Message\CompletePurchaseRequest $request */ $request = $this->gateway->completePurchase($this->options); /** @var CreditCard $card */ $card = $request->getCard(); $this->assertInstanceOf('Omnipay\MultiSafepay\Message\CompletePurchaseRequest', $request); $this->assertSame('http://localhost/notify', $request->getNotifyUrl()); $this->assertSame('http://localhost/cancel', $request->getCancelUrl()); $this->assertSame('http://localhost/return', $request->getReturnUrl()); $this->assertSame('IDEAL', $request->getGateway()); $this->assertSame('issuer', $request->getIssuer()); $this->assertSame('123456', $request->getTransactionId()); $this->assertSame('EUR', $request->getCurrency()); $this->assertSame('100.00', $request->getAmount()); $this->assertSame('desc', $request->getDescription()); $this->assertSame('extra 1', $request->getExtraData1()); $this->assertSame('extra 2', $request->getExtraData2()); $this->assertSame('extra 3', $request->getExtraData3()); $this->assertSame('a language', $request->getLanguage()); $this->assertSame('analytics code', $request->getGoogleAnalyticsCode()); $this->assertSame('127.0.0.1', $request->getClientIp()); $this->assertSame('something@example.com', $card->getEmail()); $this->assertSame('first name', $card->getFirstName()); $this->assertSame('last name', $card->getLastName()); $this->assertSame('address 1', $card->getAddress1()); $this->assertSame('address 2', $card->getAddress2()); $this->assertSame('1000', $card->getPostcode()); $this->assertSame('a city', $card->getCity()); $this->assertSame('a country', $card->getCountry()); $this->assertSame('phone number', $card->getPhone()); } } multisafepay/composer.json 0000604 00000001733 15173176034 0012000 0 ustar 00 { "name": "omnipay/multisafepay", "type": "library", "description": "MultiSafepay driver for the Omnipay payment processing library", "keywords": [ "gateway", "merchant", "multi safepay", "multisafepay", "omnipay", "pay", "payment" ], "homepage": "https://github.com/thephpleague/omnipay-multisafepay", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-multisafepay/contributors" } ], "autoload": { "psr-4": { "Omnipay\\MultiSafepay\\" : "src/" } }, "require": { "omnipay/common": "~2.0" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } multisafepay/phpunit.xml.dist 0000604 00000001512 15173176034 0012424 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> multisafepay/.gitignore 0000604 00000000060 15173176034 0011236 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml multisafepay/LICENSE 0000604 00000002047 15173176034 0010262 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. multisafepay/CONTRIBUTING.md 0000604 00000001040 15173176034 0011476 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. multisafepay/.travis.yml 0000604 00000000372 15173176034 0011365 0 ustar 00 language: php php: - 5.3 - 5.4 - 5.5 - 5.6 - hhvm matrix: allow_failures: - php: hhvm before_script: - composer install -n --dev --prefer-source script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text multisafepay/README.md 0000604 00000003660 15173176034 0010536 0 ustar 00 # Omnipay: MultiSafepay **MultiSafepay driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-multisafepay) [](https://packagist.org/packages/omnipay/multisafepay) [](https://packagist.org/packages/omnipay/multisafepay) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements MultiSafepay 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/multisafepay": "~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: * MultiSafepay_Rest * MultiSafepay_Xml (Deprecated) 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-multisafepay/issues), or better yet, fork the library and submit a pull request. multisafepay/src/RestGateway.php 0000604 00000016032 15173176034 0013013 0 ustar 00 <?php /** * MultiSafepay REST Api Gateway. */ namespace Omnipay\MultiSafepay; use Omnipay\Common\AbstractGateway; /** * MultiSafepay REST Api gateway. * * This class forms the gateway class for the MultiSafepay REST API. * * The MultiSafepay REST api is the latest version of their API and uses * HTTP verbs and a RESTful endpoint structure. The response payloads are * formatted as JSON and authentication happens via an api key within * the HTTP headers. * * ### Environments * * The MultiSafepay API support two different environments. A sandbox environment * which can be used for testing purposes. And a live environment for production processing. * * ### Sandbox environment * * The sandbox environment allows the user to test their implementation, transactions * will be created but no actual money will be involved. * * To use the sandbox environment the testMode parameter needs to be set on the gateway object. * This ensures that the sandbox endpoint will be used, instead of the production endpoint. * * ### Credentials * * Before you can use the API you need to register an account with MultiSafepay. * * To request access to the sandbox environment you need to register * at https://testmerchant.multisafepay.com/signup * * To request access to the live environment you need to register * at https://merchant.multisafepay.com/signup * * After you create your account, you can access the MultiSafepay dashboard which is located at * https://testmerchant.multisafepay.com or https://merchant.multisafepay.com depending * on the environment you use. * * To obtain an API key you first need to register your website with MultiSafepay. * This can be done within several steps: * * 1. Navigate to the create page: https://merchant.multisafepay.com/sites * 2. Fill out the required fields. * 3. Click save. * 4. You will be redirect to the site details page where you can find the API key. * * ### Initialize gateway * * <code> * // Create the gateway * $gateway = Omnipay::create('MultiSafepay_Rest'); * * // Initialise the gateway * $gateway->initialize(array( * 'apiKey' => 'API-KEY', * 'locale' => 'en', * 'testMode' => true, // Or false, when you want to use the production environment * )); * </code> * * ### Retrieve Payment Methods * * <code> * $request = $gateway->fetchPaymentMethods(); * $response = $request->send(); * $paymentMethods = $response->getPaymentMethods(); * </code> * * @link https://github.com/MultiSafepay/PHP * @link https://www.multisafepay.com/docs/getting-started/ * @link https://www.multisafepay.com/documentation/doc/API-Reference/ * @link https://www.multisafepay.com/documentation/doc/Step-by-Step/ * @link https://www.multisafepay.com/signup/ */ class RestGateway extends AbstractGateway { /** * @{inheritdoc} */ public function getName() { return 'MultiSafepay REST'; } /** * Get the gateway parameters * * @return array */ public function getDefaultParameters() { return array( 'apiKey' => '', 'locale' => 'en', 'testMode' => false, ); } /** * Get the locale. * * Optional ISO 639-1 language code which is used to specify a * a language used to display gateway information and other * messages in the responses. * * The default language is English. * * @return string */ public function getLocale() { return $this->getParameter('locale'); } /** * Set the locale. * * Optional ISO 639-1 language code which is used to specify a * a language used to display gateway information and other * messages in the responses. * * The default language is English. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setLocale($value) { return $this->setParameter('locale', $value); } /** * Get the gateway API Key * * Authentication is by means of a single secret API key set as * the apiKey parameter when creating the gateway object. * * @return string */ public function getApiKey() { return $this->getParameter('apiKey'); } /** * Set the gateway API Key * * Authentication is by means of a single secret API key set as * the apiKey parameter when creating the gateway object. * * @param string $value * @return RestGateway provides a fluent interface. */ public function setApiKey($value) { return $this->setParameter('apiKey', $value); } /** * Retrieve payment methods active on the given MultiSafepay * account. * * @param array $parameters * * @return \Omnipay\MultiSafepay\Message\RestFetchPaymentMethodsRequest */ public function fetchPaymentMethods(array $parameters = array()) { return $this->createRequest( 'Omnipay\MultiSafepay\Message\RestFetchPaymentMethodsRequest', $parameters ); } /** * Retrieve issuers for gateway. * * @param array $parameters * * @return \Omnipay\MultiSafepay\Message\RestFetchIssuersRequest */ public function fetchIssuers(array $parameters = array()) { return $this->createRequest( 'Omnipay\MultiSafepay\Message\RestFetchIssuersRequest', $parameters ); } /** * Retrieve transaction by the given identifier. * * @param array $parameters * @return \Omnipay\MultiSafepay\Message\RestFetchTransactionRequest */ public function fetchTransaction(array $parameters = array()) { return $this->createRequest( 'Omnipay\MultiSafepay\Message\RestFetchTransactionRequest', $parameters ); } /** * Create a refund. * * @param array $parameters * @return \Omnipay\MultiSafepay\Message\RestRefundRequest */ public function refund(array $parameters = array()) { return $this->createRequest( 'Omnipay\MultiSafepay\Message\RestRefundRequest', $parameters ); } /** * Create a purchase request. * * MultisafePay support different types of transactions, * such as iDEAL, Paypal and CreditCard payments. * * @param array $parameters * * @return \Omnipay\MultiSafepay\Message\RestPurchaseRequest */ public function purchase(array $parameters = array()) { return $this->createRequest( 'Omnipay\MultiSafepay\Message\RestPurchaseRequest', $parameters ); } /** * Complete a payment request. * * @param array $parameters * * @return \Omnipay\MultiSafepay\Message\RestCompletePurchaseRequest */ public function completePurchase(array $parameters = array()) { return $this->createRequest( 'Omnipay\MultiSafepay\Message\RestCompletePurchaseRequest', $parameters ); } } multisafepay/src/Gateway.php 0000604 00000000605 15173176034 0012154 0 ustar 00 <?php /** * MultiSafepay XML Api Gateway. */ namespace Omnipay\MultiSafepay; /** * MultiSafepay XML Api gateway. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. * * @link https://www.multisafepay.com/downloads/handleidingen/Handleiding_connect(ENG).pdf */ class Gateway extends XmlGateway { } multisafepay/src/XmlGateway.php 0000604 00000007367 15173176034 0012651 0 ustar 00 <?php /** * MultiSafepay XML Api Gateway. */ namespace Omnipay\MultiSafepay; use Omnipay\Common\AbstractGateway; /** * MultiSafepay XML Api gateway. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. * * * ### Initialize gateway * * <code> * // Create the gateway * $gateway = Omnipay::create('MultiSafepay_Xml'); * * // Initialise the gateway * $gateway->initialize(array( * 'apiKey' => 'API-KEY', * 'locale' => 'en', * 'testMode' => true, // Or false, when you want to use the production environment * )); * </code> * * @link https://www.multisafepay.com/downloads/handleidingen/Handleiding_connect(ENG).pdf */ class XmlGateway extends AbstractGateway { /** * {@inheritdoc} */ public function getName() { return 'MultiSafepay XML'; } /** * {@inheritdoc} */ public function getDefaultParameters() { return array( 'accountId' => '', 'siteId' => '', 'siteCode' => '', 'testMode' => false, ); } /** * Get the account identifier. * * @return mixed */ public function getAccountId() { return $this->getParameter('accountId'); } /** * Set the account identifier. * * @param $value * @return $this */ public function setAccountId($value) { return $this->setParameter('accountId', $value); } /** * Get the site identifier. * * @return mixed */ public function getSiteId() { return $this->getParameter('siteId'); } /** * Set the site identifier. * * @param $value * @return $this */ public function setSiteId($value) { return $this->setParameter('siteId', $value); } /** * Get the site code. * * @return mixed */ public function getSiteCode() { return $this->getParameter('siteCode'); } /** * Set the site code. * * @param $value * @return $this */ public function setSiteCode($value) { return $this->setParameter('siteCode', $value); } /** * Retrieve payment methods active on the given MultiSafepay * account. * * @param array $parameters * * @return \Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest */ public function fetchPaymentMethods(array $parameters = array()) { return $this->createRequest( '\Omnipay\MultiSafepay\Message\FetchPaymentMethodsRequest', $parameters ); } /** * Retrieve iDEAL issuers. * * @param array $parameters * * @return \Omnipay\MultiSafepay\Message\FetchIssuersRequest */ public function fetchIssuers(array $parameters = array()) { return $this->createRequest( '\Omnipay\MultiSafepay\Message\FetchIssuersRequest', $parameters ); } /** * Create Purchase request. * * @param array $parameters * * @return \Omnipay\MultiSafepay\Message\PurchaseRequest */ public function purchase(array $parameters = array()) { return $this->createRequest( '\Omnipay\MultiSafepay\Message\PurchaseRequest', $parameters ); } /** * Complete purchase request. * * @param array $parameters * * @return \Omnipay\MultiSafepay\Message\CompletePurchaseRequest */ public function completePurchase(array $parameters = array()) { return $this->createRequest( '\Omnipay\MultiSafepay\Message\CompletePurchaseRequest', $parameters ); } } multisafepay/src/Message/RestAbstractResponse.php 0000604 00000003413 15173176034 0016257 0 ustar 00 <?php /** * MultiSafepay Rest Api Abstract Response class. */ namespace Omnipay\MultiSafepay\Message; use Omnipay\Common\Message\AbstractResponse; /** * MultiSafepay Rest Api Abstract Response class. * * All Response classes within the Rest namespace * inheritance from this class. */ abstract class RestAbstractResponse extends AbstractResponse { /** * Is the response successful? * * @return boolean */ public function isSuccessful() { if (! isset($this->data['success'])) { return false; } return $this->data['success']; } /** * Response Message. * * @return null|string A response message from the payment gateway */ public function getMessage() { if (!$this->isSuccessful() && isset($this->data['error_info'])) { return $this->data['error_info']; } } /** * Response code. * * @return null|string A response code from the payment gateway */ public function getCode() { if (! $this->isSuccessful() && isset($this->data['error_code'])) { return $this->data['error_code']; } } /** * Gateway Reference. * * @return null|string A reference provided by the gateway to represent this transaction */ public function getTransactionReference() { if (isset($this->data['data']['transaction_id'])) { return $this->data['data']['transaction_id']; } } /** * Get the transaction ID as generated by the merchant website. * * @return string */ public function getTransactionId() { if (isset($this->data['data']['order_id'])) { return $this->data['data']['order_id']; } } } multisafepay/src/Message/FetchPaymentMethodsRequest.php 0000604 00000003374 15173176034 0017431 0 ustar 00 <?php /** * MultiSafepay XML Api Fetch Payment Methods Request. */ namespace Omnipay\MultiSafepay\Message; use SimpleXMLElement; /** * MultiSafepay XML Api Fetch Payment Methods Request. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. */ class FetchPaymentMethodsRequest extends AbstractRequest { /** * Get the country. * * @return mixed */ public function getCountry() { return $this->getParameter('country'); } /** * Set the country. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setCountry($value) { return $this->setParameter('country', $value); } /** * {@inheritdoc} */ public function getData() { $data = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><gateways/>'); $data->addAttribute('ua', $this->userAgent); $merchant = $data->addChild('merchant'); $merchant->addChild('account', $this->getAccountId()); $merchant->addChild('site_id', $this->getSiteId()); $merchant->addChild('site_secure_code', $this->getSiteCode()); $customer = $data->addChild('customer'); $customer->addChild('country', $this->getCountry()); return $data; } /** * {@inheritdoc} */ public function sendData($data) { $httpResponse = $this->httpClient->post( $this->getEndpoint(), $this->getHeaders(), $data->asXML() )->send(); $this->response = new FetchPaymentMethodsResponse( $this, $httpResponse->xml() ); return $this->response; } } multisafepay/src/Message/PurchaseResponse.php 0000604 00000003127 15173176034 0015432 0 ustar 00 <?php /** * MultiSafepay XML Api Purchase Response. */ namespace Omnipay\MultiSafepay\Message; use Omnipay\Common\Message\RedirectResponseInterface; /** * MultiSafepay XML Api Purchase Response. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. */ class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface { /** * {@inheritdoc} */ public function getTransactionReference() { if (isset($this->data->transaction->id)) { return (string)$this->data->transaction->id; } } /** * {@inheritdoc} */ public function isSuccessful() { return false; } /** * {@inheritdoc} */ public function isRedirect() { if (isset($this->data->transaction->payment_url) || isset($this->data->gatewayinfo->redirecturl) ) { return true; } return false; } /** * {@inheritdoc} */ public function getRedirectUrl() { if (isset($this->data->gatewayinfo->redirecturl)) { return (string)$this->data->gatewayinfo->redirecturl; } if (isset($this->data->transaction->payment_url)) { return (string) $this->data->transaction->payment_url; } return null; } /** * {@inheritdoc} */ public function getRedirectMethod() { return 'GET'; } /** * {@inheritdoc} */ public function getRedirectData() { return null; } } multisafepay/src/Message/RestRefundResponse.php 0000604 00000001754 15173176034 0015745 0 ustar 00 <?php /** * MultiSafepay Rest Api Refund Response. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepay Rest Api Refund Response. * * The MultiSafepay API support refunds, meaning you can refund any * transaction to the customer. The fund will be deducted * from the MultiSafepay balance. * * The API also support partial refunds which means that only a * part of the amount will be refunded. * * When a transaction has been refunded the status will change to * "refunded". When the transaction has only been partial refunded the * status will change to "partial_refunded". * * ### Example * * <code> * $request = $this->gateway->refund(); * * $request->setTransactionId('test-transaction'); * $request->setAmount('10.00'); * $request->setCurrency('eur'); * $request->setDescription('Test Refund'); * * $response = $request->send(); * var_dump($response->isSuccessful()); * </code> */ class RestRefundResponse extends RestAbstractResponse { } multisafepay/src/Message/RestFetchPaymentMethodsResponse.php 0000604 00000002562 15173176034 0020433 0 ustar 00 <?php /** * MultiSafepay Rest Api Fetch Payment Methods Response. */ namespace Omnipay\MultiSafepay\Message; use Omnipay\Common\Message\FetchPaymentMethodsResponseInterface; use Omnipay\Common\PaymentMethod; /** * MultiSafepay Rest Api Fetch Payment Methods Response. * * The MultiSafepay API supports multiple payment gateways, such as * iDEAL, Paypal or CreditCard. * * This response class will be returned when using the * RestFetchPaymentMethodsRequest. And provides a list of * all supported payment methods. * * ### Example * * <code> * $request = $gateway->fetchPaymentMethods(); * $response = $request->send(); * $paymentMethods = $response->getPaymentMethods(); * print_r($paymentMethods); * </code> */ class RestFetchPaymentMethodsResponse extends RestAbstractResponse implements FetchPaymentMethodsResponseInterface { /** * Get the returned list of payment methods. * * These represent separate payment methods which the user must choose between. * * @return \Omnipay\Common\PaymentMethod[] */ public function getPaymentMethods() { $paymentMethods = array(); foreach ($this->data['data'] as $method) { $paymentMethods[] = new PaymentMethod( $method['id'], $method['description'] ); } return $paymentMethods; } } multisafepay/src/Message/FetchIssuersResponse.php 0000604 00000001472 15173176034 0016270 0 ustar 00 <?php /** * MultiSafepay XML Api Fetch Issuers Response. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepay XML Api Fetch Issuers Response. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. */ class FetchIssuersResponse extends AbstractResponse { /** * {@inheritdoc} */ public function isSuccessful() { return isset($this->data->issuers); } /** * Return available issuers as an associative array. * * @return array */ public function getIssuers() { $result = array(); foreach ($this->data->issuers->issuer as $issuer) { $result[(string) $issuer->code] = (string) $issuer->description; } return $result; } } multisafepay/src/Message/RestCompletePurchaseResponse.php 0000604 00000001144 15173176034 0017756 0 ustar 00 <?php /** * MultiSafepay Rest Api Complete Purchase Response. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepay Rest Api Complete Purchase Response. * * * ### Example * * <code> * $transaction = $gateway->completePurchase(); * $transaction->setTransactionId($transactionId); * $response = $transaction->send(); * print_r($response->getData()); * </code> * */ class RestCompletePurchaseResponse extends RestFetchTransactionResponse { /** * {@inheritdoc} */ public function isSuccessful() { return $this->getPaymentStatus() == 'completed'; } } multisafepay/src/Message/FetchPaymentMethodsResponse.php 0000604 00000001544 15173176034 0017574 0 ustar 00 <?php /** * MultiSafepay XML Api Fetch Payment Methods Response. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepat XML Api Fetch Payment Methods Response. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. */ class FetchPaymentMethodsResponse extends AbstractResponse { /** * {@inheritdoc} */ public function isSuccessful() { return isset($this->data->gateways); } /** * Return available payment methods as an associative array. * * @return array */ public function getPaymentMethods() { $result = array(); foreach ($this->data->gateways->gateway as $gateway) { $result[(string) $gateway->id] = (string) $gateway->description; } return $result; } } multisafepay/src/Message/RestAbstractRequest.php 0000604 00000010344 15173176034 0016112 0 ustar 00 <?php /** * MultiSafepay Rest Api Abstract Request class. */ namespace Omnipay\MultiSafepay\Message; use Omnipay\Common\Message\AbstractRequest; use Guzzle\Common\Event; /** * MultiSafepay Rest API Abstract Request class. * * All Request classes prefixed by the Rest keyword * inheritance from this class. */ abstract class RestAbstractRequest extends AbstractRequest { /** * User Agent. * * This user agent will be sent with each API request. * * @var string */ protected $userAgent = 'Omnipay'; /** * Live API endpoint. * * This endpoint will be used when the test mode is disabled. * * @var string */ protected $liveEndpoint = 'https://api.multisafepay.com/v1/json'; /** * Test API endpoint. * * This endpoint will be used when the test mode is enabled. * * @var string */ protected $testEndpoint = 'https://testapi.multisafepay.com/v1/json'; /** * Get the locale. * * Optional ISO 639-1 language code which is used to specify a * a language used to display gateway information and other * messages in the responses. * * The default language is English. * * @return string */ public function getLocale() { return $this->getParameter('locale'); } /** * Set the locale. * * Optional ISO 639-1 language code which is used to specify a * a language used to display gateway information and other * messages in the responses. * * The default language is English. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setLocale($value) { return $this->setParameter('locale', $value); } /** * Get the gateway API Key * * Authentication is by means of a single secret API key set as * the apiKey parameter when creating the gateway object. * * @return string */ public function getApiKey() { return $this->getParameter('apiKey'); } /** * Set the gateway API Key * * Authentication is by means of a single secret API key set as * the apiKey parameter when creating the gateway object. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setApiKey($value) { return $this->setParameter('apiKey', $value); } /** * Get endpoint * * @return string */ public function getEndpoint() { if ($this->getTestMode()) { return $this->testEndpoint; } return $this->liveEndpoint; } /** * Get the raw data array for this message. The format of this varies from gateway to * gateway, but will usually be either an associative array, or a SimpleXMLElement. * * @return mixed * @throws \Omnipay\Common\Exception\InvalidRequestException */ public function getData() { $this->validate('apiKey'); } /** * Get headers. * * @return array */ protected function getHeaders() { return array( 'api_key' => $this->getApiKey(), 'User-Agent' => $this->userAgent, ); } /** * Execute the Guzzle request. * * @param $method * @param $endpoint * @param null $query * @param null $data * @return \Guzzle\Http\Message\Response */ protected function sendRequest($method, $endpoint, $query = null, $data = null) { $this->httpClient->getEventDispatcher()->addListener('request.error', function (Event $event) { $response = $event['response']; if ($response->isError()) { $event->stopPropagation(); } }); $httpRequest = $this->httpClient->createRequest( $method, $this->getEndpoint() . $endpoint, $this->getHeaders(), $data ); // Add query parameters if (is_array($query) && ! empty($query)) { foreach ($query as $itemKey => $itemValue) { $httpRequest->getQuery()->add($itemKey, $itemValue); } } return $httpRequest->send(); } } multisafepay/src/Message/CompletePurchaseResponse.php 0000604 00000004103 15173176034 0017116 0 ustar 00 <?php /** * MultiSafepay XML Api Complete Purchase Response. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepay XML Api Complete Purchase Response. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. */ class CompletePurchaseResponse extends AbstractResponse { /** * {@inheritdoc} */ public function isSuccessful() { return $this->getPaymentStatus() === 'completed'; } /** * {@inheritdoc} */ public function getTransactionReference() { if (isset($this->data->transaction->id)) { return (string) $this->data->transaction->id; } } /** * Is the payment created, but uncompleted? * * @return boolean */ public function isInitialized() { return $this->getPaymentStatus() === 'initialized'; } /** * Is the payment created, but not yet exempted (credit cards)? * * @return boolean */ public function isUncleared() { return $this->getPaymentStatus() === 'uncleared'; } /** * Is the payment canceled? * * @return boolean */ public function isCanceled() { return $this->getPaymentStatus() === 'canceled'; } /** * Is the payment rejected? * * @return boolean */ public function isRejected() { return $this->getPaymentStatus() === 'declined'; } /** * Is the payment refunded? * * @return boolean */ public function isRefunded() { return $this->getPaymentStatus() === 'refunded'; } /** * Is the payment expired? * * @return boolean */ public function isExpired() { return $this->getPaymentStatus() === 'expired'; } /** * Get raw payment status. * * @return null|string */ public function getPaymentStatus() { if (isset($this->data->ewallet->status)) { return (string)$this->data->ewallet->status; } } } multisafepay/src/Message/AbstractRequest.php 0000604 00000005047 15173176034 0015260 0 ustar 00 <?php /** * MultiSafepay Abstract XML Api Request. */ namespace Omnipay\MultiSafepay\Message; use Omnipay\Common\Message\AbstractRequest as BaseAbstractRequest; /** * Multisafepay Abstract XML Api Request. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. */ abstract class AbstractRequest extends BaseAbstractRequest { /** * User Agent. * * This user agent will be sent with each API request. * * @var string */ protected $userAgent = 'Omnipay'; /** * Live API endpoint. * * This endpoint will be used when the test mode is disabled. * * @var string */ protected $liveEndpoint = 'https://api.multisafepay.com/ewx/'; /** * Test API endpoint. * * This endpoint will be used when the test mode is enabled. * * @var string */ protected $testEndpoint = 'https://testapi.multisafepay.com/ewx/'; /** * Get the account identifier. * * @return mixed */ public function getAccountId() { return $this->getParameter('accountId'); } /** * Set the account identifier. * * @param $value * @return BaseAbstractRequest */ public function setAccountId($value) { return $this->setParameter('accountId', $value); } /** * Get the site identifier. * * @return mixed */ public function getSiteId() { return $this->getParameter('siteId'); } /** * Set the site identifier. * * @param $value * @return BaseAbstractRequest */ public function setSiteId($value) { return $this->setParameter('siteId', $value); } /** * Get the site code. * * @return mixed */ public function getSiteCode() { return $this->getParameter('siteCode'); } /** * Set the site code. * * @param $value * @return BaseAbstractRequest */ public function setSiteCode($value) { return $this->setParameter('siteCode', $value); } /** * Get the API endpoint. * * @return string */ public function getEndpoint() { if ($this->getTestMode()) { return $this->testEndpoint; } return $this->liveEndpoint; } /** * Get headers. * * @return array */ protected function getHeaders() { return array( 'User-Agent' => $this->userAgent, ); } } multisafepay/src/Message/RestRefundRequest.php 0000604 00000003762 15173176034 0015600 0 ustar 00 <?php /** * MultiSafepay Rest Api Refund Request. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepay Rest Api Refund Request. * * The MultiSafepay API support refunds, meaning you can refund any * transaction to the customer. The fund will be deducted * from the MultiSafepay balance. * * The API also support partial refunds which means that only a * part of the amount will be refunded. * * When a transaction has been refunded the status will change to * "refunded". When the transaction has only been partial refunded the * status will change to "partial_refunded". * * ### Example * * <code> * $request = $this->gateway->refund(); * * $request->setTransactionId('test-transaction'); * $request->setAmount('10.00'); * $request->setCurrency('eur'); * $request->setDescription('Test Refund'); * * $response = $request->send(); * var_dump($response->isSuccessful()); * </code> */ class RestRefundRequest extends RestAbstractRequest { /** * Get the required data for the API request. * * @return array * @throws \Omnipay\Common\Exception\InvalidRequestException */ public function getData() { parent::getData(); $this->validate('amount', 'currency', 'description', 'transactionId'); return array( 'amount' => $this->getAmountInteger(), 'currency' => $this->getCurrency(), 'description' => $this->getDescription(), 'id' => $this->getTransactionId(), 'type' => 'refund', ); } /** * Send the request with specified data * * @param mixed $data * @return RestRefundResponse */ public function sendData($data) { $httpResponse = $this->sendRequest( 'POST', '/orders/' . $data['id'] . '/refunds', $data ); $this->response = new RestRefundResponse( $this, $httpResponse ); return $this->response; } } multisafepay/src/Message/RestCompletePurchaseRequest.php 0000604 00000002347 15173176034 0017616 0 ustar 00 <?php /** * MultiSafepay Rest Api Complete Purchase Request. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepay Rest Api Complete Purchase Request. * * ### Example * * <code> * $transaction = $gateway->completePurchase(); * $transaction->setTransactionId($transactionId); * $response = $transaction->send(); * print_r($response->getData()); * </code> * */ class RestCompletePurchaseRequest extends RestFetchTransactionRequest { /** * Get the required data from the API request. * * @return array * @throws \Omnipay\Common\Exception\InvalidRequestException */ public function getData() { $this->validate('transactionId'); $transactionId = $this->getTransactionId(); return compact('transactionId'); } /** * Send the API request. * * @param mixed $data * @return RestCompletePurchaseResponse */ public function sendData($data) { $httpResponse = $this->sendRequest( 'get', '/orders/' . $data['transactionId'] ); $this->response = new RestCompletePurchaseResponse( $this, $httpResponse->json() ); return $this->response; } } multisafepay/src/Message/RestFetchIssuersRequest.php 0000604 00000002771 15173176034 0016763 0 ustar 00 <?php /** * MultiSafepay Rest Api Fetch Issuers Request. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepay Rest Api Fetch Issuers Request. * * Some payment providers require you to specify a issuer. * This request provides a list of all possible issuers * for the specified gateway. * * Currently IDEAL is the only provider which requires an issuer. * * <code> * $request = $gateway->fetchIssuers(); * $request->setPaymentMethod('IDEAL'); * $response = $request->send(); * $issuers = $response->getIssuers(); * print_r($issuers); * </code> * * @link https://www.multisafepay.com/documentation/doc/API-Reference */ class RestFetchIssuersRequest extends RestAbstractRequest { /** * Get the required data for the API request. * * @return array * @throws \Omnipay\Common\Exception\InvalidRequestException */ public function getData() { parent::getData(); $this->validate('paymentMethod'); $paymentMethod = $this->getPaymentMethod(); return compact('paymentMethod'); } /** * Execute the API request. * * @param mixed $data * @return FetchIssuersResponse */ public function sendData($data) { $httpResponse = $this->sendRequest( 'GET', '/issuers/' . $data['paymentMethod'] ); $this->response = new RestFetchIssuersResponse( $this, $httpResponse->json() ); return $this->response; } } multisafepay/src/Message/RestFetchIssuersResponse.php 0000604 00000002170 15173176034 0017122 0 ustar 00 <?php /** * MultiSafepay Rest Api Fetch Issuers Response. */ namespace Omnipay\MultiSafepay\Message; use Omnipay\Common\Issuer; use Omnipay\Common\Message\FetchIssuersResponseInterface; /** * MultiSafepay Rest Api Fetch Issuers Response. * * This response class will be returned when * using the RestFetchIssuersRequest. And provides a * list of all possible issuers for the specified gateway. * * ### Example * * <code> * $request = $gateway->fetchIssuers(); * $request->setPaymentMethod('IDEAL'); * $response = $request->send(); * $issuers = $response->getIssuers(); * print_r($issuers); * </code> */ class RestFetchIssuersResponse extends RestAbstractResponse implements FetchIssuersResponseInterface { /** * Return available issuers as an associative array. * * @return \Omnipay\Common\Issuer[] */ public function getIssuers() { $issuers = array(); foreach ($this->data['data'] as $issuer) { $issuers[] = new Issuer( $issuer['code'], $issuer['description'] ); } return $issuers; } } multisafepay/src/Message/RestPurchaseResponse.php 0000604 00000006455 15173176034 0016277 0 ustar 00 <?php /** * MultiSafepay Rest Api Purchase Response. */ namespace Omnipay\MultiSafepay\Message; use Omnipay\Common\Message\RedirectResponseInterface; /** * MultiSafepay Rest Api Purchase Response. * * The payment request allows the merchant to charge a customer. * * ### Redirect vs Direct Payments * * A redirect payment is the standard payment process. * During a redirect payment the consumer is redirected to * MultiSafepay's secure Hosted Payment Pages to enter their * payment details and is suitable for most scenarios. If you * prefer greater control over your checkout process you should * use direct payments. During a direct payment the consumer * does not need to visit MultiSafepay Hosted Payment Pages. * Instead your website collects the requirement payment details * and the consumer is redirect immediately to their chosen payment * provider. * * ### Create Card * * <code> * // Create a credit card object * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '4222222222222222', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'email' => 'customer@example.com', * 'address1' => '1 Scrubby Creek Road', * 'country' => 'AU', * 'city' => 'Scrubby Creek', * 'postalcode' => '4999', * 'state' => 'QLD', * )); * </code> * * ### Initialize a "redirect" payment. * * The customer will be redirected to the MultiSafepay website * where they need to enter their payment details. * * <code> * $request = $gateway->purchase(); * * $request->setAmount('20.00'); * $request->setTransactionId('TEST-TRANSACTION'); * $request->setDescription('Test transaction'); * * $request->setCurrency('EUR'); * $request->setType('redirect'); * * $response = $request->send(); * var_dump($response->getData()); * </code> * * ### Initialize a "direct" payment. * * The merchant website need to collect the payment details, so * the user can stay at the merchant website. * * <code> * $request = $gateway->purchase(); * * $request->setAmount('20.00'); * $request->setTransactionId('TEST-TRANSACTION'); * $request->setDescription('Test transaction'); * * $request->setCurrency('EUR'); * $request->setType('direct'); * $request->setCard($card); * * $request->setGateway('IDEAL'); * $request->setIssuer('ISSUER-ID'); // This ID can be found, with the RestFetchIssuersRequest. * * $response = $request->send(); * var_dump($response->getData()); * </code> */ class RestPurchaseResponse extends RestAbstractResponse implements RedirectResponseInterface { /** * {@inheritdoc} */ public function isRedirect() { return isset($this->data['data']['payment_url']); } /** * {@inheritdoc} */ public function getRedirectUrl() { if (! $this->isRedirect()) { return null; } return $this->data['data']['payment_url']; } /** * {@inheritdoc} */ public function getRedirectMethod() { return 'GET'; } /** * {@inheritdoc} */ public function getRedirectData() { return null; } } multisafepay/src/Message/RestFetchTransactionResponse.php 0000604 00000004313 15173176034 0017753 0 ustar 00 <?php /** * MultiSafepay Rest Api Fetch Transaction Response. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepay Rest Api Fetch Transaction Response. * * To get information about a previous processed transaction, MultiSafepay provides * the /orders/{order_id} resource. This resource can be used to query the details * about a specific transaction. * * <code> * // Fetch the transaction. * $transaction = $gateway->fetchTransaction(); * $transaction->setTransactionId($transactionId); * $response = $transaction->send(); * print_r($response->getData()); * </code> * * @link https://www.multisafepay.com/documentation/doc/API-Reference */ class RestFetchTransactionResponse extends RestAbstractResponse { /** * Is the payment created, but uncompleted? * * @return boolean */ public function isInitialized() { return $this->getPaymentStatus() == 'initialized'; } /** * Is the payment created, but not yet exempted (credit cards)? * * @return boolean */ public function isUncleared() { return $this->getPaymentStatus() == 'uncleared'; } /** * Is the payment canceled? * * @return boolean */ public function isCanceled() { return $this->getPaymentStatus() == 'canceled'; } /** * Is the payment rejected? * * @return boolean */ public function isDeclined() { return $this->getPaymentStatus() == 'declined'; } /** * Is the payment refunded? * * @return boolean */ public function isRefunded() { if ($this->getPaymentStatus() == 'refunded' || $this->getPaymentStatus() == 'chargedback' ) { return true; } return false; } /** * Is the payment expired? * * @return boolean */ public function isExpired() { return $this->getPaymentStatus() == 'expired'; } /** * Get raw payment status. * * @return null|string */ public function getPaymentStatus() { if (isset($this->data['data']['status'])) { return $this->data['data']['status']; } } } multisafepay/src/Message/CompletePurchaseRequest.php 0000604 00000002633 15173176034 0016756 0 ustar 00 <?php /** * MultiSafepay XML Api Complete Purchase Request. */ namespace Omnipay\MultiSafepay\Message; use SimpleXMLElement; /** * MultiSafepay XML Api Complete Purchase Request. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. */ class CompletePurchaseRequest extends PurchaseRequest { /** * {@inheritdoc} */ public function getData() { $this->validate('transactionId'); $data = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><status/>'); $data->addAttribute('ua', $this->userAgent); $merchant = $data->addChild('merchant'); $merchant->addChild('account', $this->getAccountId()); $merchant->addChild('site_id', $this->getSiteId()); $merchant->addChild('site_secure_code', $this->getSiteCode()); $transaction = $data->addChild('transaction'); $transaction->addChild('id', $this->getTransactionId()); return $data; } /** * {@inheritdoc} */ public function sendData($data) { $httpResponse = $this->httpClient->post( $this->getEndpoint(), $this->getHeaders(), $data->asXML() )->send(); $this->response = new CompletePurchaseResponse( $this, $httpResponse->xml() ); return $this->response; } } multisafepay/src/Message/PurchaseRequest.php 0000604 00000016631 15173176034 0015270 0 ustar 00 <?php /** * MultiSafepay XML Api Purchase Request. */ namespace Omnipay\MultiSafepay\Message; use Omnipay\Common\CreditCard; use SimpleXMLElement; /** * MultiSafepay XML Api Purchase Request. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. */ class PurchaseRequest extends AbstractRequest { /** * Get the language. * * @return mixed */ public function getLanguage() { return $this->getParameter('language'); } /** * Set the language. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setLanguage($value) { return $this->setParameter('language', $value); } /** * Get the gateway. * * @return mixed */ public function getGateway() { return $this->getParameter('gateway'); } /** * Set the gateway. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setGateway($value) { return $this->setParameter('gateway', $value); } /** * Get Issuer. * * @return mixed */ public function getIssuer() { return $this->getParameter('issuer'); } /** * Set issuer. * * @param string $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setIssuer($value) { return $this->setParameter('issuer', $value); } /** * Get the Google analytics code. * * @return mixed */ public function getGoogleAnalyticsCode() { return $this->getParameter('googleAnalyticsCode'); } /** * Set the Google analytics code. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setGoogleAnalyticsCode($value) { return $this->setParameter('googleAnalyticsCode', $value); } /** * Get the value of "extradata1" * * @return mixed */ public function getExtraData1() { return $this->getParameter('extraData1'); } /** * Set the value of "extradata1" * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setExtraData1($value) { return $this->setParameter('extraData1', $value); } /** * Get the value of "extradata2" * * @return mixed */ public function getExtraData2() { return $this->getParameter('extraData2'); } /** * Set the value of "extraData2 * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setExtraData2($value) { return $this->setParameter('extraData2', $value); } /** * Get the value of "extraData3" * * @return mixed */ public function getExtraData3() { return $this->getParameter('extraData3'); } /** * Set the value of "extraData3" * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setExtraData3($value) { return $this->setParameter('extraData3', $value); } /** * Get the items. * * @return mixed */ public function getItems() { return $this->getParameter('items'); } /** * Set the items. * * @param array|\Omnipay\Common\ItemBag $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setItems($value) { return $this->setParameter('items', $value); } /** * {@inheritdoc} */ public function getData() { $this->validate('transactionId', 'amount', 'currency', 'description', 'clientIp', 'card'); if ('IDEAL' === $this->getGateway() && $this->getIssuer()) { $data = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><directtransaction/>'); } else { $data = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><redirecttransaction/>'); } $data->addAttribute('ua', $this->userAgent); $merchant = $data->addChild('merchant'); $merchant->addChild('account', $this->getAccountId()); $merchant->addChild('site_id', $this->getSiteId()); $merchant->addChild('site_secure_code', $this->getSiteCode()); $merchant->addChild('notification_url', htmlspecialchars($this->getNotifyUrl())); $merchant->addChild('cancel_url', htmlspecialchars($this->getCancelUrl())); $merchant->addChild('redirect_url', htmlspecialchars($this->getReturnUrl())); /** @var CreditCard $card */ $card = $this->getCard(); $customer = $data->addChild('customer'); $customer->addChild('ipaddress', $this->getClientIp()); $customer->addChild('locale', $this->getLanguage()); $customer->addChild('email', $card->getEmail()); $customer->addChild('firstname', $card->getFirstName()); $customer->addChild('lastname', $card->getLastName()); $customer->addChild('address1', $card->getAddress1()); $customer->addChild('address2', $card->getAddress2()); $customer->addChild('zipcode', $card->getPostcode()); $customer->addChild('city', $card->getCity()); $customer->addChild('country', $card->getCountry()); $customer->addChild('phone', $card->getPhone()); $data->addChild('google_analytics', $this->getGoogleAnalyticsCode()); $transaction = $data->addChild('transaction'); $transaction->addChild('id', $this->getTransactionId()); $transaction->addChild('currency', $this->getCurrency()); $transaction->addChild('amount', $this->getAmountInteger()); $transaction->addChild('description', $this->getDescription()); $transaction->addChild('var1', $this->getExtraData1()); $transaction->addChild('var2', $this->getExtraData2()); $transaction->addChild('var3', $this->getExtraData3()); $transaction->addChild('gateway', $this->getGateway()); if ($items = $this->getItems()) { $itemsHtml = '<ul>'; foreach ($items as $item) { $itemsHtml .= "<li>{$item['quantity']} x {$item['name']}</li>"; } $itemsHtml .= '</ul>'; $transaction->addChild('items', htmlspecialchars($itemsHtml)); } if ('IDEAL' === $this->getGateway() && $this->getIssuer()) { $gatewayInfo = $data->addChild('gatewayinfo'); $gatewayInfo->addChild('issuerid', $this->getIssuer()); } $data->addChild('signature', $this->generateSignature()); return $data; } /** * {@inheritdoc} */ public function sendData($data) { $httpResponse = $this->httpClient->post( $this->getEndpoint(), $this->getHeaders(), $data->asXML() )->send(); $this->response = new PurchaseResponse( $this, $httpResponse->xml() ); return $this->response; } /** * Generate signature. * * @return string */ protected function generateSignature() { return md5( $this->getAmountInteger(). $this->getCurrency(). $this->getAccountId(). $this->getSiteId(). $this->getTransactionId() ); } } multisafepay/src/Message/FetchIssuersRequest.php 0000604 00000002355 15173176034 0016123 0 ustar 00 <?php /** * MultiSafepay XML Api Fetch Issuers Request. */ namespace Omnipay\MultiSafepay\Message; use SimpleXMLElement; /** * MultiSafepay XML Api Fetch Issuers Request. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. */ class FetchIssuersRequest extends AbstractRequest { /** * {@inheritdoc} */ public function getData() { $data = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?><idealissuers/>'); $data->addAttribute('ua', $this->userAgent); $merchant = $data->addChild('merchant'); $merchant->addChild('account', $this->getAccountId()); $merchant->addChild('site_id', $this->getSiteId()); $merchant->addChild('site_secure_code', $this->getSiteCode()); return $data; } /** * {@inheritdoc} */ public function sendData($data) { $httpResponse = $this->httpClient->post( $this->getEndpoint(), $this->getHeaders(), $data->asXML() )->send(); $this->response = new FetchIssuersResponse( $this, $httpResponse->xml() ); return $this->response; } } multisafepay/src/Message/RestFetchTransactionRequest.php 0000604 00000003071 15173176034 0017605 0 ustar 00 <?php /** * MultiSafepay Rest Api Fetch Transaction Request. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepay Rest Api Fetch Transaction Request. * * To get information about a previous processed transaction, MultiSafepay provides * the /orders/{order_id} resource. This resource can be used to query the details * about a specific transaction. * * <code> * // Fetch the transaction. * $transaction = $gateway->fetchTransaction(); * $transaction->setTransactionId($transactionId); * $response = $transaction->send(); * print_r($response->getData()); * </code> * * @link https://www.multisafepay.com/documentation/doc/API-Reference */ class RestFetchTransactionRequest extends RestAbstractRequest { /** * Get the required data which is needed * to execute the API request. * * @return array * @throws \Omnipay\Common\Exception\InvalidRequestException */ public function getData() { parent::getData(); $this->validate('transactionId'); $transactionId = $this->getTransactionId(); return compact('transactionId'); } /** * Execute the API request. * * @param mixed $data * @return RestFetchTransactionResponse */ public function sendData($data) { $httpResponse = $this->sendRequest( 'get', '/orders/' . $data['transactionId'] ); $this->response = new RestFetchTransactionResponse( $this, $httpResponse->json() ); return $this->response; } } multisafepay/src/Message/AbstractResponse.php 0000604 00000001513 15173176034 0015420 0 ustar 00 <?php /** * MultiSafepay Abstract XML Api Response. */ namespace Omnipay\MultiSafepay\Message; use Omnipay\Common\Message\AbstractResponse as BaseAbstractResponse; /** * MultiSafepay Abstract XML Api Response. * * @deprecated This API is deprecated and will be removed in * an upcoming version of this package. Please switch to the Rest API. */ abstract class AbstractResponse extends BaseAbstractResponse { /** * {@inheritdoc} */ public function getMessage() { if (isset($this->data->error)) { return (string) $this->data->error->description; } return null; } /** * {@inheritdoc} */ public function getCode() { if (isset($this->data->error)) { return (string) $this->data->error->code; } return null; } } multisafepay/src/Message/RestFetchPaymentMethodsRequest.php 0000604 00000003543 15173176034 0020265 0 ustar 00 <?php /** * MultiSafepay Rest Api Fetch Payments Methods Request. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepay Rest Api Fetch Payments Methods Request. * * The MultiSafepay API supports multiple payment gateways, such as * iDEAL, Paypal or CreditCard. This request provides a list * of all supported payment methods. * * ### Example * * <code> * $request = $gateway->fetchPaymentMethods(); * $response = $request->send(); * $paymentMethods = $response->getPaymentMethods(); * print_r($paymentMethods); * </code> * * @link https://www.multisafepay.com/documentation/doc/API-Reference */ class RestFetchPaymentMethodsRequest extends RestAbstractRequest { /** * Get the country. * * @return string|null */ public function getCountry() { return $this->getParameter('country'); } /** * Set the country. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setCountry($value) { return $this->setParameter('country', $value); } /** * Get the required data for the API request. * * @return array */ public function getData() { parent::getData(); $data = array( 'amount' => $this->getAmountInteger(), 'country' => $this->getCountry(), 'currency' => $this->getCurrency(), ); return array_filter($data); } /** * Execute the API request. * * @param mixed $data * @return RestFetchPaymentMethodsResponse */ public function sendData($data) { $httpResponse = $this->sendRequest('GET', '/gateways', $data); $this->response = new RestFetchPaymentMethodsResponse( $this, $httpResponse->json() ); return $this->response; } } multisafepay/src/Message/RestPurchaseRequest.php 0000604 00000034166 15173176034 0016131 0 ustar 00 <?php /** * MultiSafepay Rest Api Purchase Request. */ namespace Omnipay\MultiSafepay\Message; /** * MultiSafepay Rest Api Purchase Request. * * The payment request allows the merchant to charge a customer. * * ### Redirect vs Direct Payments * * A redirect payment is the standard payment process. * During a redirect payment the consumer is redirected to * MultiSafepay's secure Hosted Payment Pages to enter their * payment details and is suitable for most scenarios. If you * prefer greater control over your checkout process you should * use direct payments. During a direct payment the consumer * does not need to visit MultiSafepay Hosted Payment Pages. * Instead your website collects the requirement payment details * and the consumer is redirect immediately to their chosen payment * provider. * * ### Create Card * * <code> * // Create a credit card object * $card = new CreditCard(array( * 'firstName' => 'Example', * 'lastName' => 'Customer', * 'number' => '4222222222222222', * 'expiryMonth' => '01', * 'expiryYear' => '2020', * 'cvv' => '123', * 'email' => 'customer@example.com', * 'address1' => '1 Scrubby Creek Road', * 'country' => 'AU', * 'city' => 'Scrubby Creek', * 'postalcode' => '4999', * 'state' => 'QLD', * )); * </code> * * ### Initialize a "redirect" payment. * * The customer will be redirected to the MultiSafepay website * where they need to enter their payment details. * * <code> * $request = $gateway->purchase(); * * $request->setAmount('20.00'); * $request->setTransactionId('TEST-TRANSACTION'); * $request->setDescription('Test transaction'); * * $request->setCurrency('EUR'); * $request->setType('redirect'); * * $response = $request->send(); * var_dump($response->getData()); * </code> * * ### Initialize a "direct" payment. * * The merchant website need to collect the payment details, so * the user can stay at the merchant website. * * <code> * $request = $gateway->purchase(); * * $request->setAmount('20.00'); * $request->setTransactionId('TEST-TRANSACTION'); * $request->setDescription('Test transaction'); * * $request->setCurrency('EUR'); * $request->setType('direct'); * $request->setCard($card); * * $request->setGateway('IDEAL'); * $request->setIssuer('ISSUER-ID'); // This ID can be found, with the RestFetchIssuersRequest. * * $response = $request->send(); * var_dump($response->getData()); * </code> */ class RestPurchaseRequest extends RestAbstractRequest { /** * Get payment type. * * Specifies the payment flow for the checkout process. * * @return string */ public function getType() { return $this->getParameter('type'); } /** * Set payment type. * * Specifies the payment flow for the checkout process. * Possible values are 'redirect', 'direct' * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setType($value) { return $this->setParameter('type', $value); } /** * Get recurring Payment Id * * A previously stored identifier referring to a * payment method to be charged again. * * @return int|null */ public function getRecurringId() { return $this->getParameter('recurring_id'); } /** * Set recurring Payment Id * * A previously stored identifier referring to a * payment method to be charged again. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setRecurringId($value) { return $this->setParameter('recurring_id', $value); } /** * Get the gateway. * * The unique gateway id to immediately direct the customer to the payment method. * You retrieve these gateways using a gateway request. * * @return mixed */ public function getGateway() { return $this->getParameter('gateway'); } /** * Set the gateway. * * The unique gateway id to immediately direct the customer to the payment method. * You retrieve these gateways using a gateway request. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setGateway($value) { return $this->setParameter('gateway', $value); } /** * Get value of var1. * * A free variable for custom data to be stored and persisted. * * @return string|null */ public function getVar1() { return $this->getParameter('var1'); } /** * Set var1. * * A free optional variable for custom data to be stored and persisted. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setVar1($value) { return $this->setParameter('var1', $value); } /** * Get var2. * * A free variable for custom data to be stored and persisted. * * @return string|null */ public function getVar2() { return $this->getParameter('var2'); } /** * Set var2. * * A free variable for custom data to be stored and persisted. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setVar2($value) { return $this->setParameter('var2', $value); } /** * Get var3. * * A free variable for custom data to be stored and persisted. * * @return string|null */ public function getVar3() { return $this->getParameter('var3'); } /** * Set var3. * * A free variable for custom data to be stored and persisted. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setVar3($value) { return $this->setParameter('var3', $value); } /** * Get manual. * * If true this forces a credit card transaction to require manual * acceptance regardless of the outcome from fraud checks. * It is possible that a high risk transaction is still declined. * * @return boolean|null */ public function getManual() { return $this->getParameter('manual'); } /** * Set manual. * * If true this forces a credit card transaction to require manual * acceptance regardless of the outcome from fraud checks. * It is possible that a high risk transaction is still declined. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setManual($value) { return $this->setParameter('manual', $value); } /** * Get days active. * * The number of days the payment link will be active for. * When not specified the default will be 30 days. * * @return int|null */ public function getDaysActive() { return $this->getParameter('days_active'); } /** * Set days active. * * The number of days the payment link will be active for. * When not specified the default will be 30 days. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setDaysActive($value) { return $this->setParameter('days_active', $value); } /** * Get close window. * * Set to true if you will display the MultiSafepay payment * page in a new window and want it to close automatically * after the payment process has been completed. * * @return boolean|null */ public function getCloseWindow() { return $this->getParameter('close_window'); } /** * Set close window. * * Set to true if you will display the MultiSafepay payment * page in a new window and want it to close automatically * after the payment process has been completed. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setCloseWindow($value) { return $this->setParameter('close_window', $value); } /** * Send mail. * * True if you will send your own bank transfer payment instructions to * consumers and do not want MultiSafepay to do this. * * @return boolean */ public function getSendMail() { return $this->getParameter('disable_send_mail'); } /** * Send mail. * * True if you will send your own bank transfer payment instructions to * consumers and do not want MultiSafepay to do this. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setSendMail($value) { return $this->setParameter('disable_send_mail', $value); } /** * Google analytics code. * * Your Google Analytics Site Id. * This will be injected into the payment pages * so you can trigger custom events and track payment metrics. * * @return string|null */ public function getGoogleAnalyticsCode() { return $this->getParameter('google_analytics'); } /** * Google analytics code. * * Your Google Analytics Site Id. * This will be injected into the payment pages * so you can trigger custom events and track payment metrics. * * @param $value * @return \Omnipay\Common\Message\AbstractRequest */ public function setGoogleAnalyticsCode($value) { return $this->setParameter('google_analytics', $value); } /** * Get the payment options. * * @return array */ protected function getPaymentData() { $data = array( 'cancel_url' => $this->getCancelUrl(), 'close_window' => $this->getCloseWindow(), 'notify_url' => $this->getNotifyUrl(), 'return_url' => $this->getReturnUrl(), ); return array_filter($data); } /** * Customer information. * * This function returns all the provided * client related parameters. * * @return array */ public function getCustomerData() { $data = array( 'disable_send_mail' => $this->getSendMail(), 'locale' => $this->getLocale(), ); if (is_null($this->getCard())) { return array_filter($data); } $cardData = array( 'address_1' => $this->getCard()->getAddress1(), 'address_2' => $this->getCard()->getAddress2(), 'city' => $this->getCard()->getCity(), 'country' => $this->getCard()->getCountry(), 'email' => $this->getCard()->getEmail(), 'first_name' => $this->getCard()->getFirstName(), 'house_number' => $this->getCard()->getNumber(), 'last_name' => $this->getCard()->getLastName(), 'phone' => $this->getCard()->getPhone(), 'state' => $this->getCard()->getState(), 'zip_code' => $this->getCard()->getPostcode(), ); return array_filter( array_merge($data, $cardData) ); } /** * Get gateway data. * * @return array */ protected function getGatewayData() { $data = array( 'issuer_id' => $this->getIssuer(), ); return array_filter($data); } /** * Get the raw data array for this message. The format of this varies from gateway to * gateway, but will usually be either an associative array, or a SimpleXMLElement. * * @return array * @throws \Omnipay\Common\Exception\InvalidRequestException */ public function getData() { parent::getData(); $this->validate( 'amount', 'currency', 'description', 'transactionId', 'type' ); // Direct order. if ($this->getType() === 'direct') { $this->validate('gateway'); } // When the gateway is set to IDEAL, // the issuer parameter is required. if ( $this->getType() == 'direct' && $this->getGateway() == 'IDEAL' ) { $this->validate('issuer'); } $data = array( 'amount' => $this->getAmountInteger(), 'currency' => $this->getCurrency(), 'days_active' => $this->getDaysActive(), 'description' => $this->getDescription(), 'gateway' => $this->getGateway(), 'google_analytics' => $this->getGoogleAnalyticsCode(), 'items' => $this->getItems(), 'manual' => $this->getManual(), 'order_id' => $this->getTransactionId(), 'recurring_id' => $this->getRecurringId(), 'type' => $this->getType(), 'var1' => $this->getVar1(), 'var2' => $this->getVar2(), 'var3' => $this->getVar3(), ); $paymentData = $this->getPaymentData(); if (! empty($paymentData)) { $data['payment_options'] = $paymentData; } $customerData = $this->getCustomerData(); if (! empty($customerData)) { $data['customer'] = $customerData; } $gatewayData = $this->getGatewayData(); if (! empty($gatewayData)) { $data['gateway_info'] = $gatewayData; } return array_filter($data); } /** * Send the request with specified data * * @param mixed $data * @return RestPurchaseResponse */ public function sendData($data) { $httpResponse = $this->sendRequest('POST', '/orders', null, $data); $this->response = new RestPurchaseResponse( $this, $httpResponse->json() ); return $this->response; } } gocardless/phpunit.xml.dist 0000604 00000001512 15173176034 0012047 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> gocardless/CONTRIBUTING.md 0000604 00000001040 15173176034 0011121 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. gocardless/composer.json 0000604 00000001715 15173176034 0011423 0 ustar 00 { "name": "omnipay/gocardless", "type": "library", "description": "GoCardless driver for the Omnipay payment processing library", "keywords": [ "gateway", "go cardless", "gocardless", "merchant", "omnipay", "pay", "payment" ], "homepage": "https://github.com/thephpleague/omnipay-gocardless", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-gocardless/contributors" } ], "autoload": { "psr-4": { "Omnipay\\GoCardless\\" : "src/" } }, "require": { "omnipay/common": "~2.0" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } gocardless/src/Gateway.php 0000604 00000006501 15173176034 0011600 0 ustar 00 <?php namespace Omnipay\GoCardless; use Omnipay\Common\AbstractGateway; use Omnipay\GoCardless\Message\PurchaseRequest; use Omnipay\GoCardless\Message\CompletePurchaseRequest; /** * GoCardless Gateway * * @link https://sandbox.gocardless.com/docs */ class Gateway extends AbstractGateway { public function getName() { return 'GoCardless'; } public function getDefaultParameters() { return array( 'appId' => '', 'appSecret' => '', 'merchantId' => '', 'accessToken' => '', 'testMode' => false, ); } public function getAppId() { return $this->getParameter('appId'); } public function setAppId($value) { return $this->setParameter('appId', $value); } public function getAppSecret() { return $this->getParameter('appSecret'); } public function setAppSecret($value) { return $this->setParameter('appSecret', $value); } public function getMerchantId() { return $this->getParameter('merchantId'); } public function setMerchantId($value) { return $this->setParameter('merchantId', $value); } public function getAccessToken() { return $this->getParameter('accessToken'); } public function setAccessToken($value) { return $this->setParameter('accessToken', $value); } public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\GoCardless\Message\PurchaseRequest', $parameters); } public function completePurchase(array $parameters = array()) { return $this->createRequest('\Omnipay\GoCardless\Message\CompletePurchaseRequest', $parameters); } public function authorize(array $parameters = array()) { return $this->createRequest('\Omnipay\GoCardless\Message\AuthorizeRequest', $parameters); } public function completeAuthorize(array $parameters = array()) { return $this->createRequest('\Omnipay\GoCardless\Message\CompleteAuthorizeRequest', $parameters); } public function capture(array $parameters = array()) { return $this->createRequest('\Omnipay\GoCardless\Message\CaptureRequest', $parameters); } /** * Generate a query string for the data array (this is some kind of sick joke) * * @link https://github.com/gocardless/gocardless-php/blob/v0.3.3/lib/GoCardless/Utils.php#L39 */ public static function generateQueryString($data, &$pairs = array(), $namespace = null) { if (is_array($data)) { foreach ($data as $k => $v) { if (is_int($k)) { static::generateQueryString($v, $pairs, $namespace.'[]'); } else { static::generateQueryString($v, $pairs, $namespace !== null ? $namespace."[$k]" : $k); } } if ($namespace !== null) { return $pairs; } if (empty($pairs)) { return ''; } sort($pairs); $strs = array_map('implode', array_fill(0, count($pairs), '='), $pairs); return implode('&', $strs); } else { $pairs[] = array(rawurlencode($namespace), rawurlencode($data)); } } } gocardless/src/Message/CompletePurchaseRequest.php 0000604 00000003262 15173176034 0016400 0 ustar 00 <?php namespace Omnipay\GoCardless\Message; use Omnipay\Common\Exception\InvalidResponseException; use Omnipay\GoCardless\Gateway; /** * GoCardless Complete Purchase Request */ class CompletePurchaseRequest extends AbstractRequest { public function getData() { $data = array(); $data['resource_uri'] = $this->httpRequest->get('resource_uri'); $data['resource_id'] = $this->httpRequest->get('resource_id'); $data['resource_type'] = $this->httpRequest->get('resource_type'); if ($this->httpRequest->get('state')) { $data['state'] = $this->httpRequest->get('state'); } if ($this->generateSignature($data) !== $this->httpRequest->get('signature')) { throw new InvalidResponseException; } unset($data['resource_uri']); return $data; } public function sendData($data) { // don't throw exceptions for 4xx errors $this->httpClient->getEventDispatcher()->addListener( 'request.error', function ($event) { if ($event['response']->isClientError()) { $event->stopPropagation(); } } ); $httpRequest = $this->httpClient->post( $this->getEndpoint().'/api/v1/confirm', array('Accept' => 'application/json'), Gateway::generateQueryString($data) ); $httpResponse = $httpRequest->setAuth($this->getAppId(), $this->getAppSecret())->send(); return $this->response = new CompletePurchaseResponse( $this, $httpResponse->json(), $this->httpRequest->get('resource_id') ); } } gocardless/src/Message/AuthorizeResponse.php 0000604 00000001363 15173176034 0015255 0 ustar 00 <?php namespace Omnipay\GoCardless\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RedirectResponseInterface; use Omnipay\GoCardless\Gateway; class AuthorizeResponse extends AbstractResponse implements RedirectResponseInterface { public function isSuccessful() { return false; } public function isRedirect() { return true; } public function getRedirectUrl() { return $this->getRequest()->getEndpoint(). '/connect/pre_authorizations/new?'. Gateway::generateQueryString($this->data); } public function getRedirectMethod() { return 'GET'; } public function getRedirectData() { return null; } } gocardless/src/Message/AbstractRequest.php 0000604 00000006755 15173176034 0014712 0 ustar 00 <?php namespace Omnipay\GoCardless\Message; use Omnipay\GoCardless\Gateway; /** * GoCardless Abstract Request */ abstract class AbstractRequest extends \Omnipay\Common\Message\AbstractRequest { protected $liveEndpoint = 'https://gocardless.com'; protected $testEndpoint = 'https://sandbox.gocardless.com'; public function getAppId() { return $this->getParameter('appId'); } public function setAppId($value) { return $this->setParameter('appId', $value); } public function getAppSecret() { return $this->getParameter('appSecret'); } public function setAppSecret($value) { return $this->setParameter('appSecret', $value); } public function getMerchantId() { return $this->getParameter('merchantId'); } public function setMerchantId($value) { return $this->setParameter('merchantId', $value); } public function getAccessToken() { return $this->getParameter('accessToken'); } public function setAccessToken($value) { return $this->setParameter('accessToken', $value); } public function getChargeCustomerAt() { return $this->getParameter('chargeCustomerAt'); } public function setChargeCustomerAt($value) { return $this->setParameter('chargeCustomerAt', $value); } public function getState() { return $this->getParameter('state'); } public function setState($value) { return $this->setParameter('state', $value); } public function getIntervalLength() { return $this->getParameter('intervalLength'); } public function setIntervalLength($value) { return $this->setParameter('intervalLength', $value); } public function getIntervalUnit() { return $this->getParameter('intervalUnit'); } public function setIntervalUnit($value) { return $this->setParameter('intervalUnit', $value); } public function getCalendarInterval() { return $this->getParameter('calendarInterval'); } public function setCalendarInterval($value) { return $this->setParameter('calendarInterval', $value); } public function getSetupFee() { return $this->getParameter('setupFee'); } public function setSetupFee($value) { return $this->setParameter('setupFee', $value); } public function getPreAuthExpire() { return $this->getParameter('preAuthExpire'); } public function setPreAuthExpire($value) { return $this->setParameter('preAuthExpire', $value); } public function getIntervalCount() { return $this->getParameter('intervalCount'); } public function setIntervalCount($value) { return $this->setParameter('intervalCount', $value); } /** * Generate a signature for the data array */ public function generateSignature($data) { return hash_hmac('sha256', Gateway::generateQueryString($data), $this->getAppSecret()); } public function getEndpoint() { return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; } /** * Generate a nonce for each request */ protected function generateNonce() { $nonce = ''; for ($i = 0; $i < 64; $i++) { // append random ASCII character $nonce .= chr(mt_rand(33, 126)); } return base64_encode($nonce); } } gocardless/src/Message/CompletePurchaseResponse.php 0000604 00000001476 15173176034 0016553 0 ustar 00 <?php namespace Omnipay\GoCardless\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RequestInterface; /** * GoCardless Complete Purchase Response */ class CompletePurchaseResponse extends AbstractResponse { protected $transactionReference; public function __construct(RequestInterface $request, $data, $transactionReference) { parent::__construct($request, $data); $this->transactionReference = $transactionReference; } public function isSuccessful() { return !isset($this->data['error']); } public function getTransactionReference() { return $this->transactionReference; } public function getMessage() { if (!$this->isSuccessful()) { return reset($this->data['error']); } } } gocardless/src/Message/CompleteAuthorizeRequest.php 0000604 00000003166 15173176034 0016603 0 ustar 00 <?php /** * GoCardless Complete Authorize Request */ namespace Omnipay\GoCardless\Message; use Omnipay\Common\Exception\InvalidResponseException; use Omnipay\GoCardless\Gateway; /** * This completes and confirms that the auth is going to be used. It has a 3 hour * life from the moment we create the pre-auth request. * * * @package Omnipay\GoCardless\Message * @link https://developer.gocardless.com/#confirm-a-new-pre-auth */ class CompleteAuthorizeRequest extends AbstractRequest { public function getData() { $data = array(); $data['resource_uri'] = $this->httpRequest->get('resource_uri'); $data['resource_id'] = $this->httpRequest->get('resource_id'); $data['resource_type'] = $this->httpRequest->get('resource_type'); if ($this->httpRequest->get('state')) { $data['state'] = $this->httpRequest->get('state'); } if ($this->generateSignature($data) !== $this->httpRequest->get('signature')) { throw new InvalidResponseException; } unset($data['resource_uri']); return $data; } public function sendData($data) { $httpRequest = $this->httpClient->post( $this->getEndpoint().'/api/v1/confirm', array('Accept' => 'application/json'), Gateway::generateQueryString($data) ); $httpResponse = $httpRequest->setAuth($this->getAppId(), $this->getAppSecret())->send(); return $this->response = new CompleteAuthorizeResponse( $this, $httpResponse->json(), $this->httpRequest->get('resource_id') ); } } gocardless/src/Message/PurchaseResponse.php 0000604 00000001363 15173176034 0015055 0 ustar 00 <?php namespace Omnipay\GoCardless\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RedirectResponseInterface; use Omnipay\GoCardless\Gateway; /** * GoCardless Purchase Response */ class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface { public function isSuccessful() { return false; } public function isRedirect() { return true; } public function getRedirectUrl() { return $this->getRequest()->getEndpoint().'/connect/bills/new?'.Gateway::generateQueryString($this->data); } public function getRedirectMethod() { return 'GET'; } public function getRedirectData() { return null; } } gocardless/src/Message/CaptureRequest.php 0000604 00000002714 15173176034 0014541 0 ustar 00 <?php /** * GoCardless Capture Request */ namespace Omnipay\GoCardless\Message; use Omnipay\GoCardless\Gateway; /** * GoCardless Capture Request - this captures an existing pre-authorization. * * All you need for this method is the pre_authorization_id that we expect to be the transactionReference. * This is a very similar call to just creating a standard bill - but doesnt require a hand off to the * payment provider. * * @see AuthorizeRequest * @link https://developer.gocardless.com/#create-a-bill-under-a-pre-auth */ class CaptureRequest extends AbstractRequest { public function getData() { $this->validate('amount', 'transactionReference'); $data = array(); $bill = array(); $bill['amount'] = $this->getAmount(); $bill['pre_authorization_id'] = $this->getTransactionReference(); $bill['name'] = $this->getDescription(); $bill['charge_customer_at'] = $this->getChargeCustomerAt(); $data['bill'] = $bill; return $data; } public function sendData($data) { $httpRequest = $this->httpClient->post( $this->getEndpoint().'/api/v1/bills', array('Accept' => 'application/json'), Gateway::generateQueryString($data) ); $httpResponse = $httpRequest->setHeader('Authorization', 'bearer '.$this->getAccessToken())->send(); return $this->response = new CaptureResponse($this, $httpResponse->json()); } } gocardless/src/Message/AuthorizeRequest.php 0000604 00000006511 15173176034 0015107 0 ustar 00 <?php /** * GoCardless Authorize Request */ namespace Omnipay\GoCardless\Message; /** * GoCardless Authorize Request * * Use this method to create a pre- authorization for a charge. Because we are dealing with direct debits we can do * a few things that other providers don't or can't do. It also means we some extra parameters. * * Required parameters: * - amount - we're using this as the max_amount for the authorization, * you have the ability to capture less then this later * - intervalLength - the number of intervalUnits that make up an interval (1 month) would be monthly charge * - intervalUnit - string of `day` `week` or `month` * * Optional Parameters: * see documentation. * * * @see \Omnipay\GoCardless\Gateway * @link https://developer.gocardless.com/#create-a-pre-auth */ class AuthorizeRequest extends AbstractRequest { public function getData() { $this->validate('amount', 'intervalLength', 'intervalUnit'); $data = array(); //Required Items from the API $data['client_id'] = $this->getAppId(); $data['nonce'] = $this->generateNonce(); $data['timestamp'] = gmdate('Y-m-d\TH:i:s\Z'); $data['pre_authorization']['max_amount'] = $this->getAmount(); $data['pre_authorization']['interval_length'] = $this->getIntervalLength(); $data['pre_authorization']['interval_unit'] = $this->getIntervalUnit(); $data['pre_authorization']['merchant_id'] = $this->getMerchantId(); $data['redirect_uri'] = $this->getReturnUrl(); //Nice to haves. if ($this->getCancelUrl()) { $data['cancel_uri'] = $this->getCancelUrl(); } if ($this->getState()) { $data['state'] = $this->getState(); } if ($this->getDescription()) { $data['name'] = $this->getDescription(); } if ($this->getCalendarInterval()) { $data['pre_authorization']['calendar_intervals'] = $this->getCalendarInterval(); } if ($this->getSetupFee()) { $data['pre_authorization']['setup_fee'] = $this->getSetupFee(); } if ($this->getIntervalCount()) { $data['pre_authorization']['interval_count'] = $this->getIntervalCount(); } if ($this->getPreAuthExpire()) { $data['pre_authorization']['expires_at'] = $this->getPreAuthExpire(); } if ($this->getCard()) { $data['bill']['user'] = array(); $data['bill']['user']['first_name'] = $this->getCard()->getFirstName(); $data['bill']['user']['last_name'] = $this->getCard()->getLastName(); $data['bill']['user']['email'] = $this->getCard()->getEmail(); $data['bill']['user']['billing_address1'] = $this->getCard()->getAddress1(); $data['bill']['user']['billing_address2'] = $this->getCard()->getAddress2(); $data['bill']['user']['billing_town'] = $this->getCard()->getCity(); $data['bill']['user']['billing_county'] = $this->getCard()->getCountry(); $data['bill']['user']['billing_postcode'] = $this->getCard()->getPostcode(); } $data['signature'] = $this->generateSignature($data); return $data; } public function sendData($data) { return $this->response = new AuthorizeResponse($this, $data); } } gocardless/src/Message/PurchaseRequest.php 0000604 00000003264 15173176034 0014711 0 ustar 00 <?php namespace Omnipay\GoCardless\Message; /** * GoCardless Purchase Request */ class PurchaseRequest extends AbstractRequest { public function getData() { $this->validate('amount'); $data = array(); $data['client_id'] = $this->getAppId(); $data['nonce'] = $this->generateNonce(); $data['timestamp'] = gmdate('Y-m-d\TH:i:s\Z'); $data['redirect_uri'] = $this->getReturnUrl(); $data['cancel_uri'] = $this->getCancelUrl(); $data['state'] = $this->getState(); $data['bill'] = array(); $data['bill']['merchant_id'] = $this->getMerchantId(); $data['bill']['amount'] = $this->getAmount(); $data['bill']['name'] = $this->getDescription(); if ($this->getCard()) { $data['bill']['user'] = array(); $data['bill']['user']['first_name'] = $this->getCard()->getFirstName(); $data['bill']['user']['last_name'] = $this->getCard()->getLastName(); $data['bill']['user']['email'] = $this->getCard()->getEmail(); $data['bill']['user']['billing_address1'] = $this->getCard()->getAddress1(); $data['bill']['user']['billing_address2'] = $this->getCard()->getAddress2(); $data['bill']['user']['billing_town'] = $this->getCard()->getCity(); $data['bill']['user']['billing_county'] = $this->getCard()->getCountry(); $data['bill']['user']['billing_postcode'] = $this->getCard()->getPostcode(); } $data['signature'] = $this->generateSignature($data); return $data; } public function sendData($data) { return $this->response = new PurchaseResponse($this, $data); } } gocardless/src/Message/CaptureResponse.php 0000604 00000000675 15173176034 0014713 0 ustar 00 <?php namespace Omnipay\GoCardless\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RequestInterface; class CaptureResponse extends AbstractResponse { public function isSuccessful() { return !isset($this->data['error']); } public function getMessage() { if (!$this->isSuccessful()) { return reset($this->data['error']); } return null; } } gocardless/src/Message/CompleteAuthorizeResponse.php 0000604 00000001443 15173176034 0016745 0 ustar 00 <?php namespace Omnipay\GoCardless\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RequestInterface; class CompleteAuthorizeResponse extends AbstractResponse { protected $transactionReference; public function __construct(RequestInterface $request, $data, $transactionReference) { parent::__construct($request, $data); $this->transactionReference = $transactionReference; } public function isSuccessful() { return !isset($this->data['error']); } public function getTransactionReference() { return $this->transactionReference; } public function getMessage() { if (!$this->isSuccessful()) { return reset($this->data['error']); } return null; } } gocardless/README.md 0000604 00000003563 15173176034 0010163 0 ustar 00 # Omnipay: GoCardless **GoCardless driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-gocardless) [](https://packagist.org/packages/omnipay/gocardless) [](https://packagist.org/packages/omnipay/gocardless) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements GoCardless 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/gocardless": "~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: * GoCardless 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-gocardless/issues), or better yet, fork the library and submit a pull request. gocardless/.gitignore 0000604 00000000060 15173176034 0010661 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml gocardless/tests/Message/CompletePurchaseResponseTest.php 0000604 00000002017 15173176034 0017756 0 ustar 00 <?php namespace Omnipay\GoCardless\Message; use Omnipay\Tests\TestCase; class CompletePurchaseResponseTest extends TestCase { public function testCompletePurchaseSuccess() { $httpResponse = $this->getMockHttpResponse('CompletePurchaseSuccess.txt'); $response = new CompletePurchaseResponse($this->getMockRequest(), $httpResponse->json(), 'abc123'); $this->assertTrue($response->isSuccessful()); $this->assertSame('abc123', $response->getTransactionReference()); $this->assertNull($response->getMessage()); } public function testCompletePurchaseFailure() { $httpResponse = $this->getMockHttpResponse('CompletePurchaseFailure.txt'); $response = new CompletePurchaseResponse($this->getMockRequest(), $httpResponse->json(), 'abc123'); $this->assertFalse($response->isSuccessful()); $this->assertSame('abc123', $response->getTransactionReference()); $this->assertSame('The resource cannot be confirmed', $response->getMessage()); } } gocardless/tests/Mock/CapturePaymentFailure.txt 0000604 00000000100 15173176034 0015731 0 ustar 00 HTTP/1.1 200 OK {"error":["The authorization cannot be found"]} gocardless/tests/Mock/CompletePurchaseSuccess.txt 0000604 00000000042 15173176034 0016261 0 ustar 00 HTTP/1.1 200 OK {"success":true} gocardless/tests/Mock/CompletePurchaseFailure.txt 0000604 00000000100 15173176034 0016233 0 ustar 00 HTTP/1.1 200 OK {"error":["The resource cannot be confirmed"]} gocardless/tests/Mock/CapturePaymentSuccess.txt 0000604 00000000042 15173176034 0015757 0 ustar 00 HTTP/1.1 200 OK {"success":true} gocardless/tests/GatewayTest.php 0000604 00000012655 15173176034 0013022 0 ustar 00 <?php namespace Omnipay\GoCardless; use Omnipay\Tests\GatewayTestCase; class GatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); $this->gateway->setAppId('abc'); $this->gateway->setAppSecret('123'); $this->options = array( 'amount' => '10.00', 'returnUrl' => 'https://www.example.com/return', ); } public function testPurchase() { $response = $this->gateway->purchase($this->options)->send(); $this->assertInstanceOf('\Omnipay\GoCardless\Message\PurchaseResponse', $response); $this->assertTrue($response->isRedirect()); $this->assertStringStartsWith('https://gocardless.com/connect/bills/new?', $response->getRedirectUrl()); } public function testCompletePurchaseSuccess() { $this->getHttpRequest()->request->replace( array( 'resource_uri' => 'a', 'resource_id' => 'b', 'resource_type' => 'c', 'state' => 'd', 'signature' => 'cdc9e0cdb88114976dd18f597cb0a8f46cb26be6c8c17094b6394e76a7fc5732', ) ); $this->setMockHttpResponse('CompletePurchaseSuccess.txt'); $response = $this->gateway->completePurchase($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('b', $response->getTransactionReference()); } public function testCompletePurchaseError() { $this->getHttpRequest()->request->replace( array( 'resource_uri' => 'a', 'resource_id' => 'b', 'resource_type' => 'c', 'signature' => '416f52e7d287dab49fa8445c1cd0957ca8ddf1c04a6300e00117dc0bedabc7d7', ) ); $this->setMockHttpResponse('CompletePurchaseFailure.txt'); $response = $this->gateway->completePurchase($this->options)->send(); $this->assertFalse($response->isSuccessful()); $this->assertSame('The resource cannot be confirmed', $response->getMessage()); } /** * @expectedException Omnipay\Common\Exception\InvalidResponseException */ public function testCompletePurchaseInvalid() { $this->getHttpRequest()->request->replace( array( 'resource_uri' => 'a', 'resource_id' => 'b', 'resource_type' => 'c', 'signature' => 'd', ) ); $response = $this->gateway->completePurchase($this->options)->send(); } public function testAuthorization() { $params = array( 'amount' => '10.00', 'intervalLength' => 12, 'intervalUnit' => 'week', 'returnUrl' => 'foo.bar/baz' ); $response = $this->gateway->authorize($params)->send(); $this->assertInstanceOf('Omnipay\GoCardless\Message\AuthorizeResponse', $response); $this->assertStringStartsWith('https://gocardless.com/connect/pre_authorizations/new?', $response->getRedirectUrl()); //NB: These are here for a potential refactor. $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertSame('GET', $response->getRedirectMethod()); $this->assertNull($response->getRedirectData()); } public function testCompleteAuthorizeSuccess() { $this->getHttpRequest()->request->replace( array( 'resource_uri' => 'a', 'resource_id' => 'b', 'resource_type' => 'c', 'state' => 'd', 'signature' => 'cdc9e0cdb88114976dd18f597cb0a8f46cb26be6c8c17094b6394e76a7fc5732', ) ); $this->setMockHttpResponse('CompletePurchaseSuccess.txt'); $response = $this->gateway->completeAuthorize($this->options)->send(); $this->assertTrue($response->isSuccessful()); $this->assertEquals('b', $response->getTransactionReference()); } public function testCapture() { $response = $this->gateway->capture(array('amount' => '10.00')); $this->assertInstanceOf('Omnipay\GoCardless\Message\CaptureRequest', $response); } public function testCaptureSuccess() { $params = array( 'amount' => '10.00', 'transactionReference' => 'abc', 'description' => 'fyi' ); $transaction = $this->gateway->capture($params); $transaction->setChargeCustomerAt('2015-12-12'); $this->setMockHttpResponse('CapturePaymentSuccess.txt'); $response = $transaction->send(); $this->assertInstanceOf('Omnipay\GoCardless\Message\CaptureResponse', $response); $this->assertTrue($response->isSuccessful()); $this->assertNull($response->getMessage()); } public function testCaptureFailure() { $params = array( 'amount' => '10.00', 'transactionReference' => '12v' ); $this->setMockHttpResponse('CapturePaymentFailure.txt'); $response = $this->gateway->capture($params)->send(); $this->assertInstanceOf('Omnipay\GoCardless\Message\CaptureResponse', $response); $this->assertFalse($response->isSuccessful()); $this->assertSame('The authorization cannot be found', $response->getMessage()); } } gocardless/LICENSE 0000604 00000002047 15173176034 0007705 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. gocardless/.travis.yml 0000604 00000000317 15173176034 0011007 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 payfast/tests/GatewayTest.php 0000604 00000001476 15173176034 0012342 0 ustar 00 <?php namespace Omnipay\PayFast; use Omnipay\Tests\GatewayTestCase; class GatewayTest extends GatewayTestCase { public function setUp() { parent::setUp(); $this->gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); } public function testPurchase() { $request = $this->gateway->purchase(array('amount' => '12.00')); $this->assertInstanceOf('\Omnipay\PayFast\Message\PurchaseRequest', $request); $this->assertSame('12.00', $request->getAmount()); } public function testCompletePurchase() { $request = $this->gateway->completePurchase(array('amount' => '12.00')); $this->assertInstanceOf('\Omnipay\PayFast\Message\CompletePurchaseRequest', $request); $this->assertSame('12.00', $request->getAmount()); } } payfast/tests/Message/PurchaseResponseTest.php 0000604 00000001437 15173176034 0015613 0 ustar 00 <?php namespace Omnipay\PayFast\Message; use Omnipay\Tests\TestCase; class PurchaseResponseTest extends TestCase { public function testConstruct() { $data = array('test' => '123'); $response = new PurchaseResponse($this->getMockRequest(), $data, 'https://example.com/'); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertSame($data, $response->getData()); $this->assertSame('https://example.com/', $response->getRedirectUrl()); $this->assertSame('POST', $response->getRedirectMethod()); $this->assertSame($data, $response->getRedirectData()); } } payfast/tests/Message/CompletePurchaseRequestTest.php 0000604 00000005752 15173176034 0017142 0 ustar 00 <?php namespace Omnipay\PayFast\Message; use Omnipay\Tests\TestCase; class CompletePurchaseRequestTest extends TestCase { public function setUp() { $this->request = new CompletePurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); } public function getItnPostData() { return array( 'm_payment_id' => '', 'pf_payment_id' => '61493', 'payment_status' => 'COMPLETE', 'item_name' => 'fjdksl', 'item_description' => '', 'amount_gross' => '12.00', 'amount_fee' => '-0.27', 'amount_net' => '11.73', 'custom_str1' => '', 'custom_str2' => '', 'custom_str3' => '', 'custom_str4' => '', 'custom_str5' => '', 'custom_int1' => '', 'custom_int2' => '', 'custom_int3' => '', 'custom_int4' => '', 'custom_int5' => '', 'name_first' => 'Test', 'name_last' => 'User 01', 'email_address' => 'sbtu01@payfast.co.za', 'merchant_id' => '10000103', 'signature' => '92ac916145511e9050383b008729e162', ); } public function testCompletePurchaseItnSuccess() { $this->getHttpRequest()->request->replace($this->getItnPostData()); $this->setMockHttpResponse('CompletePurchaseItnSuccess.txt'); $response = $this->request->send(); $this->assertInstanceOf('Omnipay\PayFast\Message\CompletePurchaseItnResponse', $response); $this->assertTrue($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertSame('61493', $response->getTransactionReference()); $this->assertSame('COMPLETE', $response->getMessage()); $this->assertNull($response->getCode()); } public function testCompletePurchaseItnInvalid() { $this->getHttpRequest()->request->replace($this->getItnPostData()); $this->setMockHttpResponse('CompletePurchaseItnFailure.txt'); $response = $this->request->send(); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('INVALID', $response->getMessage()); $this->assertNull($response->getCode()); } public function testCompletePurchasePdtSuccess() { $this->getHttpRequest()->query->replace(array('pt' => 'abc')); $this->setMockHttpResponse('CompletePurchasePdtFailure.txt'); $response = $this->request->send(); $this->assertInstanceOf('Omnipay\PayFast\Message\CompletePurchasePdtResponse', $response); $this->assertFalse($response->isSuccessful()); $this->assertFalse($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertSame('FAIL', $response->getMessage()); $this->assertNull($response->getCode()); } } payfast/tests/Message/PurchaseRequestTest.php 0000604 00000003112 15173176034 0015435 0 ustar 00 <?php namespace Omnipay\PayFast\Message; use Omnipay\Tests\TestCase; class PurchaseRequestTest extends TestCase { public function setUp() { $this->request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); } public function testSignature() { $this->request->initialize( array( 'amount' => '12.00', 'description' => 'Test Product', 'transactionId' => 123, 'merchantId' => 'foo', 'merchantKey' => 'bar', 'returnUrl' => 'https://www.example.com/return', 'cancelUrl' => 'https://www.example.com/cancel', ) ); $data = $this->request->getData(); $this->assertSame('ab86df60906e97d3bfb362aff26fd9e6', $data['signature']); } public function testPurchase() { $this->request->setAmount('12.00')->setDescription('Test Product'); $response = $this->request->send(); $this->assertInstanceOf('Omnipay\PayFast\Message\PurchaseResponse', $response); $this->assertFalse($response->isSuccessful()); $this->assertTrue($response->isRedirect()); $this->assertNull($response->getTransactionReference()); $this->assertNull($response->getMessage()); $this->assertNull($response->getCode()); $this->assertSame('https://www.payfast.co.za/eng/process', $response->getRedirectUrl()); $this->assertSame('POST', $response->getRedirectMethod()); $this->assertArrayHasKey('signature', $response->getData()); } } payfast/tests/Mock/CompletePurchasePdtSuccess.txt 0000604 00000001276 15173176034 0016264 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 07 Mar 2013 04:50:36 GMT Server: Apache/2.2.3 (CentOS) Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Vary: Accept-Encoding,User-Agent Content-Length: 397 Connection: close Content-Type: text/html; charset=UTF-8 SUCCESS m_payment_id= pf_payment_id=61484 payment_status=COMPLETE item_name=fjdksl item_description= amount_gross=12.00 amount_fee=-0.27 amount_net=11.73 custom_str1= custom_str2= custom_str3= custom_str4= custom_str5= custom_int1= custom_int2= custom_int3= custom_int4= custom_int5= name_first=Test name_last=User+01 email_address=sbtu01%40payfast.co.za merchant_id=10000103 payfast/tests/Mock/CompletePurchaseItnSuccess.txt 0000604 00000000512 15173176034 0016257 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 07 Mar 2013 05:30:11 GMT Server: Apache/2.2.3 (CentOS) Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Vary: Accept-Encoding,User-Agent Content-Length: 5 Connection: close Content-Type: text/html; charset=UTF-8 VALID payfast/tests/Mock/CompletePurchaseItnFailure.txt 0000604 00000000746 15173176034 0016247 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 07 Mar 2013 04:57:24 GMT Server: Apache/2.2.3 (CentOS) Set-Cookie: refer_session=Direct; path=/; domain=.payfast.co.za, refer_first=Direct; expires=Fri, 07-Mar-2014 04:57:24 GMT; path=/; domain=.payfast.co.za Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Vary: Accept-Encoding,User-Agent Content-Length: 7 Connection: close Content-Type: text/html; charset=UTF-8 INVALID payfast/tests/Mock/CompletePurchasePdtFailure.txt 0000604 00000000511 15173176034 0016232 0 ustar 00 HTTP/1.1 200 OK Date: Thu, 07 Mar 2013 05:07:38 GMT Server: Apache/2.2.3 (CentOS) Expires: Thu, 19 Nov 1981 08:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Vary: Accept-Encoding,User-Agent Content-Length: 4 Connection: close Content-Type: text/html; charset=UTF-8 FAIL payfast/CONTRIBUTING.md 0000604 00000001040 15173176034 0010442 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. payfast/README.md 0000604 00000003517 15173176034 0007503 0 ustar 00 # Omnipay: PayFast **PayFast driver for the Omnipay PHP payment processing library** [](https://travis-ci.org/thephpleague/omnipay-payfast) [](https://packagist.org/packages/omnipay/payfast) [](https://packagist.org/packages/omnipay/payfast) [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment processing library for PHP 5.3+. This package implements PayFast 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/payfast": "~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: * PayFast 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-payfast/issues), or better yet, fork the library and submit a pull request. payfast/.gitignore 0000604 00000000060 15173176034 0010202 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml payfast/phpunit.xml.dist 0000604 00000001512 15173176034 0011370 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> payfast/.travis.yml 0000604 00000000317 15173176034 0010330 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 payfast/LICENSE 0000604 00000002047 15173176034 0007226 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. payfast/composer.json 0000604 00000001644 15173176034 0010745 0 ustar 00 { "name": "omnipay/payfast", "type": "library", "description": "PayFast driver for the Omnipay payment processing library", "keywords": [ "gateway", "merchant", "omnipay", "pay", "payfast", "payment" ], "homepage": "https://github.com/thephpleague/omnipay-payfast", "license": "MIT", "authors": [ { "name": "Adrian Macneil", "email": "adrian@adrianmacneil.com" }, { "name": "Omnipay Contributors", "homepage": "https://github.com/thephpleague/omnipay-payfast/contributors" } ], "autoload": { "psr-4": { "Omnipay\\PayFast\\" : "src/" } }, "require": { "omnipay/common": "~2.0" }, "require-dev": { "omnipay/tests": "~2.0" }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } payfast/src/Message/PurchaseResponse.php 0000604 00000001612 15173176034 0014373 0 ustar 00 <?php namespace Omnipay\PayFast\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RequestInterface; use Omnipay\Common\Message\RedirectResponseInterface; /** * PayFast Purchase Response */ class PurchaseResponse extends AbstractResponse implements RedirectResponseInterface { protected $redirectUrl; public function __construct(RequestInterface $request, $data, $redirectUrl) { parent::__construct($request, $data); $this->redirectUrl = $redirectUrl; } public function isSuccessful() { return false; } public function isRedirect() { return true; } public function getRedirectUrl() { return $this->redirectUrl; } public function getRedirectMethod() { return 'POST'; } public function getRedirectData() { return $this->getData(); } } payfast/src/Message/PurchaseRequest.php 0000604 00000005142 15173176034 0014227 0 ustar 00 <?php namespace Omnipay\PayFast\Message; use Omnipay\Common\Message\AbstractRequest; /** * PayFast Purchase Request */ class PurchaseRequest extends AbstractRequest { protected $liveEndpoint = 'https://www.payfast.co.za/eng'; protected $testEndpoint = 'https://sandbox.payfast.co.za/eng'; public function getMerchantId() { return $this->getParameter('merchantId'); } public function setMerchantId($value) { return $this->setParameter('merchantId', $value); } public function getMerchantKey() { return $this->getParameter('merchantKey'); } public function setMerchantKey($value) { return $this->setParameter('merchantKey', $value); } public function getPdtKey() { return $this->getParameter('pdtKey'); } public function setPdtKey($value) { return $this->setParameter('pdtKey', $value); } public function getData() { $this->validate('amount', 'description'); $data = array(); $data['merchant_id'] = $this->getMerchantId(); $data['merchant_key'] = $this->getMerchantKey(); $data['return_url'] = $this->getReturnUrl(); $data['cancel_url'] = $this->getCancelUrl(); $data['notify_url'] = $this->getReturnUrl(); if ($this->getCard()) { $data['name_first'] = $this->getCard()->getFirstName(); $data['name_last'] = $this->getCard()->getLastName(); $data['email_address'] = $this->getCard()->getEmail(); } $data['m_payment_id'] = $this->getTransactionId(); $data['amount'] = $this->getAmount(); $data['item_name'] = $this->getDescription(); $data['signature'] = $this->generateSignature($data); return $data; } protected function generateSignature($data) { $fields = array(); // specific order required by PayFast foreach (array('merchant_id', 'merchant_key', 'return_url', 'cancel_url', 'notify_url', 'name_first', 'name_last', 'email_address', 'm_payment_id', 'amount', 'item_name', 'item_description', 'email_confirmation', 'confirmation_address') as $key) { if (!empty($data[$key])) { $fields[$key] = $data[$key]; } } return md5(http_build_query($fields)); } public function sendData($data) { return $this->response = new PurchaseResponse($this, $data, $this->getEndpoint().'/process'); } public function getEndpoint() { return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; } } payfast/src/Message/CompletePurchaseItnResponse.php 0000604 00000001643 15173176035 0016544 0 ustar 00 <?php namespace Omnipay\PayFast\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RequestInterface; /** * PayFast Complete Purchase ITN Response */ class CompletePurchaseItnResponse extends AbstractResponse { public function __construct(RequestInterface $request, $data, $status) { parent::__construct($request, $data); $this->status = $status; } public function isSuccessful() { return 'VALID' === $this->status; } public function getTransactionReference() { if ($this->isSuccessful() && isset($this->data['pf_payment_id'])) { return $this->data['pf_payment_id']; } } public function getMessage() { if ($this->isSuccessful() && isset($this->data['payment_status'])) { return $this->data['payment_status']; } else { return $this->status; } } } payfast/src/Message/CompletePurchaseRequest.php 0000604 00000003504 15173176035 0015721 0 ustar 00 <?php namespace Omnipay\PayFast\Message; use Omnipay\Common\Exception\InvalidRequestException; /** * PayFast Complete Purchase Request * * We use the same return URL & class to handle both PDT (Payment Data Transfer) * and ITN (Instant Transaction Notification). */ class CompletePurchaseRequest extends PurchaseRequest { public function getData() { if ($this->httpRequest->query->get('pt')) { // this is a Payment Data Transfer request $data = array(); $data['pt'] = $this->httpRequest->query->get('pt'); $data['at'] = $this->getPdtKey(); return $data; } elseif ($signature = $this->httpRequest->request->get('signature')) { // this is an Instant Transaction Notification request $data = $this->httpRequest->request->all(); // signature is completely useless since it has no shared secret // signature must not be posted back to the validate URL, so we unset it unset($data['signature']); return $data; } throw new InvalidRequestException('Missing PDT or ITN variables'); } public function sendData($data) { if (isset($data['pt'])) { // validate PDT $url = $this->getEndpoint().'/query/fetch'; $httpResponse = $this->httpClient->post($url, null, $data)->send(); return $this->response = new CompletePurchasePdtResponse($this, $httpResponse->getBody(true)); } else { // validate ITN $url = $this->getEndpoint().'/query/validate'; $httpResponse = $this->httpClient->post($url, null, $data)->send(); $status = $httpResponse->getBody(true); return $this->response = new CompletePurchaseItnResponse($this, $data, $status); } } } payfast/src/Message/CompletePurchasePdtResponse.php 0000604 00000001647 15173176035 0016545 0 ustar 00 <?php namespace Omnipay\PayFast\Message; use Omnipay\Common\Message\AbstractResponse; use Omnipay\Common\Message\RequestInterface; /** * PayFast Complete Purchase PDT Response */ class CompletePurchasePdtResponse extends AbstractResponse { protected $status; public function __construct(RequestInterface $request, $data) { $this->request = $request; $this->data = array(); // parse ridiculous response format $lines = explode('\n', $data); $this->status = $lines[0]; foreach ($lines as $line) { $parts = explode('=', $line, 2); $this->data[$parts[0]] = isset($parts[1]) ? urldecode($parts[1]) : null; } } public function isSuccessful() { return 'SUCCESS' === $this->status; } public function getMessage() { return $this->isSuccessful() ? $this->data['payment_status'] : $this->status; } } payfast/src/Gateway.php 0000604 00000003022 15173176035 0011115 0 ustar 00 <?php namespace Omnipay\PayFast; use Omnipay\Common\AbstractGateway; /** * PayFast Gateway * * Quote: The PayFast engine is basically a "black box" which processes a purchaser's payment. * * @link https://www.payfast.co.za/s/std/integration-guide */ class Gateway extends AbstractGateway { public function getName() { return 'PayFast'; } public function getDefaultParameters() { return array( 'merchantId' => '', 'merchantKey' => '', 'pdtKey' => '', 'testMode' => false, ); } public function getMerchantId() { return $this->getParameter('merchantId'); } public function setMerchantId($value) { return $this->setParameter('merchantId', $value); } public function getMerchantKey() { return $this->getParameter('merchantKey'); } public function setMerchantKey($value) { return $this->setParameter('merchantKey', $value); } public function getPdtKey() { return $this->getParameter('pdtKey'); } public function setPdtKey($value) { return $this->setParameter('pdtKey', $value); } public function purchase(array $parameters = array()) { return $this->createRequest('\Omnipay\PayFast\Message\PurchaseRequest', $parameters); } public function completePurchase(array $parameters = array()) { return $this->createRequest('\Omnipay\PayFast\Message\CompletePurchaseRequest', $parameters); } } netaxept/.gitignore 0000604 00000000060 15173176035 0010364 0 ustar 00 /vendor composer.lock composer.phar phpunit.xml netaxept/tests/Mock/CompletePurchaseSuccess.txt 0000604 00000001225 15173176035 0015770 0 ustar 00 HTTP/1.1 200 OK Cache-Control: private Content-Type: text/xml Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Fri, 22 Feb 2013 16:53:34 GMT Content-Length: 474 <?xml version="1.0"?> <ProcessResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Operation>AUTH</Operation> <ResponseCode>OK</ResponseCode> <AuthorizationId>090896</AuthorizationId> <TransactionId>8a88d40cab5b47fab25e24d6228180a7</TransactionId> <ExecutionTime>2013-02-22T17:53:33.9906245+01:00</ExecutionTime> <MerchantId>424278</MerchantId> <BatchNumber>246</BatchNumber> </ProcessResponse> netaxept/tests/Mock/CaptureFailure.txt 0000604 00000000673 15173176035 0014115 0 ustar 00 HTTP/1.1 200 OK Cache-Control: private Content-Type: text/xml Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Fri, 22 Feb 2013 16:55:41 GMT Content-Length: 245 <?xml version="1.0"?> <GenericError xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <Error xsi:type="GenericError"> <Message>Unable to find transaction</Message> </Error> </GenericError>