Skip to content

Commit 20ccae7

Browse files
committed
New version
* add support for direct payments/MOTO * add unit tests to get coverage back to 100% * add explicit PHP version requirement to composer * change to PatronBase forks of common & tests * change from Travis to Github Actions * update composer dependencies * update PHPUnit config to mimic omnipay-common * fix failing unit test * fix up whitespace/phpcs messages
1 parent c455ece commit 20ccae7

12 files changed

+189
-97
lines changed

.github/workflows/phpunit.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: "PHPUnit tests"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "master"
8+
9+
jobs:
10+
phpunit:
11+
name: "PHPUnit tests"
12+
13+
runs-on: "ubuntu-latest"
14+
15+
strategy:
16+
matrix:
17+
dependencies:
18+
- "highest"
19+
php-version:
20+
- "7.2"
21+
- "7.3"
22+
- "7.4"
23+
- "8.0"
24+
- "8.1"
25+
- "8.2"
26+
- "8.3"
27+
- "8.4"
28+
29+
include:
30+
- php-version: '7.2'
31+
dependencies: "lowest"
32+
33+
steps:
34+
- name: "Checkout"
35+
uses: "actions/checkout@v4"
36+
37+
- name: "Install PHP"
38+
uses: "shivammathur/setup-php@v2"
39+
with:
40+
coverage: "pcov"
41+
php-version: "${{ matrix.php-version }}"
42+
ini-values: memory_limit=-1
43+
tools: composer:v2
44+
45+
- name: "Install lowest dependencies"
46+
if: ${{ matrix.dependencies == 'lowest' }}
47+
run: "composer update --prefer-lowest --no-interaction --no-progress"
48+
49+
- name: "Install highest dependencies"
50+
if: ${{ matrix.dependencies == 'highest' }}
51+
run: "composer update --no-interaction --no-progress"
52+
53+
- name: "Tests"
54+
run: "vendor/bin/phpunit"

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@
22
composer.lock
33
composer.phar
44
phpunit.xml
5+
/.phpunit.result.cache
6+
/build

.travis.yml

Lines changed: 0 additions & 22 deletions
This file was deleted.

composer.json

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,41 @@
3535
"psr-4": { "Omnipay\\Redsys\\" : "tests/" }
3636
},
3737
"require": {
38+
"php": "^7.2|^8.0",
3839
"omnipay/common": "dev-address3-support"
3940
},
4041
"require-dev": {
4142
"omnipay/tests": "dev-address3-support",
42-
"squizlabs/php_codesniffer": "^3.5"
43+
"squizlabs/php_codesniffer": "^3.5",
44+
"http-interop/http-factory-guzzle": "^1.2"
4345
},
4446
"suggest": {
4547
"ext-openssl": "Required for hashing functions to check message signatures"
4648
},
49+
"scripts": {
50+
"test": "phpunit",
51+
"check-style": "phpcs -p --standard=PSR2 src/",
52+
"fix-style": "phpcbf -p --standard=PSR2 src/"
53+
},
4754
"extra": {
4855
"branch-alias": {
49-
"dev-master": "3.2.x-dev"
56+
"dev-master": "4.0.x-dev"
5057
}
5158
},
5259
"repositories": [
5360
{
5461
"type": "vcs",
55-
"url": "https://github.com/CodeDruids/omnipay-common"
62+
"url": "https://github.com/PatronBase/omnipay-common"
5663
},
5764
{
5865
"type": "vcs",
59-
"url": "https://github.com/CodeDruids/omnipay-tests"
66+
"url": "https://github.com/PatronBase/omnipay-tests"
6067
}
6168
],
62-
"prefer-stable": true
69+
"prefer-stable": true,
70+
"config": {
71+
"allow-plugins": {
72+
"php-http/discovery": true
73+
}
74+
}
6375
}

phpunit.xml.dist

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,32 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit backupGlobals="false"
3-
backupStaticAttributes="false"
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
43
bootstrap="vendor/autoload.php"
4+
backupGlobals="false"
5+
backupStaticAttributes="false"
56
colors="true"
7+
verbose="true"
68
convertErrorsToExceptions="true"
79
convertNoticesToExceptions="true"
810
convertWarningsToExceptions="true"
911
processIsolation="false"
1012
stopOnFailure="false"
11-
syntaxCheck="false">
12-
<php>
13-
<ini name="date.timezone" value="UTC" />
14-
</php>
15-
<testsuites>
16-
<testsuite name="Omnipay Test Suite">
17-
<directory>./tests/</directory>
18-
</testsuite>
19-
</testsuites>
20-
<filter>
21-
<whitelist>
22-
<directory>./src</directory>
23-
</whitelist>
24-
</filter>
13+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
14+
<coverage>
15+
<include>
16+
<directory suffix=".php">src/</directory>
17+
</include>
18+
<report>
19+
<clover outputFile="build/logs/clover.xml"/>
20+
<html outputDirectory="build/coverage"/>
21+
<text outputFile="build/coverage.txt"/>
22+
</report>
23+
</coverage>
24+
<testsuites>
25+
<testsuite name="Omnipay Test Suite">
26+
<directory>tests</directory>
27+
</testsuite>
28+
</testsuites>
29+
<logging>
30+
<junit outputFile="build/report.junit.xml"/>
31+
</logging>
2532
</phpunit>

