├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── makedoc.sh ├── phpunit.xml.dist ├── runtests.sh ├── src ├── Gateway.php └── Message │ ├── CardReferenceRequest.php │ ├── CreditCardRequest.php │ ├── Response.php │ └── TransactionReferenceRequest.php └── tests ├── GatewayTest.php └── Message ├── CardReferenceRequestTest.php ├── CreditCardRequestTest.php ├── ResponseTest.php └── TransactionReferenceRequestTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | composer.phar 4 | phpunit.xml 5 | .directory 6 | .idea/ 7 | dirlist.app 8 | dirlist.cache 9 | dirlist.vendor 10 | documents/ 11 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.6 5 | - 7.0 6 | - 7.1 7 | - 7.2 8 | 9 | before_script: 10 | - composer install -n --dev --prefer-source 11 | 12 | script: vendor/bin/phpcs --standard=PSR2 src && vendor/bin/phpunit --coverage-text 13 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | * Fork the project. 4 | * Make your feature addition or bug fix. 5 | * Add tests for it. This is important so I don't break it in a future version unintentionally. 6 | * Commit just the modifications, do not mess with the composer.json or CHANGELOG.md files. 7 | * 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) 8 | style and that all tests pass. 9 | * Send the pull request. 10 | * Check that the Travis CI build passed. If not, rinse and repeat. 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2013 Adrian Macneil 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Omnipay: Dummy 2 | 3 | **Dummy driver for the Omnipay PHP payment processing library** 4 | 5 | [![Build Status](https://travis-ci.org/thephpleague/omnipay-dummy.png?branch=master)](https://travis-ci.org/thephpleague/omnipay-dummy) 6 | [![Latest Stable Version](https://poser.pugx.org/omnipay/dummy/version.png)](https://packagist.org/packages/omnipay/dummy) 7 | [![Total Downloads](https://poser.pugx.org/omnipay/dummy/d/total.png)](https://packagist.org/packages/omnipay/dummy) 8 | 9 | [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment 10 | processing library for PHP 5.3+. This package implements Dummy support for Omnipay. 11 | 12 | ## Installation 13 | 14 | Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply require `league/omnipay` and `omnipay/dummy` with Composer: 15 | 16 | ``` 17 | composer require league/omnipay omnipay/dummy 18 | ``` 19 | 20 | ## Basic Usage 21 | 22 | The following gateways are provided by this package: 23 | 24 | * Dummy 25 | 26 | This is a dummy gateway driver intended for testing purposes. If you provide a card number ending in an even number, the driver will return a success response. If it ends in an odd number, the driver will return a generic failure response. For example: 27 | 28 | * 4929000000006 - Success 29 | * 4444333322221111 - Failure 30 | 31 | For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) 32 | repository. 33 | 34 | ## Support 35 | 36 | If you are having general issues with Omnipay, we suggest posting on 37 | [Stack Overflow](http://stackoverflow.com/). Be sure to add the 38 | [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. 39 | 40 | If you want to keep up to date with release anouncements, discuss ideas for the project, 41 | or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which 42 | you can subscribe to. 43 | 44 | If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/thephpleague/omnipay-dummy/issues), 45 | or better yet, fork the library and submit a pull request. 46 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "omnipay/dummy", 3 | "type": "library", 4 | "description": "Dummy driver for the Omnipay payment processing library", 5 | "keywords": [ 6 | "dummy", 7 | "gateway", 8 | "merchant", 9 | "omnipay", 10 | "pay", 11 | "payment" 12 | ], 13 | "homepage": "https://github.com/thephpleague/omnipay-dummy", 14 | "license": "MIT", 15 | "authors": [ 16 | { 17 | "name": "Adrian Macneil", 18 | "email": "adrian@adrianmacneil.com" 19 | }, 20 | { 21 | "name": "Omnipay Contributors", 22 | "homepage": "https://github.com/thephpleague/omnipay-dummy/contributors" 23 | } 24 | ], 25 | "autoload": { 26 | "psr-4": { "Omnipay\\Dummy\\" : "src/" } 27 | }, 28 | "require": { 29 | "omnipay/common": "~3.0" 30 | }, 31 | "require-dev": { 32 | "omnipay/tests": "~3.0", 33 | "squizlabs/php_codesniffer": "~3.0" 34 | }, 35 | "extra": { 36 | "branch-alias": { 37 | "dev-master": "3.0.x-dev" 38 | } 39 | }, 40 | "prefer-stable": true 41 | } 42 | -------------------------------------------------------------------------------- /makedoc.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Smart little documentation generator. 5 | # GPL/LGPL 6 | # (c) Del 2015 http://www.babel.com.au/ 7 | # 8 | 9 | APPNAME='Omnipay Dummy Gateway Documentation' 10 | CMDFILE=apigen.cmd.$$ 11 | DESTDIR=./documents 12 | SRCDIRS="src" 13 | VENDORDIRS="vendor/guzzle vendor/omnipay" 14 | 15 | # 16 | # Ensure that dependencies are installed (including codeception and phpunit) 17 | # 18 | if [ -f composer.lock ]; then 19 | /usr/local/bin/composer install 20 | else 21 | /usr/local/bin/composer update 22 | fi 23 | 24 | # 25 | # Find apigen, either in the path or as a local phar file 26 | # 27 | if [ -f apigen.phar ]; then 28 | APIGEN="php apigen.phar" 29 | 30 | else 31 | APIGEN=`which apigen` 32 | if [ ! -f "$APIGEN" ]; then 33 | 34 | # Search for phpdoc if apigen is not found. 35 | if [ -f phpDocumentor.phar ]; then 36 | PHPDOC="php phpDocumentor.phar" 37 | 38 | else 39 | PHPDOC=`which phpdoc` 40 | if [ ! -f "$PHPDOC" ]; then 41 | echo "Neither apigen nor phpdoc is installed in the path or locally, please install one of them" 42 | echo "see http://www.apigen.org/ or http://www.phpdoc.org/" 43 | exit 1 44 | fi 45 | fi 46 | fi 47 | fi 48 | 49 | # 50 | # As of version 4 of apigen need to use the generate subcommand 51 | # 52 | if [ ! -z "$APIGEN" ]; then 53 | APIGEN="$APIGEN generate" 54 | fi 55 | 56 | # 57 | # Without any arguments this builds the entire system documentation, 58 | # making the cache file first if required. 59 | # 60 | if [ -z "$1" ]; then 61 | # 62 | # Check to see that the cache has been made. 63 | # 64 | if [ ! -f dirlist.cache ]; then 65 | echo "Making dirlist.cache file" 66 | $0 makecache 67 | fi 68 | 69 | # 70 | # Build the apigen/phpdoc command in a file. 71 | # 72 | if [ ! -z "$APIGEN" ]; then 73 | echo "$APIGEN --php --tree --title '$APPNAME API Documentation' --destination $DESTDIR/main \\" > $CMDFILE 74 | cat dirlist.cache | while read dir; do 75 | echo "--source $dir \\" >> $CMDFILE 76 | done 77 | echo "" >> $CMDFILE 78 | 79 | elif [ ! -z "$PHPDOC" ]; then 80 | echo "$PHPDOC --sourcecode --title '$APPNAME API Documentation' --target $DESTDIR/main --directory \\" > $CMDFILE 81 | cat dirlist.cache | while read dir; do 82 | echo "${dir},\\" >> $CMDFILE 83 | done 84 | echo "" >> $CMDFILE 85 | 86 | else 87 | "Neither apigen nor phpdoc are found, how did I get here?" 88 | exit 1 89 | fi 90 | 91 | # 92 | # Run the apigen command 93 | # 94 | rm -rf $DESTDIR/main 95 | mkdir -p $DESTDIR/main 96 | . ./$CMDFILE 97 | 98 | /bin/rm -f ./$CMDFILE 99 | 100 | # 101 | # The "makecache" argument causes the script to just make the cache file 102 | # 103 | elif [ "$1" = "makecache" ]; then 104 | echo "Find application source directories" 105 | find $SRCDIRS -name \*.php -print | \ 106 | ( 107 | while read file; do 108 | grep -q 'class' $file && dirname $file 109 | done 110 | ) | sort -u | \ 111 | grep -v -E 'config|docs|migrations|test|Test|views|web' > dirlist.app 112 | 113 | echo "Find vendor source directories" 114 | find $VENDORDIRS -name \*.php -print | \ 115 | ( 116 | while read file; do 117 | grep -q 'class' $file && dirname $file 118 | done 119 | ) | sort -u | \ 120 | grep -v -E 'config|docs|migrations|test|Test|views|codesniffer|phpmd|pdepend|php-parser|codeception|phpunit' > dirlist.vendor 121 | 122 | # 123 | # Filter out any directories for which apigen fails 124 | # 125 | echo "Filter source directories" 126 | mkdir -p $DESTDIR/tmp 127 | cat dirlist.app dirlist.vendor | while read dir; do 128 | if [ ! -z "$APIGEN" ]; then 129 | $APIGEN --quiet --title "Test please ignore" \ 130 | --source $dir \ 131 | --destination $DESTDIR/tmp && ( 132 | echo "Including $dir" 133 | echo $dir >> dirlist.cache 134 | ) || ( 135 | echo "Excluding $dir" 136 | ) 137 | 138 | elif [ ! -z "$PHPDOC" ]; then 139 | $PHPDOC --quiet --title "Test please ignore" \ 140 | --directory $dir \ 141 | --target $DESTDIR/tmp && ( 142 | echo "Including $dir" 143 | echo $dir >> dirlist.cache 144 | ) || ( 145 | echo "Excluding $dir" 146 | ) 147 | 148 | fi 149 | done 150 | echo "Documentation cache dirlist.cache built OK" 151 | 152 | # 153 | # Clean up 154 | # 155 | /bin/rm -rf $DESTDIR/tmp 156 | 157 | fi 158 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests/ 15 | 16 | 17 | 18 | 19 | ./src 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /runtests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # 4 | # Command line runner for unit tests for composer projects 5 | # (c) Del 2015 http://www.babel.com.au/ 6 | # No Rights Reserved 7 | # 8 | 9 | # 10 | # Clean up after any previous test runs 11 | # 12 | mkdir -p documents 13 | rm -rf documents/coverage-html-new 14 | rm -f documents/coverage.xml 15 | 16 | # 17 | # Run phpunit 18 | # 19 | vendor/bin/phpunit --coverage-html documents/coverage-html-new --coverage-clover documents/coverage.xml 20 | 21 | if [ -d documents/coverage-html-new ]; then 22 | rm -rf documents/coverage-html 23 | mv documents/coverage-html-new documents/coverage-html 24 | fi 25 | 26 | -------------------------------------------------------------------------------- /src/Gateway.php: -------------------------------------------------------------------------------- 1 | 30 | * // Create a gateway for the Dummy Gateway 31 | * // (routes to GatewayFactory::create) 32 | * $gateway = Omnipay::create('Dummy'); 33 | * 34 | * // Initialise the gateway 35 | * $gateway->initialize(array( 36 | * 'testMode' => true, // Doesn't really matter what you use here. 37 | * )); 38 | * 39 | * // Create a credit card object 40 | * // This card can be used for testing. 41 | * $card = new CreditCard(array( 42 | * 'firstName' => 'Example', 43 | * 'lastName' => 'Customer', 44 | * 'number' => '4242424242424242', 45 | * 'expiryMonth' => '01', 46 | * 'expiryYear' => '2020', 47 | * 'cvv' => '123', 48 | * )); 49 | * 50 | * // Do a purchase transaction on the gateway 51 | * $transaction = $gateway->purchase(array( 52 | * 'amount' => '10.00', 53 | * 'currency' => 'AUD', 54 | * 'card' => $card, 55 | * )); 56 | * $response = $transaction->send(); 57 | * if ($response->isSuccessful()) { 58 | * echo "Purchase transaction was successful!\n"; 59 | * $sale_id = $response->getTransactionReference(); 60 | * echo "Transaction reference = " . $sale_id . "\n"; 61 | * } 62 | * 63 | */ 64 | class Gateway extends AbstractGateway 65 | { 66 | public function getName() 67 | { 68 | return 'Dummy'; 69 | } 70 | 71 | public function getDefaultParameters() 72 | { 73 | return array(); 74 | } 75 | 76 | public function authorize(array $parameters = array()) 77 | { 78 | return $this->createRequest('\Omnipay\Dummy\Message\CreditCardRequest', $parameters); 79 | } 80 | 81 | public function purchase(array $parameters = array()) 82 | { 83 | return $this->createRequest('\Omnipay\Dummy\Message\CreditCardRequest', $parameters); 84 | } 85 | 86 | public function completeAuthorize(array $parameters = array()) 87 | { 88 | return $this->createRequest('\Omnipay\Dummy\Message\TransactionReferenceRequest', $parameters); 89 | } 90 | 91 | public function capture(array $parameters = array()) 92 | { 93 | return $this->createRequest('\Omnipay\Dummy\Message\TransactionReferenceRequest', $parameters); 94 | } 95 | 96 | public function completePurchase(array $parameters = array()) 97 | { 98 | return $this->createRequest('\Omnipay\Dummy\Message\TransactionReferenceRequest', $parameters); 99 | } 100 | 101 | public function refund(array $parameters = array()) 102 | { 103 | return $this->createRequest('\Omnipay\Dummy\Message\TransactionReferenceRequest', $parameters); 104 | } 105 | 106 | public function void(array $parameters = array()) 107 | { 108 | return $this->createRequest('\Omnipay\Dummy\Message\TransactionReferenceRequest', $parameters); 109 | } 110 | 111 | public function createCard(array $parameters = array()) 112 | { 113 | return $this->createRequest('\Omnipay\Dummy\Message\CreditCardRequest', $parameters); 114 | } 115 | 116 | public function updateCard(array $parameters = array()) 117 | { 118 | return $this->createRequest('\Omnipay\Dummy\Message\CardReferenceRequest', $parameters); 119 | } 120 | 121 | public function deleteCard(array $parameters = array()) 122 | { 123 | return $this->createRequest('\Omnipay\Dummy\Message\CardReferenceRequest', $parameters); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /src/Message/CardReferenceRequest.php: -------------------------------------------------------------------------------- 1 | validate('cardReference'); 17 | return array('cardReference' => $this->getCardReference()); 18 | } 19 | 20 | public function sendData($data) 21 | { 22 | $data['reference'] = $this->getCardReference(); 23 | $data['success'] = 0 === substr($this->getCardReference(), -1, 1) % 2; 24 | $data['message'] = $data['success'] ? 'Success' : 'Failure'; 25 | 26 | return $this->response = new Response($this, $data); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/Message/CreditCardRequest.php: -------------------------------------------------------------------------------- 1 | validate('amount', 'card'); 18 | 19 | $this->getCard()->validate(); 20 | 21 | return array('amount' => $this->getAmount()); 22 | } 23 | 24 | public function sendData($data) 25 | { 26 | $data['reference'] = uniqid(); 27 | $data['success'] = 0 === substr($this->getCard()->getNumber(), -1, 1) % 2; 28 | $data['message'] = $data['success'] ? 'Success' : 'Failure'; 29 | 30 | return $this->response = new Response($this, $data); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/Message/Response.php: -------------------------------------------------------------------------------- 1 | data['success']) && $this->data['success']; 18 | } 19 | 20 | public function getTransactionReference() 21 | { 22 | return isset($this->data['reference']) ? $this->data['reference'] : null; 23 | } 24 | 25 | public function getTransactionId() 26 | { 27 | return isset($this->data['reference']) ? $this->data['reference'] : null; 28 | } 29 | 30 | public function getCardReference() 31 | { 32 | return isset($this->data['reference']) ? $this->data['reference'] : null; 33 | } 34 | 35 | public function getMessage() 36 | { 37 | return isset($this->data['message']) ? $this->data['message'] : null; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/Message/TransactionReferenceRequest.php: -------------------------------------------------------------------------------- 1 | validate('transactionReference'); 17 | return array('transactionReference' => $this->getTransactionReference()); 18 | } 19 | 20 | public function sendData($data) 21 | { 22 | $data['reference'] = $this->getTransactionReference(); 23 | $data['success'] = strpos($this->getTransactionReference(), 'fail') !== false ? false : true; 24 | $data['message'] = $data['success'] ? 'Success' : 'Failure'; 25 | 26 | return $this->response = new Response($this, $data); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /tests/GatewayTest.php: -------------------------------------------------------------------------------- 1 | gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); 14 | } 15 | 16 | public function testAuthorize() 17 | { 18 | $options = array( 19 | 'amount' => '10.00', 20 | 'card' => $this->getValidCard(), 21 | ); 22 | $request= $this->gateway->authorize($options); 23 | 24 | $this->assertInstanceOf('\Omnipay\Dummy\Message\CreditCardRequest', $request); 25 | $this->assertArrayHasKey('amount', $request->getData()); 26 | } 27 | 28 | public function testPurchase() 29 | { 30 | $options = array( 31 | 'amount' => '10.00', 32 | 'card' => $this->getValidCard(), 33 | ); 34 | $request= $this->gateway->purchase($options); 35 | 36 | $this->assertInstanceOf('\Omnipay\Dummy\Message\CreditCardRequest', $request); 37 | $this->assertArrayHasKey('amount', $request->getData()); 38 | } 39 | 40 | public function testCompleteAuthorize() 41 | { 42 | $options = array( 43 | 'transactionReference' => 'abc123' 44 | ); 45 | $request= $this->gateway->completeAuthorize($options); 46 | 47 | $this->assertInstanceOf('\Omnipay\Dummy\Message\TransactionReferenceRequest', $request); 48 | $this->assertArrayHasKey('transactionReference', $request->getData()); 49 | } 50 | 51 | public function testCapture() 52 | { 53 | $options = array( 54 | 'transactionReference' => 'abc123' 55 | ); 56 | $request= $this->gateway->capture($options); 57 | 58 | $this->assertInstanceOf('\Omnipay\Dummy\Message\TransactionReferenceRequest', $request); 59 | $this->assertArrayHasKey('transactionReference', $request->getData()); 60 | } 61 | 62 | public function testCompletePurchase() 63 | { 64 | $options = array( 65 | 'transactionReference' => 'abc123' 66 | ); 67 | $request= $this->gateway->completePurchase($options); 68 | 69 | $this->assertInstanceOf('\Omnipay\Dummy\Message\TransactionReferenceRequest', $request); 70 | $this->assertArrayHasKey('transactionReference', $request->getData()); 71 | } 72 | 73 | public function testRefund() 74 | { 75 | $options = array( 76 | 'transactionReference' => 'abc123' 77 | ); 78 | $request= $this->gateway->refund($options); 79 | 80 | $this->assertInstanceOf('\Omnipay\Dummy\Message\TransactionReferenceRequest', $request); 81 | $this->assertArrayHasKey('transactionReference', $request->getData()); 82 | } 83 | 84 | public function testVoid() 85 | { 86 | $options = array( 87 | 'transactionReference' => 'abc123' 88 | ); 89 | $request= $this->gateway->void($options); 90 | 91 | $this->assertInstanceOf('\Omnipay\Dummy\Message\TransactionReferenceRequest', $request); 92 | $this->assertArrayHasKey('transactionReference', $request->getData()); 93 | } 94 | 95 | public function testCreateCard() 96 | { 97 | $options = array( 98 | 'amount' => '10.00', 99 | 'card' => $this->getValidCard(), 100 | ); 101 | $request= $this->gateway->createCard($options); 102 | 103 | $this->assertInstanceOf('\Omnipay\Dummy\Message\CreditCardRequest', $request); 104 | $this->assertArrayHasKey('amount', $request->getData()); 105 | } 106 | 107 | public function testUpdateCard() 108 | { 109 | $options = array( 110 | 'cardReference' => 'abc123' 111 | ); 112 | $request= $this->gateway->updateCard($options); 113 | 114 | $this->assertInstanceOf('\Omnipay\Dummy\Message\CardReferenceRequest', $request); 115 | $this->assertArrayHasKey('cardReference', $request->getData()); 116 | } 117 | 118 | public function testDeleteCard() 119 | { 120 | $options = array( 121 | 'cardReference' => 'abc123' 122 | ); 123 | $request= $this->gateway->deleteCard($options); 124 | 125 | $this->assertInstanceOf('\Omnipay\Dummy\Message\CardReferenceRequest', $request); 126 | $this->assertArrayHasKey('cardReference', $request->getData()); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /tests/Message/CardReferenceRequestTest.php: -------------------------------------------------------------------------------- 1 | gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); 13 | } 14 | 15 | public function testGetData() 16 | { 17 | $request = new CardReferenceRequest($this->getHttpClient(), $this->getHttpRequest()); 18 | $request->initialize(array( 19 | 'cardReference' => 'pass123' 20 | )); 21 | $data = $request->getData(); 22 | $this->assertSame('pass123', $data['cardReference']); 23 | } 24 | 25 | public function testSuccess() 26 | { 27 | // reference ids which are even should pass 28 | $options = array('cardReference' => '22222'); 29 | $response = $this->gateway->deleteCard($options)->send(); 30 | 31 | $this->assertInstanceOf('\Omnipay\Dummy\Message\Response', $response); 32 | $this->assertTrue($response->isSuccessful()); 33 | $this->assertFalse($response->isRedirect()); 34 | $this->assertNotEmpty($response->getCardReference()); 35 | $this->assertSame('Success', $response->getMessage()); 36 | } 37 | 38 | public function testFailure() 39 | { 40 | // reference ids which are odd should fail 41 | $options = array('cardReference' => '33333'); 42 | $response = $this->gateway->deleteCard($options)->send(); 43 | 44 | $this->assertInstanceOf('\Omnipay\Dummy\Message\Response', $response); 45 | $this->assertFalse($response->isSuccessful()); 46 | $this->assertFalse($response->isRedirect()); 47 | $this->assertNotEmpty($response->getCardReference()); 48 | $this->assertSame('Failure', $response->getMessage()); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /tests/Message/CreditCardRequestTest.php: -------------------------------------------------------------------------------- 1 | gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); 13 | } 14 | 15 | public function testGetData() 16 | { 17 | $request = new CreditCardRequest($this->getHttpClient(), $this->getHttpRequest()); 18 | $request->initialize(array( 19 | 'amount' => '10.00', 20 | 'card' => $this->getValidCard(), 21 | )); 22 | $data = $request->getData(); 23 | $this->assertSame('10.00', $data['amount']); 24 | } 25 | 26 | public function testCreditCardSuccess() 27 | { 28 | // card numbers ending in even number should be successful 29 | $options = array( 30 | 'amount' => '10.00', 31 | 'card' => $this->getValidCard(), 32 | ); 33 | $options['card']['number'] = '4242424242424242'; 34 | $response = $this->gateway->authorize($options)->send(); 35 | 36 | $this->assertInstanceOf('\Omnipay\Dummy\Message\Response', $response); 37 | $this->assertTrue($response->isSuccessful()); 38 | $this->assertFalse($response->isRedirect()); 39 | $this->assertNotEmpty($response->getTransactionReference()); 40 | $this->assertSame('Success', $response->getMessage()); 41 | } 42 | 43 | public function testCreditCardFailure() 44 | { 45 | // card numbers ending in odd number should be declined 46 | $options = array( 47 | 'amount' => '10.00', 48 | 'card' => $this->getValidCard(), 49 | ); 50 | $options['card']['number'] = '4111111111111111'; 51 | $response = $this->gateway->authorize($options)->send(); 52 | 53 | $this->assertInstanceOf('\Omnipay\Dummy\Message\Response', $response); 54 | $this->assertFalse($response->isSuccessful()); 55 | $this->assertFalse($response->isRedirect()); 56 | $this->assertNotEmpty($response->getTransactionReference()); 57 | $this->assertSame('Failure', $response->getMessage()); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /tests/Message/ResponseTest.php: -------------------------------------------------------------------------------- 1 | getMockRequest(), 13 | array('reference' => 'abc123', 'success' => 1, 'message' => 'Success') 14 | ); 15 | 16 | $this->assertTrue($response->isSuccessful()); 17 | $this->assertFalse($response->isRedirect()); 18 | $this->assertSame('abc123', $response->getTransactionReference()); 19 | $this->assertSame('Success', $response->getMessage()); 20 | } 21 | 22 | public function testFailure() 23 | { 24 | $response = new Response( 25 | $this->getMockRequest(), 26 | array('reference' => 'abc123', 'success' => 0, 'message' => 'Failure') 27 | ); 28 | 29 | $this->assertFalse($response->isSuccessful()); 30 | $this->assertFalse($response->isRedirect()); 31 | $this->assertSame('abc123', $response->getTransactionReference()); 32 | $this->assertSame('Failure', $response->getMessage()); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /tests/Message/TransactionReferenceRequestTest.php: -------------------------------------------------------------------------------- 1 | gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); 13 | } 14 | 15 | public function testGetData() 16 | { 17 | $request = new TransactionReferenceRequest($this->getHttpClient(), $this->getHttpRequest()); 18 | $request->initialize(array( 19 | 'transactionReference' => 'abc123', 20 | )); 21 | $data = $request->getData(); 22 | $this->assertSame('abc123', $data['transactionReference']); 23 | } 24 | 25 | public function testSuccess() 26 | { 27 | $options['transactionReference'] = 'pass123'; 28 | $response = $this->gateway->void($options)->send(); 29 | 30 | $this->assertTrue($response->isSuccessful()); 31 | $this->assertFalse($response->isRedirect()); 32 | $this->assertNotEmpty($response->getTransactionReference()); 33 | $this->assertSame('Success', $response->getMessage()); 34 | } 35 | 36 | public function testFollowupFailure() 37 | { 38 | // transactionReferences containing 'fail' fail 39 | $options['transactionReference'] = 'fail123'; 40 | $response = $this->gateway->void($options)->send(); 41 | 42 | $this->assertInstanceOf('\Omnipay\Dummy\Message\Response', $response); 43 | $this->assertFalse($response->isSuccessful()); 44 | $this->assertFalse($response->isRedirect()); 45 | $this->assertNotEmpty($response->getTransactionReference()); 46 | $this->assertSame('Failure', $response->getMessage()); 47 | } 48 | 49 | } 50 | --------------------------------------------------------------------------------