Skip to content

Commit f9a292b

Browse files
authored
Merge pull request #5 from PatronBase/stored-card-adjustments
Update stored cards mechanisms, add testing scaffolding
2 parents a29eaf2 + ecca0cf commit f9a292b

File tree

11 files changed

+225
-41
lines changed

11 files changed

+225
-41
lines changed

.github/workflows/main.yml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
name: "Build tests"
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- "main"
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+
env:
45+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
46+
47+
# Fixes any pubkeys failure (add a `composer diagnose` step to debug if necessary)
48+
- name: "Composer force self-update"
49+
run: "composer self-update"
50+
51+
- name: "Install lowest dependencies"
52+
if: ${{ matrix.dependencies == 'lowest' }}
53+
run: "composer update --prefer-lowest --no-interaction --no-progress"
54+
55+
- name: "Install highest dependencies"
56+
if: ${{ matrix.dependencies == 'highest' }}
57+
run: "composer update --no-interaction --no-progress"
58+
59+
- name: "Tests (PHPUnit 9)"
60+
if: ${{ matrix.php-version <= '8.0' }}
61+
run: "vendor/bin/phpunit --configuration phpunit9.xml.dist"
62+
63+
- name: "Tests (PHPUnit 10+)"
64+
if: ${{ matrix.php-version >= '8.1' }}
65+
run: "vendor/bin/phpunit"

.gitignore

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

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 CI build passed. If not, rinse and repeat.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
**Windcave REST API (Hosted Payment Page) driver for the Omnipay PHP payment processing library**
44

5-
[![Build Status](https://travis-ci.org/PatronBase/omnipay-windcave-hpp.png?branch=main)](https://app.travis-ci.com/github/PatronBase/omnipay-windcave-hpp)
5+
![Build Status](https://github.com/PatronBase/omnipay-windcave-hpp/actions/workflows/main.yml/badge.svg?branch=main)
66
[![Coverage Status](https://img.shields.io/scrutinizer/coverage/g/PatronBase/omnipay-windcave-hpp.svg?style=flat)](https://scrutinizer-ci.com/g/PatronBase/omnipay-windcave-hpp/code-structure)
77
[![Code Quality](https://img.shields.io/scrutinizer/g/PatronBase/omnipay-windcave-hpp.svg?style=flat)](https://scrutinizer-ci.com/g/PatronBase/omnipay-windcave-hpp/?branch=main)
88
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)](LICENSE.md)
@@ -11,8 +11,8 @@
1111

1212

1313
[Omnipay](https://github.com/thephpleague/omnipay) is a framework agnostic, multi-gateway payment
14-
processing library for PHP 5.6+. This package implements GoCardless support for Omnipay. It includes
15-
support for the redirect (3-party) version of the gateway (Redirect Flow).
14+
processing library for PHP 7.2+. This package implements Windcave REST API support for Omnipay. It
15+
includes support for the redirect (3-party) version of the gateway (Hosted Payment Page).
1616

1717
## Installation
1818

composer.json

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
"merchant",
1111
"omnipay",
1212
"pay",
13-
"payment"
13+
"payment",
14+
"hosted",
15+
"checkout",
16+
"redirect"
1417
],
1518
"homepage": "https://github.com/PatronBase/omnipay-windcave-hpp",
1619
"license": "MIT",
@@ -22,6 +25,10 @@
2225
{
2326
"name": "Aimal Muhammad",
2427
"email": "[email protected]"
28+
},
29+
{
30+
"name": "Leith Caldwell",
31+
"email": "[email protected]"
2532
}
2633
],
2734
"autoload": {
@@ -35,17 +42,28 @@
3542
}
3643
},
3744
"require": {
38-
"omnipay/common": "^3",
39-
"php": "^7||^8"
45+
"omnipay/common": "^3.1",
46+
"php": "^7.2||^8"
4047
},
4148
"require-dev": {
42-
"omnipay/tests": "^3",
43-
"squizlabs/php_codesniffer": "^3.5"
49+
"omnipay/tests": "^4.2",
50+
"squizlabs/php_codesniffer": "^3.5",
51+
"http-interop/http-factory-guzzle": "^1.1"
52+
},
53+
"scripts": {
54+
"test": "phpunit",
55+
"check-style": "phpcs -p --standard=PSR2 src/",
56+
"fix-style": "phpcbf -p --standard=PSR2 src/"
4457
},
4558
"extra": {
4659
"branch-alias": {
47-
"dev-master": "1.0.x-dev"
60+
"dev-master": "1.1.x-dev"
4861
}
4962
},
50-
"prefer-stable": true
51-
}
63+
"prefer-stable": true,
64+
"config": {
65+
"allow-plugins": {
66+
"php-http/discovery": false
67+
}
68+
}
69+
}

phpunit.xml.dist

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
backupGlobals="false"
6+
backupStaticProperties="false"
7+
colors="true"
8+
processIsolation="false"
9+
stopOnFailure="false">
10+
<coverage>
11+
<report>
12+
<clover outputFile="build/logs/clover.xml"/>
13+
<html outputDirectory="build/coverage"/>
14+
<text outputFile="build/coverage.txt"/>
15+
</report>
16+
</coverage>
17+
<source restrictDeprecations="true" restrictNotices="true" restrictWarnings="true">
18+
<include>
19+
<directory suffix=".php">src/</directory>
20+
</include>
21+
</source>
22+
<testsuites>
23+
<testsuite name="Omnipay Test Suite">
24+
<directory>tests</directory>
25+
</testsuite>
26+
</testsuites>
27+
<logging>
28+
<junit outputFile="build/report.junit.xml"/>
29+
</logging>
30+
</phpunit>

phpunit9.xml.dist

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.6/phpunit.xsd"
4+
bootstrap="vendor/autoload.php"
5+
backupGlobals="false"
6+
backupStaticAttributes="false"
7+
colors="true"
8+
verbose="true"
9+
convertErrorsToExceptions="true"
10+
convertNoticesToExceptions="true"
11+
convertWarningsToExceptions="true"
12+
processIsolation="false"
13+
stopOnFailure="false">
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>
32+
</phpunit>

src/Gateway.php

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -68,14 +68,6 @@ public function purchase(array $parameters = [])
6868
);
6969
}
7070

