Skip to content

Commit

Permalink
Merge pull request #1 from digitickets/standardising-mods
Browse files Browse the repository at this point in the history
Adding standard package features
  • Loading branch information
nicksnellockdt authored Oct 19, 2018
2 parents dac9ea1 + 3384cf9 commit ac175f2
Show file tree
Hide file tree
Showing 14 changed files with 181 additions and 101 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea/
vendor/
vendor/
.php_cs.cache
composer.lock
23 changes: 23 additions & 0 deletions .scrutinizer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
filter:
excluded_paths: [tests/*]

checks:
php:
remove_extra_empty_lines: true
remove_php_closing_tag: true
remove_trailing_whitespace: true
fix_use_statements:
remove_unused: true
preserve_multiple: false
preserve_blanklines: true
order_alphabetically: true
fix_php_opening_tag: true
fix_linefeed: true
fix_line_ending: true
fix_identation_4spaces: true
fix_doc_comments: true

tools:
external_code_coverage:
timeout: 600
runs: 3
69 changes: 31 additions & 38 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,53 +7,46 @@ git:

matrix:
include:
- php: 5.5
- php: 5.6
- php: 7.0
env: PHPSTAN=true COVERAGE=true
- php: 7.1
- php: 7.2
env: PHPSTAN=true
- php: nightly
- php: hhvm
sudo: required
dist: trusty
group: edge
- php: 7.0
env: PHPSTAN=true COVERAGE=true
- php: 7.1
- php: 7.2
env: PHPSTAN=true
- php: nightly
- php: hhvm
sudo: required
dist: trusty
group: edge
allow_failures:
- php: nightly
- php: nightly
- php: 7.2

cache:
directories:
- $HOME/.composer/cache
- $HOME/.php-cs-fixer
- $HOME/.composer/cache
- $HOME/.php-cs-fixer

before_install:
- source .travis/xdebug.sh
- xdebug-disable
- source .travis/xdebug.sh
- xdebug-disable

before_script:
- travis_retry composer self-update
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist -vvv --profile
- travis_retry composer self-update
- travis_retry composer update ${COMPOSER_FLAGS} --no-interaction --prefer-dist -vvv --profile

script:
- if [[ $PHPSTAN == "true" ]]; then
composer require --dev phpstan/phpstan:^0.6 && vendor/bin/phpstan analyse -c phpstan.neon -l 3 src;
fi
- if [[ "$COVERAGE" == "true" ]]; then
xdebug-enable;
vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml;
xdebug-disable;
else
vendor/bin/phpunit;
fi


after_script:
- if [[ "$COVERAGE" == "true" ]]; then
php vendor/bin/ocular code-coverage:upload --format=php-clover coverage.clover
fi
- if [[ $PHPSTAN == "true" ]]; then
composer require --dev phpstan/phpstan:^0.6 && vendor/bin/phpstan analyse -c phpstan.neon -l 3 src;
fi;
- if [[ "$COVERAGE" == "true" ]]; then
xdebug-enable;
vendor/bin/phpunit --coverage-text --coverage-clover build/logs/clover.xml;
xdebug-disable;
else
vendor/bin/phpunit;
fi;

after_success:
- if [[ "$COVERAGE" == "true" ]]; then
travis_retry php vendor/bin/coveralls
fi
- if [[ "$COVERAGE" == "true" ]]; then
travis_retry php vendor/bin/coveralls;
fi;
22 changes: 22 additions & 0 deletions .travis/xdebug.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/usr/bin/env bash

# The problem is that we do not want to remove the configuration file, just disable it for a few tasks, then enable it
#
# For reference, see
#
# - https://docs.travis-ci.com/user/languages/php#Disabling-preinstalled-PHP-extensions
# - https://docs.travis-ci.com/user/languages/php#Custom-PHP-configuration

config="/home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini"

function xdebug-disable() {
if [[ -f $config ]]; then
mv $config "$config.bak"
fi
}

function xdebug-enable() {
if [[ -f "$config.bak" ]]; then
mv "$config.bak" $config
fi
}
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
Omnipay implementation of the Pay360 payment gateway.

[![Build Status](https://travis-ci.org/digitickets/omnipay-pay360.png?branch=master)](https://travis-ci.org/digitickets/omnipay-pay360)
[![Coverage Status](https://coveralls.io/repos/github/digitickets/omnipay-pay360/badge.svg?branch=master)](https://coveralls.io/github/digitickets/omnipay-pay360?branch=master)
[![Latest Stable Version](https://poser.pugx.org/digitickets/omnipay-pay360/version.png)](https://packagist.org/packages/digitickets/omnipay-pay360)
[![Total Downloads](https://poser.pugx.org/digitickets/omnipay-pay360/d/total.png)](https://packagist.org/packages/digitickets/omnipay-pay360)

Expand Down
17 changes: 12 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,18 @@
}
},
"require": {
"omnipay/common": "~2.0"
"omnipay/common": "~2.0",
"php": "^7",
"symfony/event-dispatcher": "^2.8"
},
"require-dev": {
"omnipay/tests": "~2.0"
"friendsofphp/php-cs-fixer": "^2.0",
"omnipay/tests": "~2.0",
"satooshi/php-coveralls": "^1.0"
},
"minimum-stability": "dev",
"prefer-stable": true
}
"scripts": {
"run-sa": "vendor/bin/phpstan analyse --ansi --no-progress -c phpstan.neon -l 4 src tests",
"run-fixer": "vendor/bin/php-cs-fixer fix",
"run-tests": "vendor/bin/phpunit"
}
}
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
autoload_files:
- vendor/autoload.php
ignoreErrors:
- '#Access to an undefined property scpService_credentials::\$identifier#' # bad wsdl missing bits
- '#\(token\) does not accept string#' # wsdl defines "token" but doesn't reference it properly
7 changes: 5 additions & 2 deletions src/Messages/CompletePurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,16 @@

namespace DigiTickets\Pay360\Messages;

use Omnipay\Common\Message\AbstractRequest;
use Omnipay\Common\Message\AbstractResponse;

class CompletePurchaseResponse extends AbstractResponse
{
public function getTransactionId()
{
return $this->getRequest()->getTransactionId();
/** @var CompletePurchaseRequest|AbstractRequest $request */
$request = $this->getRequest();
return $request->getTransactionId();
}

