├── .gitignore ├── .travis.yml ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── composer.json ├── phpunit.xml.dist ├── src ├── Gateway.php └── Message │ ├── CompletePurchaseRequest.php │ ├── CompletePurchaseResponse.php │ ├── PurchaseRequest.php │ └── PurchaseResponse.php └── tests ├── GatewayTest.php └── Message ├── CompletePurchaseResponseTest.php ├── PurchaseRequestTest.php └── PurchaseResponseTest.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.lock 3 | composer.phar 4 | phpunit.xml 5 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: php 2 | 3 | php: 4 | - 5.6 5 | - 7.0 6 | - 7.1 7 | - 7.2 8 | - 7.3 9 | - 7.4snapshot 10 | 11 | # This triggers builds to run on the new TravisCI infrastructure. 12 | # See: http://docs.travis-ci.com/user/workers/container-based-infrastructure/ 13 | sudo: false 14 | 15 | matrix: 16 | allow_failures: 17 | - php: 7.4snapshot 18 | 19 | ## Cache composer 20 | cache: 21 | directories: 22 | - $HOME/.composer/cache 23 | 24 | install: 25 | - composer install --prefer-dist --no-interaction 26 | 27 | script: 28 | - vendor/bin/phpcs --standard=PSR2 src 29 | - vendor/bin/phpunit --coverage-text 30 | -------------------------------------------------------------------------------- /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: 2Checkout (Deprecated) 2 | 3 | This driver uses [lagacy parameters](http://help.2checkout.com/articles/Knowledge_Article/Legacy-Parameter-Set) with no support to pass line items of products to puchase and lack support for payment via credit card token. 4 | Use this [improved driver](https://github.com/collizo4sky/omnipay-2checkout) instead (https://github.com/collizo4sky/omnipay-2checkout) 5 | 6 | 7 | **2Checkout driver for the Omnipay PHP payment processing library** 8 | 9 | [![Build Status](https://travis-ci.org/thephpleague/omnipay-2checkout.png?branch=master)](https://travis-ci.org/thephpleague/omnipay-2checkout) 10 | [![Latest Stable Version](https://poser.pugx.org/omnipay/2checkout/version.png)](https://packagist.org/packages/omnipay/2checkout) 11 | [![Total Downloads](https://poser.pugx.org/omnipay/2checkout/d/total.png)](https://packagist.org/packages/omnipay/2checkout) 12 | 13 | [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment 14 | processing library for PHP 5.3+. This package implements 2Checkout support for Omnipay. 15 | 16 | ## Installation 17 | 18 | Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply add it 19 | to your `composer.json` file: 20 | 21 | ```json 22 | { 23 | "require": { 24 | "omnipay/2checkout": "~2.0" 25 | } 26 | } 27 | ``` 28 | 29 | And run composer to update your dependencies: 30 | 31 | $ curl -s http://getcomposer.org/installer | php 32 | $ php composer.phar update 33 | 34 | ## Basic Usage 35 | 36 | The following gateways are provided by this package: 37 | 38 | * TwoCheckout 39 | 40 | For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) 41 | repository. 42 | 43 | ## Support 44 | 45 | If you are having general issues with Omnipay, we suggest posting on 46 | [Stack Overflow](http://stackoverflow.com/). Be sure to add the 47 | [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. 48 | 49 | If you want to keep up to date with release anouncements, discuss ideas for the project, 50 | or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which 51 | you can subscribe to. 52 | 53 | If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/thephpleague/omnipay-2checkout/issues), 54 | or better yet, fork the library and submit a pull request. 55 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "omnipay/2checkout", 3 | "type": "library", 4 | "description": "2Checkout driver for the Omnipay payment processing library", 5 | "keywords": [ 6 | "2checkout", 7 | "2co", 8 | "gateway", 9 | "merchant", 10 | "omnipay", 11 | "pay", 12 | "payment", 13 | "twocheckout" 14 | ], 15 | "homepage": "https://github.com/thephpleague/omnipay-2checkout", 16 | "license": "MIT", 17 | "authors": [ 18 | { 19 | "name": "Adrian Macneil", 20 | "email": "adrian@adrianmacneil.com" 21 | }, 22 | { 23 | "name": "Omnipay Contributors", 24 | "homepage": "https://github.com/thephpleague/omnipay-2checkout/contributors" 25 | } 26 | ], 27 | "autoload": { 28 | "psr-4": { "Omnipay\\TwoCheckout\\" : "src/" } 29 | }, 30 | "require": { 31 | "omnipay/common": "^3.0", 32 | "league/omnipay": "^3", 33 | "guzzlehttp/guzzle": "^6.3" 34 | }, 35 | "require-dev": { 36 | "omnipay/tests": "^3.0", 37 | "squizlabs/php_codesniffer": "^3" 38 | }, 39 | "extra": { 40 | "branch-alias": { 41 | "dev-master": "3.0.x-dev" 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests/ 15 | 16 | 17 | 18 | 19 | ./src 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /src/Gateway.php: -------------------------------------------------------------------------------- 1 | '', 25 | 'secretWord' => '', 26 | 'testMode' => false, 27 | ); 28 | } 29 | 30 | public function getAccountNumber() 31 | { 32 | return $this->getParameter('accountNumber'); 33 | } 34 | 35 | public function setAccountNumber($value) 36 | { 37 | return $this->setParameter('accountNumber', $value); 38 | } 39 | 40 | public function getSecretWord() 41 | { 42 | return $this->getParameter('secretWord'); 43 | } 44 | 45 | public function setSecretWord($value) 46 | { 47 | return $this->setParameter('secretWord', $value); 48 | } 49 | 50 | public function purchase(array $parameters = array()) 51 | { 52 | return $this->createRequest('\Omnipay\TwoCheckout\Message\PurchaseRequest', $parameters); 53 | } 54 | 55 | public function completePurchase(array $parameters = array()) 56 | { 57 | return $this->createRequest('\Omnipay\TwoCheckout\Message\CompletePurchaseRequest', $parameters); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/Message/CompletePurchaseRequest.php: -------------------------------------------------------------------------------- 1 | httpRequest->request->get('order_number'); 15 | 16 | // strange exception specified by 2Checkout 17 | if ($this->getTestMode()) { 18 | $orderNo = '1'; 19 | } 20 | 21 | $key = md5($this->getSecretWord().$this->getAccountNumber().$orderNo.$this->getAmount()); 22 | if (strtolower($this->httpRequest->request->get('key')) !== $key) { 23 | throw new InvalidResponseException('Invalid key'); 24 | } 25 | 26 | return $this->httpRequest->request->all(); 27 | } 28 | 29 | public function sendData($data) 30 | { 31 | return $this->response = new CompletePurchaseResponse($this, $data); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Message/CompletePurchaseResponse.php: -------------------------------------------------------------------------------- 1 | data['order_number']) ? $this->data['order_number'] : null; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/Message/PurchaseRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('accountNumber'); 15 | } 16 | 17 | public function setAccountNumber($value) 18 | { 19 | return $this->setParameter('accountNumber', $value); 20 | } 21 | 22 | public function getSecretWord() 23 | { 24 | return $this->getParameter('secretWord'); 25 | } 26 | 27 | public function setSecretWord($value) 28 | { 29 | return $this->setParameter('secretWord', $value); 30 | } 31 | 32 | public function getData() 33 | { 34 | $this->validate('amount', 'returnUrl'); 35 | 36 | $data = array(); 37 | $data['sid'] = $this->getAccountNumber(); 38 | $data['cart_order_id'] = $this->getTransactionId(); 39 | $data['merchant_order_id'] = $this->getTransactionId(); 40 | $data['total'] = $this->getAmount(); 41 | $data['tco_currency'] = $this->getCurrency(); 42 | $data['currency_code'] = $this->getCurrency(); 43 | $data['fixed'] = 'Y'; 44 | $data['skip_landing'] = 1; 45 | $data['x_receipt_link_url'] = $this->getReturnUrl(); 46 | 47 | if ($this->getCard()) { 48 | $data['card_holder_name'] = $this->getCard()->getName(); 49 | $data['street_address'] = $this->getCard()->getAddress1(); 50 | $data['street_address2'] = $this->getCard()->getAddress2(); 51 | $data['city'] = $this->getCard()->getCity(); 52 | $data['state'] = $this->getCard()->getState(); 53 | $data['zip'] = $this->getCard()->getPostcode(); 54 | $data['country'] = $this->getCard()->getCountry(); 55 | $data['phone'] = $this->getCard()->getPhone(); 56 | $data['email'] = $this->getCard()->getEmail(); 57 | } 58 | 59 | if ($this->getTestMode()) { 60 | $data['demo'] = 'Y'; 61 | } 62 | 63 | return $data; 64 | } 65 | 66 | public function sendData($data) 67 | { 68 | return $this->response = new PurchaseResponse($this, $data); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/Message/PurchaseResponse.php: -------------------------------------------------------------------------------- 1 | getRequest()->getTestMode() ? $this->testEndpoint : $this->endpoint; 29 | return $endpoint.'?'.http_build_query($this->data); 30 | } 31 | 32 | public function getRedirectMethod() 33 | { 34 | return 'GET'; 35 | } 36 | 37 | public function getRedirectData() 38 | { 39 | return array(); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tests/GatewayTest.php: -------------------------------------------------------------------------------- 1 | gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); 15 | $this->gateway->setAccountNumber('123456'); 16 | $this->gateway->setSecretWord('secret'); 17 | 18 | $this->options = array( 19 | 'amount' => '10.00', 20 | 'returnUrl' => 'https://www.example.com/return', 21 | ); 22 | } 23 | 24 | public function testPurchase() 25 | { 26 | $source = new CreditCard; 27 | $response = $this->gateway->purchase($this->options)->send(); 28 | 29 | $this->assertFalse($response->isSuccessful()); 30 | $this->assertTrue($response->isRedirect()); 31 | $this->assertNull($response->getTransactionReference()); 32 | $this->assertNull($response->getMessage()); 33 | $this->assertContains('https://www.2checkout.com/checkout/purchase?', $response->getRedirectUrl()); 34 | $this->assertSame('GET', $response->getRedirectMethod()); 35 | $this->assertEquals(array(), $response->getRedirectData()); 36 | } 37 | 38 | /** 39 | * @expectedException Omnipay\Common\Exception\InvalidResponseException 40 | */ 41 | public function testCompletePurchaseError() 42 | { 43 | $this->getHttpRequest()->request->replace(array('order_number' => '5', 'key' => 'ZZZ')); 44 | 45 | $response = $this->gateway->completePurchase($this->options)->send(); 46 | } 47 | 48 | public function testCompletePurchaseSuccess() 49 | { 50 | $this->getHttpRequest()->request->replace( 51 | array( 52 | 'order_number' => '5', 53 | 'key' => md5('secret123456510.00'), 54 | ) 55 | ); 56 | 57 | $response = $this->gateway->completePurchase($this->options)->send(); 58 | 59 | $this->assertTrue($response->isSuccessful()); 60 | $this->assertFalse($response->isRedirect()); 61 | $this->assertSame('5', $response->getTransactionReference()); 62 | $this->assertNull($response->getMessage()); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /tests/Message/CompletePurchaseResponseTest.php: -------------------------------------------------------------------------------- 1 | getMockRequest(), array('order_number' => 'abc123')); 12 | 13 | $this->assertTrue($response->isSuccessful()); 14 | $this->assertFalse($response->isRedirect()); 15 | $this->assertSame('abc123', $response->getTransactionReference()); 16 | $this->assertNull($response->getMessage()); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /tests/Message/PurchaseRequestTest.php: -------------------------------------------------------------------------------- 1 | getHttpClient(), $this->getHttpRequest()); 12 | 13 | $request->setAccountNumber('12345'); 14 | $request->setSecretWord('secretWord'); 15 | $request->setTransactionId('mytransaction1'); 16 | $request->setAmount('10.00'); 17 | $request->setReturnUrl('http://example.com/return'); 18 | 19 | $requestData = $request->getData(); 20 | 21 | $this->assertEquals($requestData['sid'], '12345'); 22 | $this->assertEquals($requestData['cart_order_id'], 'mytransaction1'); 23 | $this->assertEquals($requestData['merchant_order_id'], 'mytransaction1'); 24 | $this->assertEquals($requestData['total'], '10.00'); 25 | $this->assertEquals($requestData['x_receipt_link_url'], 'http://example.com/return'); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /tests/Message/PurchaseResponseTest.php: -------------------------------------------------------------------------------- 1 | getMockRequest(); 12 | $request->shouldReceive('getTestMode')->andReturn(false); 13 | 14 | $response = new Purchaseresponse($request, array('sid' => '12345', 'total' => '10.00')); 15 | 16 | $this->assertFalse($response->isSuccessful()); 17 | $this->assertTrue($response->isRedirect()); 18 | $this->assertNull($response->getTransactionReference()); 19 | $this->assertNull($response->getMessage()); 20 | $this->assertSame('https://www.2checkout.com/checkout/purchase?sid=12345&total=10.00', $response->getRedirectUrl()); 21 | $this->assertSame('GET', $response->getRedirectMethod()); 22 | $this->assertEquals(array(), $response->getRedirectData()); 23 | } 24 | } 25 | --------------------------------------------------------------------------------