71-
public function createCard(array $parameters = [])
72-
{
73-
return $this->createRequest(
74-
PurchaseRequest::class,
75-
$parameters + ['store_card' => true]
76-
);
77-
}
78-
7971
/**
8072
* Complete a purchase process
8173
*
@@ -91,21 +83,6 @@ public function completePurchase(array $parameters = [])
9183
);
9284
}
9385

94-
/**
95-
* Complete a purchase process and save card
96-
*
97-
* @param array $parameters
98-
*
99-
* @return Omnipay\WindcaveHpp\Message\CompletePurchaseRequest
100-
*/
101-
public function completeCreateCard(array $parameters = [])
102-
{
103-
return $this->createRequest(
104-
CompletePurchaseRequest::class,
105-
$parameters
106-
);
107-
}
108-
10986
public function acceptNotification(array $parameters = [])
11087
{
11188
return $this->createRequest(

src/Message/BaseRequest.php

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,16 @@ protected function getAuthorization()
3636
return base64_encode($this->getApiUsername() . ':' . $this->getApiKey());
3737
}
3838

39+
public function setCreateToken($value)
40+
{
41+
return $this->setParameter('createToken', $value);
42+
}
43+
44+
public function getCreateToken()
45+
{
46+
return $this->getParameter('createToken');
47+
}
48+
3949
// Merchant Reference
4050
public function setMerchantReference($value)
4151
{
@@ -125,14 +135,20 @@ public function getDeclineUrl()
125135
return $this->getParameter('declineUrl');
126136
}
127137

138+
/**
139+
* @deprecated Alias. Use standard `setCreateToken()` instead
140+
*/
128141
public function setStoreCard($value)
129142
{
130-
return $this->setParameter('storeCard', $value);
143+
return $this->setCreateToken($value);
131144
}
132145

146+
/**
147+
* @deprecated Alias. Use standard `getCreateToken()` instead
148+
*/
133149
public function getStoreCard()
134150
{
135-
return $this->getParameter('storeCard');
151+
return $this->getCreateToken();
136152
}
137153

138154
public function setStoredCardIndicator($value)
@@ -207,4 +223,4 @@ protected function getEndpoint($path = '')
207223
$base = $this->getTestMode() ? self::ENDPOINT_TEST : self::ENDPOINT_LIVE;
208224
return $base . '/' . $path;
209225
}
210-
}
226+
}

src/Message/PurchaseRequest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function getData()
2525
$data['currency'] = $this->getCurrency();
2626
$data['callbackUrls'] = [];
2727

28-
if ( $this->getStoreCard() ) {
28+
if ( (bool) $this->getCreateToken() ) {
2929
$data['storeCard'] = true;
3030
}
3131

@@ -41,8 +41,8 @@ public function getData()
4141
$data['recurringFrequency'] = $this->getRecurringFrequency();
4242
}
4343

44-
if ( $this->getToken() ) {
45-
$data['cardId'] = $this->getToken();
44+
if ( $this->getToken() || $this->getCardReference() ) {
45+
$data['cardId'] = $this->getToken() ?? $this->getCardReference();
4646
}
4747

4848
if ( is_array($this->getPaymentMethods()) ) {
@@ -100,4 +100,4 @@ public function sendData($data)
100100

101101
return $this->response = new PurchaseResponse($this, $responseData ?? []);
102102
}
103-
}
103+
}

0 commit comments

Comments
 (0)