Skip to content

Commit

Permalink
Merge pull request #9 from solverat/query_modifier_fix
Browse files Browse the repository at this point in the history
fix modifier query
  • Loading branch information
solverat authored Feb 26, 2021
2 parents 00a8e2f + d90c7aa commit af0958f
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 55 deletions.
4 changes: 4 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
language: php

env:
global:
- XDEBUG_MODE=coverage

cache:
directories:
- $HOME/.composer/cache
Expand Down
16 changes: 4 additions & 12 deletions Action/CaptureAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
use Karser\PayumSaferpay\Request\Api\InitPaymentPage;
use Karser\PayumSaferpay\Request\Api\InitTransaction;
use League\Uri\Http as HttpUri;
use League\Uri\Modifiers\MergeQuery;
use League\Uri\UriModifier;
use Payum\Core\Action\ActionInterface;
use Payum\Core\ApiAwareInterface;
use Payum\Core\ApiAwareTrait;
Expand Down Expand Up @@ -135,17 +135,9 @@ private function handleTransactionInterface(Capture $request)

private function composeReturnUrls(string $url): array
{
$successUrl = HttpUri::createFromString($url);
$modifier = new MergeQuery('success=1');
$successUrl = $modifier->process($successUrl);

$failedUrl = HttpUri::createFromString($url);
$modifier = new MergeQuery('fail=1');
$failedUrl = $modifier->process($failedUrl);

$cancelUri = HttpUri::createFromString($url);
$modifier = new MergeQuery('abort=1');
$cancelUri = $modifier->process($cancelUri);
$successUrl = UriModifier::mergeQuery(HttpUri::createFromString($url), 'success=1');
$failedUrl = UriModifier::mergeQuery(HttpUri::createFromString($url), 'fail=1');
$cancelUri = UriModifier::mergeQuery(HttpUri::createFromString($url), 'abort=1');

return [
'Success' => (string) $successUrl,
Expand Down
16 changes: 4 additions & 12 deletions Action/InsertCardAliasAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Karser\PayumSaferpay\Request\Api\InsertAlias;
use Karser\PayumSaferpay\Request\InsertCardAlias;
use League\Uri\Http as HttpUri;
use League\Uri\Modifiers\MergeQuery;
use League\Uri\UriModifier;
use Payum\Core\Action\ActionInterface;
use Payum\Core\Bridge\Spl\ArrayObject;
use Payum\Core\Exception\RequestNotSupportedException;
Expand Down Expand Up @@ -53,17 +53,9 @@ private function insertAliasAction(InsertCardAlias $request, ArrayObject $model)
if (empty($model['ReturnUrls'])) {
$token = $request->getToken();

$successUrl = HttpUri::createFromString($token->getTargetUrl());
$modifier = new MergeQuery('success=1');
$successUrl = $modifier->process($successUrl);

$failedUrl = HttpUri::createFromString($token->getTargetUrl());
$modifier = new MergeQuery('fail=1');
$failedUrl = $modifier->process($failedUrl);

$cancelUri = HttpUri::createFromString($token->getTargetUrl());
$modifier = new MergeQuery('abort=1');
$cancelUri = $modifier->process($cancelUri);
$successUrl = UriModifier::mergeQuery(HttpUri::createFromString($token->getTargetUrl()), 'success=1');
$failedUrl = UriModifier::mergeQuery(HttpUri::createFromString($token->getTargetUrl()), 'fail=1');
$cancelUri = UriModifier::mergeQuery(HttpUri::createFromString($token->getTargetUrl()), 'abort=1');

$model['ReturnUrls'] = [
'Success' => (string) $successUrl,
Expand Down
9 changes: 4 additions & 5 deletions Tests/Unit/Action/CaptureActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@ public function shouldImplementGatewayAwareInterface(): void
$this->assertTrue($rc->implementsInterface(GatewayAwareInterface::class));
}

public function provideSupportedRequests(): array
public function provideSupportedRequests(): \Iterator
{
($r1 = new Capture(new Token()))->setModel(array());
($r2 = new Capture(new Token()))->setModel(new \ArrayObject());
return [
[$r1],
[$r2],
];

yield [$r1];
yield [$r2];
}

/**
Expand Down
6 changes: 2 additions & 4 deletions Tests/Unit/Action/CaptureReferencedActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,9 @@ public function couldBeConstructedWithoutAnyArguments(): void
/**
* Overridden because CaptureAction requires request to have TOKEN
*/
public function provideSupportedRequests(): array
public function provideSupportedRequests(): \Iterator
{
return [
[new CaptureReferenced(new Payment())],
];
yield [new CaptureReferenced(new Payment())];
}

}
31 changes: 15 additions & 16 deletions Tests/Unit/Action/ConvertPaymentActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,24 @@ public function couldBeConstructedWithoutAnyArguments(): void
self::assertNotNull(new $this->actionClass());
}

public function provideSupportedRequests()
public function provideSupportedRequests(): \Iterator
{
return array(
array(new $this->requestClass(new Payment(), 'array')),
array(new $this->requestClass($this->createMock(PaymentInterface::class), 'array')),
array(new $this->requestClass(new Payment(), 'array', $this->createMock('Payum\Core\Security\TokenInterface'))),
);
yield [new $this->requestClass(new Payment(), 'array')];
yield [new $this->requestClass($this->createMock(PaymentInterface::class), 'array')];
yield [new $this->requestClass(new Payment(), 'array', $this->createMock('Payum\Core\Security\TokenInterface'))];

}
public function provideNotSupportedRequests()

public function provideNotSupportedRequests(): \Iterator
{
return array(
array('foo'),
array(array('foo')),
array(new \stdClass()),
array($this->getMockForAbstractClass(Generic::class, array(array()))),
array(new $this->requestClass(new \stdClass(), 'array')),
array(new $this->requestClass(new Payment(), 'foobar')),
array(new $this->requestClass($this->createMock(PaymentInterface::class), 'foobar')),
);
yield ['foo'];
yield [['foo']];
yield [new \stdClass()];
yield [$this->getMockForAbstractClass(Generic::class, [[]])];
yield [new $this->requestClass(new \stdClass(), 'array')];
yield [new $this->requestClass(new Payment(), 'foobar')];
yield [new $this->requestClass($this->createMock(PaymentInterface::class), 'foobar')];

}

/**
Expand Down
8 changes: 3 additions & 5 deletions Tests/Unit/Action/InsertCardAliasActionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function couldBeConstructedWithoutAnyArguments(): void
self::assertNotNull(new $this->actionClass());
}

public function provideSupportedRequests(): array
public function provideSupportedRequests(): \Iterator
{
function getRequest($details) {
$alias = new CardAlias();
Expand All @@ -52,9 +52,7 @@ function getRequest($details) {
return $request;
}

return [
[getRequest(array())],
[getRequest(new \ArrayObject())],
];
yield [getRequest([])];
yield [getRequest(new \ArrayObject())];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
],
"require": {
"php": "^7.2.0",
"payum/core": "^1.5"
"payum/core": "^1.6"
},
"require-dev": {
"fabpot/goutte": "^3.3",
Expand Down

0 comments on commit af0958f

Please sign in to comment.