public function getTransactionReference()
Expand All @@ -30,4 +33,4 @@ public function isSuccessful()
{
return $this->getData()->paymentResult->status == 'SUCCESS';
}
}
}
9 changes: 6 additions & 3 deletions src/Messages/PurchaseRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,19 @@ public function setFundCode($value)

public function getData()
{
$this->validate('returnUrl','cancelUrl','routingSiteId','routingScpId','amount');

$routing = new \scpService_routing();
$routing->returnUrl = $this->getReturnUrl();
$routing->backUrl = $this->getBackUrl();
$routing->siteId = $this->getRoutingSiteId();
$routing->scpId = $this->getRoutingScpId();

$saleSummary = new \scpService_summaryData();
$saleSummary->description = 'Online Sale';
$saleSummary->amountInMinorUnits = (int) (100 * $this->getAmount());
$saleSummary->description = $this->getTransactionReference();
$saleSummary->amountInMinorUnits = $this->getAmountInteger();

/** @var \scpService_simpleItem[]|\scpService_items $items */
$items = [];
$lineId = 1;
/** @var \Omnipay\Common\Item $itemBagItem */
Expand Down Expand Up @@ -123,4 +126,4 @@ public function sendData($data)

return $this->response = new PurchaseResponse($this, $scpSimpleInvokeResponse);
}
}
}
8 changes: 7 additions & 1 deletion src/Messages/PurchaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ class PurchaseResponse extends AbstractResponse implements RedirectResponseInter
*/
private $message;

/**
* @var string
*/
private $transactionRef;