src/Message/PurchaseRequest.php

Lines changed: 48 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ public function getConsumerLanguage()
161161
/**
162162
* Set the language presented to the consumer
163163
*
164-
* @param null|string|int Either the ISO 639-1 code to be converted, or the gateway's own numeric language code
164+
* @param null|string|int $value The ISO 639-1 code to be converted, or the gateway's own numeric language code
165165
*/
166166
public function setConsumerLanguage($value)
167167
{
@@ -177,6 +177,41 @@ public function setConsumerLanguage($value)
177177
return $this->setParameter('consumerLanguage', $value);
178178
}
179179

180+
public function getDirectPayment()
181+
{
182+
return $this->getParameter('directPayment');
183+
}
184+
185+
/**
186+
* Set the "directness" of payment
187+
*
188+
* Can be true (merchant initiated), false/null (customer initiated) or "MOTO" (usually call centre initiated)
189+
* Invalid values will be converted to null as that's the most secure option
190+
*
191+
* @param null|bool|string $value
192+
*/
193+
public function setDirectPayment($value)
194+
{
195+
if (is_bool($value)) {
196+
// this is fine
197+
} elseif (is_string($value)) {
198+
if (strtoupper($value) == "TRUE") {
199+
$value = true;
200+
} elseif (strtoupper($value) == "FALSE") {
201+
$value = false;
202+
} elseif (strtoupper($value) == "MOTO") {
203+
$value = "MOTO";
204+
} else {
205+
// something invalid
206+
$value = null;
207+
}
208+
} else {
209+
// something invalid
210+
$value = null;
211+
}
212+
return $this->setParameter('directPayment', $value);
213+
}
214+
180215
public function getHmacKey()
181216
{
182217
return $this->getParameter('hmacKey');
@@ -278,11 +313,11 @@ public function setUse3DS($value)
278313
}
279314

280315
/**
281-
* Get the threeDSCompInd field
282-
* Corresponds to the Ds_Merchant_Emv3Ds.threeDSCompInd field in Redsys documentation.
316+
* Get the threeDSCompInd field, which indicates whether the 3DSMethod has been executed
283317
*
284-
* @return null|string
318+
* Corresponds to the Ds_Merchant_Emv3Ds.threeDSCompInd field in Redsys documentation.
285319
*
320+
* @return null|string Y = Successfully completed, N = Completed with errors, U = 3DSMethod not executed
286321
*/
287322
public function getThreeDSCompInd()
288323
{
@@ -303,11 +338,11 @@ public function setThreeDSCompInd($value)
303338
}
304339

305340
/**
306-
* Get the threeDSInfo field
307-
* Corresponds to the Ds_Merchant_Emv3Ds.threeDSInfo field in Redsys documentation.
341+
* Get the threeDSInfo field (the type of request)
308342
*
309-
* @return null|string
343+
* Corresponds to the Ds_Merchant_Emv3Ds.threeDSInfo field in Redsys documentation.
310344
*
345+
* @return null|string Possible values: CardData, AuthenticationData, ChallengeResponse
311346
*/
312347
public function getThreeDSInfo()
313348
{
@@ -1682,31 +1717,6 @@ public function setBrowserUserAgent($value)
16821717
return $this->setParameter('browserUserAgent', $value);
16831718
}
16841719

