Skip to content

Commit

Permalink
inital commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mediabeastnz committed Feb 7, 2019
0 parents commit 339bce9
Show file tree
Hide file tree
Showing 17 changed files with 704 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
; This file is for unifying the coding style for different editors and IDEs.
; More information at http://editorconfig.org

root = true

[*]
charset = utf-8
indent_size = 4
indent_style = space
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/vendor
composer.lock
composer.phar
phpunit.xml
.DS_Store
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Release Notes for Laybuy gateway for Omnipay

## 0.9.0 - 2019-02-03
### Added
- Initial release which includes basic tests and updated dependencies.
- Built for Omnipay 2.
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Contributing

Submit a pull request on Github to get started.

## Testing
Test test test. If you're adding functionality ensure you also create a test to ensure we don't introduce breaking changes or bugs.

## Running Tests

``` bash
$ composer install
$ composer test
```
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Myles Derham

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.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# omnipay-laybuy
Laybuy gateway for Omnipay payment processing library
4 changes: 4 additions & 0 deletions bootstrap.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?php
ini_set('error_reporting', E_ALL); // or error_reporting(E_ALL);
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
37 changes: 37 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"name": "mediabeastnz/omnipay-laybuy",
"type": "library",
"version": "0.9.0",
"description": "Laybuy gateway for Omnipay payment processing library",
"keywords": [
"lay buy",
"laybuy",
"merchant",
"omnipay",
"pay",
"payment",
"gateway"
],
"homepage": "https://github.com/mediabeastnz/omnipay-laybuy",
"license": "MIT",
"authors": [
{
"name": "Myles Derham",
"email": "myles.derham@gmail.com"
}
],
"autoload": {
"psr-4": {
"Omnipay\\Laybuy\\" : "src/"
}
},
"scripts": {
"test": "phpunit"
},
"require": {
"omnipay/common": "~2.0"
},
"require-dev": {
"omnipay/tests": "~2.0"
}
}
25 changes: 25 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap.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>
95 changes: 95 additions & 0 deletions src/Gateway.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php

namespace Omnipay\Laybuy;

use Omnipay\Common\AbstractGateway;

class Gateway extends AbstractGateway
{
/**
* @return string
*/
public function getName()
{
return 'Laybuy';
}

/**
* @return array
*/
public function getDefaultParameters()
{
return array(
'merchantId' => '',
'merchantSecret' => '',
'testMode' => false,
);
}

/**
* @return mixed
*/
public function getMerchantId()
{
return $this->getParameter('merchantId');
}

/**
* @param mixed $value
* @return $this
*/
public function setMerchantId($value)
{
return $this->setParameter('merchantId', $value);
}

/**
* @return mixed
*/
public function getMerchantSecret()
{
return $this->getParameter('merchantSecret');
}

/**
* @param mixed $value
* @return $this
*/
public function setMerchantSecret($value)
{
return $this->setParameter('merchantSecret', $value);
}

/**
* Configuration Request.
*
* @param array $options
* @return \Omnipay\Laybuy\Message\AuthorizeRequest
*/
public function authorize(array $options = array())
{
return $this->createRequest('\Omnipay\Laybuy\Message\AuthorizeRequest', $options);
}

/**
* Authorize and immediately capture an amount on the customers card
*
* @param array $options
* @return \Omnipay\Common\Message\ResponseInterface
*/
public function purchase(array $options = array())
{
return $this->createRequest('\Omnipay\Laybuy\Message\PurchaseRequest', $options);
}

/**
* Handle return from off-site gateways after purchase
*
* @param array $options
* @return \Omnipay\Common\Message\ResponseInterface
*/
public function completePurchase(array $options = array())
{
return $this->createRequest('\Omnipay\Laybuy\Message\CompletePurchaseRequest', $options);
}
}
127 changes: 127 additions & 0 deletions src/Message/AuthorizeRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?php

namespace Omnipay\Laybuy\Message;

use Omnipay\Common\Message\AbstractRequest;
use Omnipay\Common\Message\ResponseInterface;

class AuthorizeRequest extends AbstractRequest
{
protected $liveEndpoint = 'https://api.laybuy.com';

protected $testEndpoint = 'https://sandbox-api.laybuy.com';

/**
* @return mixed
*/
public function getMerchantId()
{
return $this->getParameter('merchantId');
}

/**
* @param mixed $value
* @return $this
* @throws \Omnipay\Common\Exception\RuntimeException
*/
public function setMerchantId($value)
{
return $this->setParameter('merchantId', $value);
}

/**
* @return mixed
*/
public function getMerchantSecret()
{
return $this->getParameter('merchantSecret');
}

/**
* @param mixed $value
* @return $this
* @throws \Omnipay\Common\Exception\RuntimeException
*/
public function setMerchantSecret($value)
{
return $this->setParameter('merchantSecret', $value);
}

/**
* @return array
*/
public function getHeaders()
{
$headers = [];
return $headers;
}

public function getData()
{
$this->validate('merchantId');
}

/**
* @param mixed $data
* @return \Omnipay\Laybuy\Message\Response
* @throws \Guzzle\Http\Exception\RequestException
*/
public function sendData($data)
{
$endpoint = $this->getEndpoint();
$httpMethod = $this->getHttpMethod();
$httpRequest = $this->httpClient->createRequest($httpMethod, $endpoint);
$httpRequest->getCurlOptions()->set(CURLOPT_SSLVERSION, 6); // CURL_SSLVERSION_TLSv1_2
$httpRequest->addHeader('Authorization', $this->buildAuthorizationHeader());
$httpRequest->addHeader('Content-type', 'application/json');
$httpRequest->addHeader('Accept', 'application/json');
$httpRequest->setBody(json_encode($data));
$httpResponse = $httpRequest->send();
return $this->createResponse($httpResponse);
}

/**
* @return string
*/
public function getHttpMethod()
{
return 'POST';
}

/**
* @return string
*/
protected function getEndpoint()
{
return $this->getTestMode() ? $this->testEndpoint : $this->liveEndpoint;
}

/**
* @param \Guzzle\Http\Message\Response $httpResponse
* @return array
*/
// protected function parseResponseData(Guzzle\Http\Message\Response $httpResponse)
// {
// return $httpResponse->json();
// }

/**
* @param mixed $data
* @return \Omnipay\Laybuy\Message\Response
*/
protected function createResponse($data)
{
return new Response($this, $data);
}

/**
* @return string
*/
protected function buildAuthorizationHeader()
{
$merchantId = $this->getMerchantId();
$merchantSecret = $this->getMerchantSecret();

return 'Basic ' . base64_encode($merchantId . ':' . $merchantSecret);
}
}
27 changes: 27 additions & 0 deletions src/Message/CompletePurchaseRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Omnipay\Laybuy\Message;

class CompletePurchaseRequest extends AuthorizeRequest
{
/**
* 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
*/
public function getData()
{
return array(
'token' => $this->getToken()
);
}

/**
* @return string
*/
public function getEndpoint()
{
return parent::getEndpoint() . '/order/confirm';
}
}
Loading

0 comments on commit 339bce9

Please sign in to comment.