/**
* PurchaseResponse constructor.
* @param PurchaseRequest $purchaseRequest
Expand All @@ -42,6 +47,7 @@ public function __construct(
PurchaseRequest $purchaseRequest,
$scpResponse = null
) {
parent::__construct($purchaseRequest, $scpResponse);
if (!($scpResponse instanceof \Throwable)) {
if (isset($scpResponse->invokeResult)) {
$this->setCode($scpResponse->invokeResult->status);
Expand Down Expand Up @@ -105,4 +111,4 @@ public function getCode()
{
return $this->code;
}
}
}
63 changes: 23 additions & 40 deletions src/SimpleInterfaceGateway.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,29 @@
use DigiTickets\Pay360\Messages\CompletePurchaseRequest;
use DigiTickets\Pay360\Messages\PurchaseRequest;
use Omnipay\Common\AbstractGateway;
use Omnipay\Common\Message\RequestInterface;


/**
* GoCardless Gateway
*
* @method RequestInterface authorize(array $options = array()) (Optional method)
* Authorize an amount on the customers card
* @method RequestInterface completeAuthorize(array $options = array()) (Optional method)
* Handle return from off-site gateways after authorization
* @method RequestInterface capture(array $options = array()) (Optional method)
* Capture an amount you have previously authorized
* @method RequestInterface void(array $options = array()) (Optional method)
* Generally can only be called up to 24 hours after submitting a transaction
* @method RequestInterface createCard(array $options = array()) (Optional method)
* The returned response object includes a cardReference, which can be used for future transactions
* @method RequestInterface updateCard(array $options = array()) (Optional method)
* Update a stored card
* @method RequestInterface deleteCard(array $options = array()) (Optional method)
* Delete a stored card
* @method RequestInterface refund(array $options = array()) (Optional method)
* Process a refund
*/

class SimpleInterfaceGateway extends AbstractGateway
{
Expand All @@ -27,44 +50,4 @@ public function completePurchase(array $parameters = array())
{
return $this->createRequest(CompletePurchaseRequest::class, $parameters);
}

public function completeAuthorize()
{
throw new \Exception('Method not implemented', 500);
}

public function deleteCard(array $parameters = array())
{
throw new \Exception('Method not implemented', 500);
}

public function authorize()
{
throw new \Exception('Method not implemented', 500);
}

public function void()
{
throw new \Exception('Method not implemented', 500);
}

public function capture()
{
throw new \Exception('Method not implemented', 500);
}

public function createCard()
{
throw new \Exception('Method not implemented', 500);
}

public function updateCard()
{
throw new \Exception('Method not implemented', 500);
}

public function refund()
{
throw new \Exception('Method not implemented', 500);
}
}
8 changes: 7 additions & 1 deletion tests/AbstractPay360RequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,13 @@ public function getCredentials()
{
return parent::getCredentials();
}
};

public function getEndpoint()
{
return parent::getEndpoint();
}
};
$message->setTestMode(TRUE);
$message->setCredentialsIdentifier('credentials identifier');
$message->setRoutingScpId('routing scpid');
$message->setRoutingSiteId('routing siteid');
Expand All @@ -48,6 +53,7 @@ public function getCredentials()
$this->assertEquals('Original', $message->getCredentials()->signature->algorithm);
$this->assertEquals('hmac key id', $message->getCredentials()->signature->hmacKeyID);
$this->assertEquals('credentials identifier', $message->getCredentials()->identifier);
$this->assertEquals($message::SERVICE_ENDPOINT_TEST, $message->getEndpoint());
}

public function testGenerateDigest()
Expand Down
23 changes: 15 additions & 8 deletions tests/Messages/PurchaseRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,32 @@ public function testGetData()
$request = Mockery::mock(\Symfony\Component\HttpFoundation\Request::class);

$request = new PurchaseRequest($client, $request);

$request->setAmount(10.00);
$request->setReturnUrl('https://www.example.com/return');
$request->setCancelUrl('https://www.example.com/cancel');
$request->setReference('reference');
$request->initialize(
[
'amount' => 12.34,
'returnUrl' => 'https://www.example.com/return',
'cancelUrl' => 'https://www.example.com/cancel',
'reference' => 'reference',
'routingSiteID'=>'1231331',
'routingScpId'=>24978567
]
);
$ref = "Hello Ma!";
$request->setTransactionReference($ref);
$request->setFundCode(8);
$request->setItems(
[
[
'description' => 'item 1',
'price' => 10.00,
'quantity' => 1,
]
],
]
);

$this->assertInstanceOf(\scpService_scpSimpleInvokeRequest::class, $request->getData());
$this->assertEquals('1000', $request->getData()->sale->saleSummary->amountInMinorUnits);
$this->assertEquals('Online Sale', $request->getData()->sale->saleSummary->description);
$this->assertEquals('1234', $request->getData()->sale->saleSummary->amountInMinorUnits);
$this->assertEquals($ref, $request->getData()->sale->saleSummary->description);
$this->assertInternalType('array', $request->getData()->sale->items);
$this->assertEquals(1, count($request->getData()->sale->items));
$this->assertInstanceOf(scpService_simpleItem::class, $request->getData()->sale->items[0]);
Expand Down
Loading

0 comments on commit ac175f2

Please sign in to comment.