├── .gitignore ├── src ├── Message │ ├── PurchaseRequest.php │ ├── VoidRequest.php │ ├── CaptureRequest.php │ ├── RefundRequest.php │ ├── FetchTransactionRequest.php │ ├── ServerNotifyRequest.php │ ├── AbstractRequest.php │ ├── Response.php │ └── AuthorizeRequest.php └── Gateway.php ├── grumphp.yml ├── .travis.yml ├── CONTRIBUTING.md ├── composer.json ├── tests ├── Mock │ ├── PurchaseFailure.txt │ └── PurchaseSuccess.txt ├── Message │ ├── PurchaseRequestTest.php │ └── PurchaseResponseTest.php └── GatewayTest.php ├── phpunit.xml.dist ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor/ 2 | .idea 3 | composer.lock 4 | -------------------------------------------------------------------------------- /src/Message/PurchaseRequest.php: -------------------------------------------------------------------------------- 1 | validate('transactionReference'); 10 | 11 | return array( 12 | 'paymentType' => 'RV', 13 | ); 14 | } 15 | 16 | protected function getEndpoint() 17 | { 18 | return parent::getEndpoint() . '/payments/' . $this->getTransactionReference(); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /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. -------------------------------------------------------------------------------- /src/Message/CaptureRequest.php: -------------------------------------------------------------------------------- 1 | validate('transactionReference', 'amount', 'currency'); 10 | 11 | return array( 12 | 'paymentType' => 'CP', 13 | 'amount' => $this->getAmount(), 14 | 'currency' => $this->getCurrency() 15 | ); 16 | } 17 | 18 | protected function getEndpoint() 19 | { 20 | return parent::getEndpoint() . '/payments/' . $this->getTransactionReference(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/Message/RefundRequest.php: -------------------------------------------------------------------------------- 1 | validate('transactionReference', 'amount', 'currency'); 10 | 11 | return array( 12 | 'paymentType' => 'RF', 13 | 'amount' => $this->getAmount(), 14 | 'currency' => $this->getCurrency() 15 | ); 16 | } 17 | 18 | protected function getEndpoint() 19 | { 20 | return parent::getEndpoint() . '/payments/' . $this->getTransactionReference(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vdbelt/omnipay-oppwa", 3 | "type": "library", 4 | "prefer-stable": true, 5 | "require": { 6 | "omnipay/common": "^3" 7 | }, 8 | "require-dev": { 9 | "omnipay/tests": "^3", 10 | "squizlabs/php_codesniffer": "^3", 11 | "phpro/grumphp": "^0.14" 12 | }, 13 | "autoload": { 14 | "psr-4": { "Omnipay\\Oppwa\\" : "src/" } 15 | }, 16 | "scripts": { 17 | "test": "phpunit" 18 | }, 19 | "license": "MIT", 20 | "homepage": "https://github.com/vdbelt/omnipay-oppwa", 21 | "keywords": [ 22 | "gateway", 23 | "merchant", 24 | "payon", 25 | "oppwa", 26 | "omnipay" 27 | ], 28 | "authors": [ 29 | { 30 | "name": "Martin van de Belt", 31 | "email": "martin@vandebelt.dk" 32 | } 33 | ] 34 | } 35 | -------------------------------------------------------------------------------- /tests/Mock/PurchaseFailure.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 403 Forbidden 2 | Date: Sat, 06 May 2017 09:03:57 GMT 3 | Server: Apache-Coyote/1.1 4 | Strict-Transport-Security: max-age=63072000; includeSubdomains; preload 5 | X-Content-Type-Options: nosniff 6 | X-XSS-Protection: 1; mode=block 7 | Cache-Control: private, no-cache, no-store 8 | Pragma: no-cache 9 | Access-Control-Allow-Origin: * 10 | Access-Control-Allow-Credentials: true 11 | X-Application-WAF-Action: allow 12 | Content-Type: application/json;charset=UTF-8 13 | Content-Length: 406 14 | 15 | {"id":"8a82944a5bd8e738015bdd00507d6e08","paymentType":"DB","paymentBrand":"SOFORTUEBERWEISUNG","result":{"code":"800.900.300","description":"invalid authentication information"},"bankAccount":{"country":"AT"},"buildNumber":"12f84ff3b13acc20971256c12de7ebf3dca5b5a8@2017-05-04 12:59:36 +0000","timestamp":"2017-05-06 09:03:57+0000","ndc":"8a829417572279ad015732d66cb427b6_f0fae40f2e7f4bcdb64b5609d7ed6eb0"} -------------------------------------------------------------------------------- /phpunit.xml.dist: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 14 | ./tests/ 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | ./src 23 | 24 | 25 | -------------------------------------------------------------------------------- /src/Message/FetchTransactionRequest.php: -------------------------------------------------------------------------------- 1 | validate('transactionReference'); 12 | 13 | return array(); 14 | } 15 | 16 | protected function getHttpMethod() 17 | { 18 | return 'GET'; 19 | } 20 | 21 | protected function getEndpoint() 22 | { 23 | if ($this->getIntegrationType() === Gateway::TYPE_SERVER_TO_SERVER) { 24 | return parent::getEndpoint() . '/payments/' . $this->getTransactionReference(); 25 | } 26 | 27 | if ($this->getIntegrationType() === Gateway::TYPE_COPY_AND_PASTE) { 28 | return parent::getEndpoint() . '/checkouts/' . $this->getTransactionReference().'/payment'; 29 | } 30 | 31 | throw new \LogicException("Unknown integrationType {$this->getIntegrationType()}"); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/Message/ServerNotifyRequest.php: -------------------------------------------------------------------------------- 1 | getDataItem('resourcePath')); 14 | 15 | return end($data); 16 | } 17 | 18 | public function getTransactionStatus() 19 | { 20 | return null; 21 | } 22 | 23 | public function getMessage() 24 | { 25 | return null; 26 | } 27 | 28 | protected function getDataItem($name) 29 | { 30 | $this->getData(); 31 | 32 | return isset($this->data[$name]) ? $this->data[$name] : ''; 33 | } 34 | 35 | public function getData() 36 | { 37 | if (!isset($this->data)) { 38 | $this->data = $this->httpRequest->query->all(); 39 | } 40 | 41 | return $this->data; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /tests/Message/PurchaseRequestTest.php: -------------------------------------------------------------------------------- 1 | request = new PurchaseRequest($this->getHttpClient(), $this->getHttpRequest()); 13 | $this->request->initialize( 14 | array( 15 | 'amount' => '10.00', 16 | 'currency' => 'USD', 17 | 'integrationType' => Gateway::TYPE_SERVER_TO_SERVER, 18 | ) 19 | ); 20 | } 21 | 22 | public function testGetData() 23 | { 24 | $this->assertSame('DB', $this->request->getData()['paymentType']); 25 | } 26 | 27 | public function testSend() 28 | { 29 | $this->setMockHttpResponse('PurchaseSuccess.txt'); 30 | 31 | $response = $this->request->send(); 32 | 33 | $this->assertFalse($response->isSuccessful()); 34 | $this->assertTrue($response->isRedirect()); 35 | } 36 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2017 Martin van de Belt 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. -------------------------------------------------------------------------------- /tests/Message/PurchaseResponseTest.php: -------------------------------------------------------------------------------- 1 | getMockHttpResponse('PurchaseSuccess.txt'); 12 | $response = new Response($this->getMockRequest(), json_decode($httpResponse->getBody(), true), $httpResponse->getStatusCode()); 13 | $this->assertFalse($response->isSuccessful()); 14 | $this->assertTrue($response->isRedirect()); 15 | $this->assertSame('8a8294495bd8df2e015bdcff493b390b', $response->getTransactionReference()); 16 | $this->assertEquals($response->getCode(), 200); 17 | } 18 | public function testPurchaseFailure() 19 | { 20 | $httpResponse = $this->getMockHttpResponse('PurchaseFailure.txt'); 21 | $response = new Response($this->getMockRequest(), json_decode($httpResponse->getBody(), true), $httpResponse->getStatusCode()); 22 | $this->assertFalse($response->isSuccessful()); 23 | $this->assertFalse($response->isRedirect()); 24 | $this->assertEquals($response->getCode(), 403); 25 | } 26 | } -------------------------------------------------------------------------------- /tests/Mock/PurchaseSuccess.txt: -------------------------------------------------------------------------------- 1 | HTTP/1.1 200 OK 2 | Date: Sat, 06 May 2017 09:02:49 GMT 3 | Server: Apache-Coyote/1.1 4 | Strict-Transport-Security: max-age=63072000; includeSubdomains; preload 5 | X-Content-Type-Options: nosniff 6 | X-XSS-Protection: 1; mode=block 7 | Cache-Control: private, no-cache, no-store 8 | Pragma: no-cache 9 | Access-Control-Allow-Origin: * 10 | Access-Control-Allow-Credentials: true 11 | X-Application-WAF-Action: allow 12 | Content-Type: application/json;charset=UTF-8 13 | Content-Length: 885 14 | 15 | {"id":"8a8294495bd8df2e015bdcff493b390b","paymentType":"DB","paymentBrand":"SOFORTUEBERWEISUNG","amount":"10.00","currency":"EUR","descriptor":"4610.8883.4210 Sofort_Channel ","result":{"code":"000.200.000","description":"transaction pending"},"resultDetails":{"connectorId":"1111-2222-3333-4444","AcquirerResponse":"received","ConnectorTxID1":"1111-2222-3333-4444"},"bankAccount":{"country":"AT"},"redirect":{"url":"https://test.acaptureservices.com/connectors/demo/sofortbanking/simulator/login.ftl?sessionID=3B68E51AF633B5473E141A5502A25978.sbg-vm-con01&amount=10.00&sofortID=1111-2222-3333-4444&ndcid=8a829417572279ad015732d66cb427b6_9632929d673b4d8caaaa09a2facc3a09","parameters":[]},"buildNumber":"12f84ff3b13acc20971256c12de7ebf3dca5b5a8@2017-05-04 12:59:36 +0000","timestamp":"2017-05-06 09:02:49+0000","ndc":"8a829417572279ad015732d66cb427b6_9632929d673b4d8caaaa09a2facc3a09"} -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Omnipay: Oppwa 2 | 3 | **Oppwa driver for the Omnipay PHP payment processing library** 4 | 5 | [![Build Status](https://travis-ci.org/vdbelt/omnipay-oppwa.png?branch=master)](https://travis-ci.org/vdbelt/omnipay-oppwa) 6 | [![Latest Stable Version](https://poser.pugx.org/vdbelt/omnipay-oppwa/version.png)](https://packagist.org/packages/vdbelt/omnipay-oppwa) 7 | [![Total Downloads](https://poser.pugx.org/vdbelt/omnipay-oppwa/d/total.png)](https://packagist.org/packages/vdbelt/omnipay-oppwa) 8 | 9 | [Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment 10 | processing library for PHP. This package implements Oppwa support for Omnipay. 11 | 12 | ## Installation 13 | 14 | Omnipay is installed via [Composer](http://getcomposer.org/). To install, simply require omnipay/omnipay and vdbelt/omnipay-oppwa with Composer: 15 | 16 | ``` 17 | composer require omnipay/omnipay vdbelt/omnipay-oppwa 18 | ``` 19 | 20 | 21 | ## Basic Usage 22 | 23 | The following gateways are provided by this package: 24 | 25 | * Oppwa 26 | 27 | Available configuration options: 28 | 29 | * token (string, required) 30 | * entityId (string, required) 31 | * testMode (0/1, optional) 32 | 33 | For general usage instructions, please see the main [Omnipay](https://github.com/thephpleague/omnipay) 34 | repository. 35 | 36 | ## Support 37 | 38 | If you are having general issues with Omnipay, we suggest posting on 39 | [Stack Overflow](http://stackoverflow.com/). Be sure to add the 40 | [omnipay tag](http://stackoverflow.com/questions/tagged/omnipay) so it can be easily found. 41 | 42 | If you want to keep up to date with release announcements, discuss ideas for the project, 43 | or ask more detailed questions, there is also a [mailing list](https://groups.google.com/forum/#!forum/omnipay) which 44 | you can subscribe to. 45 | 46 | If you believe you have found a bug, please report it using the [GitHub issue tracker](https://github.com/vdbelt/omnipay-oppwa/issues), 47 | or better yet, fork the library and submit a pull request. -------------------------------------------------------------------------------- /tests/GatewayTest.php: -------------------------------------------------------------------------------- 1 | gateway = new Gateway($this->getHttpClient(), $this->getHttpRequest()); 15 | } 16 | 17 | public function testPurchase() 18 | { 19 | $request = $this->gateway->purchase(array('amount' => '10.00', 'currency' => 'USD')); 20 | $this->assertInstanceOf('Omnipay\Oppwa\Message\PurchaseRequest', $request); 21 | $this->assertSame('10.00', $request->getAmount()); 22 | $this->assertSame('USD', $request->getCurrency()); 23 | } 24 | 25 | public function testCapture() 26 | { 27 | $request = $this->gateway->capture(array('amount' => '10.00', 'currency' => 'USD')); 28 | $this->assertInstanceOf('Omnipay\Oppwa\Message\CaptureRequest', $request); 29 | $this->assertSame('10.00', $request->getAmount()); 30 | $this->assertSame('USD', $request->getCurrency()); 31 | } 32 | 33 | public function testAuthorize() 34 | { 35 | $request = $this->gateway->authorize(array('amount' => '10.00', 'currency' => 'USD')); 36 | $this->assertInstanceOf('\Omnipay\Oppwa\Message\AuthorizeRequest', $request); 37 | $this->assertSame('10.00', $request->getAmount()); 38 | $this->assertSame('USD', $request->getCurrency()); 39 | } 40 | 41 | public function testVoid() 42 | { 43 | $request = $this->gateway->void(array('transactionReference' => '123')); 44 | $this->assertInstanceOf('\Omnipay\Oppwa\Message\VoidRequest', $request); 45 | $this->assertSame('123', $request->getTransactionReference()); 46 | } 47 | 48 | public function testRefund() 49 | { 50 | $request = $this->gateway->refund(array('transactionReference' => '123')); 51 | $this->assertInstanceOf('\Omnipay\Oppwa\Message\RefundRequest', $request); 52 | $this->assertSame('123', $request->getTransactionReference()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Message/AbstractRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('integrationType'); 16 | } 17 | 18 | public function setIntegrationType($value) 19 | { 20 | return $this->setParameter('integrationType', $value); 21 | } 22 | 23 | public function getToken() 24 | { 25 | return $this->getParameter('token'); 26 | } 27 | 28 | public function setToken($value) 29 | { 30 | return $this->setParameter('token', $value); 31 | } 32 | 33 | public function getEntityId() 34 | { 35 | return $this->getParameter('entityId'); 36 | } 37 | 38 | public function setEntityId($value) 39 | { 40 | return $this->setParameter('entityId', $value); 41 | } 42 | 43 | protected function getEndpoint() 44 | { 45 | $base = $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint; 46 | return $base . '/' . self::API_VERSION; 47 | } 48 | 49 | protected function getHttpMethod() 50 | { 51 | return 'POST'; 52 | } 53 | 54 | public function sendData($data) 55 | { 56 | $params = array( 57 | 'entityId' => $this->getEntityId() 58 | ); 59 | 60 | $http_query = $this->getHttpMethod() === 'GET' ? '?' . http_build_query($params) : ''; 61 | $body = $this->getHttpMethod() === 'POST' ? array_merge($params, $data) : null; 62 | 63 | $httpResponse = $this->httpClient->request( 64 | $this->getHttpMethod(), 65 | $this->getEndpoint() . $http_query, 66 | array( 67 | 'Content-Type' => 'application/x-www-form-urlencoded', 68 | 'Authorization' => 'Bearer '.$this->getToken() 69 | ), 70 | $body ? http_build_query($body) : null 71 | ); 72 | 73 | return $this->response = new Response( 74 | $this, 75 | json_decode($httpResponse->getBody(), true), 76 | $httpResponse->getStatusCode() 77 | ); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /src/Message/Response.php: -------------------------------------------------------------------------------- 1 | statusCode = $statusCode; 17 | } 18 | 19 | public function isSuccessful() 20 | { 21 | if ($this->getCode() >= 400) { 22 | return false; 23 | } 24 | 25 | list( $first, $second, ) = explode('.', (string) $this->data['result']['code']); 26 | 27 | return ! $this->isRedirect() && ! $this->isPending() 28 | && $first == '000' && $second < '200'; 29 | } 30 | 31 | public function isRedirect() 32 | { 33 | return isset($this->data['redirect']['url']); 34 | } 35 | 36 | public function isPending() 37 | { 38 | return isset($this->data['result']['code']) && substr($this->data['result']['code'], 0, 7) == '000.200'; 39 | } 40 | 41 | public function getTransactionReference() 42 | { 43 | if (isset($this->data['id'])) { 44 | return $this->data['id']; 45 | } 46 | } 47 | 48 | public function getTransactionId() 49 | { 50 | if (isset($this->data['merchantTransactionId'])) { 51 | return $this->data['merchantTransactionId']; 52 | } 53 | } 54 | 55 | public function getRedirectUrl() 56 | { 57 | if ($this->isRedirect()) { 58 | return $this->data['redirect']['url']; 59 | } 60 | } 61 | 62 | public function getRedirectMethod() 63 | { 64 | return 'POST'; 65 | } 66 | 67 | public function getRedirectData() 68 | { 69 | $list = array(); 70 | 71 | foreach ($this->data['redirect']['parameters'] as $pair) { 72 | $list[$pair['name']] = $pair['value']; 73 | } 74 | 75 | return $list; 76 | } 77 | 78 | public function getMessage() 79 | { 80 | if (isset($this->data['result']['description'])) { 81 | return $this->data['result']['description']; 82 | } 83 | 84 | return null; 85 | } 86 | 87 | public function getCode() 88 | { 89 | return $this->statusCode; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/Gateway.php: -------------------------------------------------------------------------------- 1 | '', 21 | 'entityId' => '', 22 | 'integrationType' => self::TYPE_SERVER_TO_SERVER 23 | ); 24 | } 25 | 26 | public function getIntegrationType() 27 | { 28 | return $this->getParameter('integrationType'); 29 | } 30 | 31 | public function setIntegrationType($value) 32 | { 33 | return $this->setParameter('integrationType', $value); 34 | } 35 | 36 | public function getToken() 37 | { 38 | return $this->getParameter('token'); 39 | } 40 | 41 | public function setToken($value) 42 | { 43 | return $this->setParameter('token', $value); 44 | } 45 | 46 | public function getEntityId() 47 | { 48 | return $this->getParameter('entityId'); 49 | } 50 | 51 | public function setEntityId($value) 52 | { 53 | return $this->setParameter('entityId', $value); 54 | } 55 | 56 | public function authorize(array $options = array()) 57 | { 58 | return $this->createRequest('\Omnipay\Oppwa\Message\AuthorizeRequest', $options); 59 | } 60 | 61 | public function completeAuthorize(array $options = array()) 62 | { 63 | return $this->createRequest('\Omnipay\Oppwa\Message\FetchTransactionRequest', $options); 64 | } 65 | 66 | public function capture(array $options = array()) 67 | { 68 | return $this->createRequest('\Omnipay\Oppwa\Message\CaptureRequest', $options); 69 | } 70 | 71 | public function purchase(array $options = array()) 72 | { 73 | return $this->createRequest('\Omnipay\Oppwa\Message\PurchaseRequest', $options); 74 | } 75 | 76 | public function completePurchase(array $options = array()) 77 | { 78 | return $this->createRequest('\Omnipay\Oppwa\Message\FetchTransactionRequest', $options); 79 | } 80 | 81 | public function refund(array $options = array()) 82 | { 83 | return $this->createRequest('\Omnipay\Oppwa\Message\RefundRequest', $options); 84 | } 85 | 86 | public function void(array $options = array()) 87 | { 88 | return $this->createRequest('\Omnipay\Oppwa\Message\VoidRequest', $options); 89 | } 90 | 91 | public function acceptNotification(array $options = array()) 92 | { 93 | return $this->createRequest('\Omnipay\Oppwa\Message\ServerNotifyRequest', $options); 94 | } 95 | 96 | public function fetchTransaction(array $options = array()) 97 | { 98 | return $this->createRequest('\Omnipay\Oppwa\Message\FetchTransactionRequest', $options); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/Message/AuthorizeRequest.php: -------------------------------------------------------------------------------- 1 | getParameter('bankAccount'); 12 | } 13 | 14 | public function setBankAccount($data) 15 | { 16 | return $this->setParameter('bankAccount', $data); 17 | } 18 | 19 | public function getCustomerGivenName() 20 | { 21 | return $this->getParameter('customerGivenName'); 22 | } 23 | 24 | public function setCustomerGivenName($value) 25 | { 26 | return $this->setParameter('customerGivenName', $value); 27 | } 28 | 29 | public function getCustomerSurname() 30 | { 31 | return $this->getParameter('customerSurname'); 32 | } 33 | 34 | public function setCustomerSurname($value) 35 | { 36 | return $this->setParameter('customerSurname', $value); 37 | } 38 | 39 | public function getCustomerEmail() 40 | { 41 | return $this->getParameter('customerEmail'); 42 | } 43 | 44 | public function setCustomerEmail($value) 45 | { 46 | return $this->setParameter('customerEmail', $value); 47 | } 48 | 49 | public function getBillingCity() 50 | { 51 | return $this->getParameter('billingCity'); 52 | } 53 | 54 | public function setBillingCity($value) 55 | { 56 | return $this->setParameter('billingCity', $value); 57 | } 58 | 59 | public function getBillingCountry() 60 | { 61 | return $this->getParameter('billingCountry'); 62 | } 63 | 64 | public function setBillingCountry($value) 65 | { 66 | return $this->setParameter('billingCountry', $value); 67 | } 68 | 69 | public function getBillingState() 70 | { 71 | return $this->getParameter('billingState'); 72 | } 73 | 74 | public function setBillingState($value) 75 | { 76 | return $this->setParameter('billingState', $value); 77 | } 78 | 79 | public function getBillingStreet() 80 | { 81 | return $this->getParameter('billingStreet'); 82 | } 83 | 84 | public function setBillingStreet($value) 85 | { 86 | return $this->setParameter('billingStreet', $value); 87 | } 88 | 89 | public function getBillingPostCode() 90 | { 91 | return $this->getParameter('billingPostCode'); 92 | } 93 | 94 | public function setBillingPostCode($value) 95 | { 96 | return $this->setParameter('billingPostCode', $value); 97 | } 98 | 99 | public function getData() 100 | { 101 | $this->validate('amount', 'currency'); 102 | 103 | $data = array( 104 | 'amount' => $this->getAmount(), 105 | 'currency' => $this->getCurrency(), 106 | 'paymentType' => 'PA', 107 | 'merchantTransactionId' => $this->getTransactionId(), 108 | 'descriptor' => $this->getDescription(), 109 | 'shopperResultUrl' => $this->getReturnUrl(), 110 | 'notificationUrl' => $this->getNotifyUrl(), 111 | 'customer.ip' => $this->getClientIp() 112 | ); 113 | 114 | $extra = array( 115 | 'customer.givenName' => $this->getCustomerGivenName(), 116 | 'customer.surname' => $this->getCustomerSurname(), 117 | 'customer.email' => $this->getCustomerEmail(), 118 | 'billing.country' => $this->getBillingCountry(), 119 | 'billing.city' => $this->getBillingCity(), 120 | 'billing.state' => $this->getBillingState(), 121 | 'billing.postcode' => $this->getBillingPostCode(), 122 | 'billing.street1' => $this->getBillingStreet() 123 | ); 124 | 125 | $data = array_merge($data, array_filter($extra)); 126 | 127 | if ($this->getBankAccount()) { 128 | foreach ($this->getBankAccount() as $key => $value) { 129 | $data['bankAccount.' . $key] = $value; 130 | } 131 | } 132 | 133 | if ($this->getPaymentMethod()) { 134 | $data['paymentBrand'] = strtoupper($this->getPaymentMethod()); 135 | } 136 | 137 | if ($this->getCard()) { 138 | $data = array_merge($data, $this->getCardData()); 139 | } 140 | 141 | return $data; 142 | } 143 | 144 | protected function getCardData() 145 | { 146 | $this->getCard()->validate(); 147 | 148 | return array( 149 | 'paymentBrand' => strtoupper($this->getBrand()), 150 | 'card.holder' => $this->getCard()->getName(), 151 | 'card.number' => $this->getCard()->getNumber(), 152 | 'card.expiryMonth' => $this->getCard()->getExpiryDate('m'), 153 | 'card.expiryYear' => $this->getCard()->getExpiryDate('Y'), 154 | 'card.cvv' => $this->getCard()->getCvv() 155 | ); 156 | } 157 | 158 | public function getBrand() 159 | { 160 | $mapper = [ 161 | 'mastercard' => 'master', 162 | 'diners_club' => 'diners' 163 | ]; 164 | 165 | if (array_key_exists($this->getCard()->getBrand(), $mapper)) { 166 | return $mapper[$this->getCard()->getBrand()]; 167 | } 168 | 169 | return $this->getCard()->getBrand(); 170 | } 171 | 172 | protected function getEndpoint() 173 | { 174 | if ($this->getIntegrationType() === Gateway::TYPE_SERVER_TO_SERVER) { 175 | return parent::getEndpoint() . '/payments'; 176 | } 177 | 178 | if ($this->getIntegrationType() === Gateway::TYPE_COPY_AND_PASTE) { 179 | return parent::getEndpoint() . '/checkouts'; 180 | } 181 | 182 | throw new \LogicException("Unknown integrationType {$this->getIntegrationType()}"); 183 | } 184 | } 185 | --------------------------------------------------------------------------------