1685-
/**
1686-
* Get the notificationURL field
1687-
*
1688-
* Corresponds to the Ds_Merchant_Emv3Ds.notificationURL field
1689-
*
1690-
* @return null|string
1691-
*/
1692-
public function getNotificationURL()
1693-
{
1694-
return $this->getParameter('notificationURL');
1695-
}
1696-
1697-
/**
1698-
* Set the notificationURL field
1699-
*
1700-
* Corresponds to the Ds_Merchant_Emv3Ds.notificationURL field
1701-
*
1702-
* @param null|string $value
1703-
* @return self
1704-
*/
1705-
public function setNotificationURL($value)
1706-
{
1707-
return $this->setParameter('notificationURL', $value);
1708-
}
1709-
17101720
/**
17111721
* Get the basic data fields that don't require any 3DS/SCA fields
17121722
*/
@@ -1797,6 +1807,11 @@ public function getMerchantRiskData()
17971807
public function getData()
17981808
{
17991809
$data = $this->getBaseData();
1810+
1811+
if ($this->getDirectPayment() !== null) {
1812+
$data['Ds_Merchant_DirectPayment'] = $this->getDirectPayment();
1813+
}
1814+
18001815
if ($this->getScaExemptionIndicator() !== null) {
18011816
$data['Ds_Merchant_Excep_Sca'] = $this->getScaExemptionIndicator();
18021817
}
@@ -1838,11 +1853,9 @@ public function getData()
18381853
'browserScreenWidth' => $this->getBrowserScreenWidth(),
18391854
'browserTZ' => $this->getBrowserTZ(),
18401855
'browserUserAgent' => $this->getBrowserUserAgent(),
1841-
'notificationURL' => $this->getNotificationURL(),
1856+
'notificationURL' => $this->getNotifyUrl(),
18421857
'protocolVersion' => $this->getProtocolVersion(),
1843-
// Indicates whether the 3DSMethod has been executed. Values ​​accepted: Y= Successfully completed, N = Completed with errors, U = 3DSMethod not executed
18441858
'threeDSCompInd' => $this->getThreeDSCompInd(),
1845-
// Type of request. Possible values: CardData, AuthenticationData, ChallengeResponse
18461859
'threeDSInfo' => $this->getThreeDSInfo(),
18471860
'threeDSServerTransID' => $this->getTransactionId(),
18481861
// optional parameters for v2

tests/Message/PurchaseRequestTest.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class PurchaseRequestTest extends TestCase
2626
/** @var mixed[] */
2727
protected $full3DSParams = [];
2828

29-
public function setUp()
29+
public function setUp(): void
3030
{
3131
$this->fullBaseParams = $this->requiredRequestParams + [
3232
'transactionId' => '123abc',
@@ -38,23 +38,24 @@ public function setUp()
3838
'merchantName' => 'My Store',
3939
'consumerLanguage' => 'en',
4040
'merchantData' => 'Ref: 99zz',
41+
'directPayment' => false,
4142
];
4243

4344
$this->full3DSParams = $this->fullBaseParams + [
4445
'use3DS' => true,
4546
'protocolVersion' => '2.1.0',
4647
'threeDSCompInd' => 'U',
47-
'threeDSInfo' => 'CardData',
48+
'threeDSInfo' => 'CardData',
4849
'threeDSServerTransID' => '12345',
4950
'browserAcceptHeader' => 'text/html,application',
50-
'browserColorDepth' => '24',
51-
'browserIP' => '192.0.0.0',
52-
'browserJavaEnabled' => true,
53-
'browserLanguage' => 'en-GB',
54-
'browserScreenHeight' => '1000',
55-
'browserScreenWidth' => '1200',
56-
'browserTZ' => '2',
57-
'browserUserAgent' => 'Mozilla/5.0',
51+
'browserColorDepth' => '24',
52+
'browserIP' => '192.0.0.0',
53+
'browserJavaEnabled' => true,
54+
'browserLanguage' => 'en-GB',
55+
'browserScreenHeight' => '1000',
56+
'browserScreenWidth' => '1200',
57+
'browserTZ' => '2',
58+
'browserUserAgent' => 'Mozilla/5.0',
5859
'card' => new CreditCard([
5960
'email' => "[email protected]",
6061
'shippingAddress1' => "Ship 1 Test",
@@ -159,6 +160,31 @@ public function testSetConsumerLanguage()
159160
$this->assertSame('002', $this->request->getConsumerLanguage());
160161
}
161162

163+
public function testSetDirectPayment()
164+
{
165+
// starts false in base test data
166+
$this->assertFalse($this->request->getDirectPayment());
167+
// valid, but corrects case
168+
$this->request->setDirectPayment("moto");
169+
$this->assertSame('MOTO', $this->request->getDirectPayment());
170+
// valid (effectively unsets)
171+
$this->request->setDirectPayment(null);
172+
$this->assertNull($this->request->getDirectPayment());
173+
// valid
174+
$this->request->setDirectPayment(true);
175+
$this->assertTrue($this->request->getDirectPayment());
176+
$this->request->setDirectPayment(false);
177+
$this->assertFalse($this->request->getDirectPayment());
178+
// valid, but converts to bool
179+
$this->request->setDirectPayment("true");
180+
$this->assertTrue($this->request->getDirectPayment());
181+
$this->request->setDirectPayment("false");
182+
$this->assertFalse($this->request->getDirectPayment());
183+
// invalid, forces back to null
184+
$this->request->setDirectPayment(100);
185+
$this->assertNull($this->request->getDirectPayment());
186+
}
187+
162188
public function testGet3DSAccountInfoData()
163189
{
164190
$data = $this->request->get3DSAccountInfoData();

0 commit comments

Comments
 (0)