Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release v2.2.0 #135

Merged
merged 11 commits into from
Sep 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@ jobs:
grep -r -l "$string" tests/ | xargs sed -i "s/$string//g"

- name: PHPUnit
run: composer exec phpunit -- --configuration phpunit.ci.xml --coverage-xml ./.coverage
run: |
case ${{ matrix.php }} in
8.1|8.2|8.3 ) composer exec phpunit -- --configuration phpunit.ci.8.xml --coverage-xml ./.coverage;;
*) composer exec phpunit -- --configuration phpunit.ci.xml --coverage-xml ./.coverage;;
esac
env:
XDEBUG_MODE: coverage

Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ phpunit.xml
.phpunit.cache/
composer.lock
.DS_Store
.env
.env
.coverage/
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# CHANGELOG

## v2.2.0 - 2024-09-05

### Changes

### 🚀 New Features

- Add function for HMAC verification (#132)

#### Contributors

@Benjamin-Freoua-Alma, @CamilleFljt, @Francois-Gomis and @carine-bonnafous

## v2.1.0 - 2024-07-29

### Changes
Expand Down Expand Up @@ -149,6 +161,7 @@
// Handle errors
}


```
* Add fields and docs to the Payment entity
* Add a Refund entity and extract refunds data within the Payment entity constructor
Expand Down Expand Up @@ -268,10 +281,15 @@ Getting more serious with a 1.0.0 release! 🎉
## v0.0.1

* Initial "pre-release" of the API Client

* Includes two main endpoints: Payments and Merchants

* Provides what's necessary for a typical payment flow:

* `Payments.createPayment` and `Payments.eligibility`
* `Merchants.me`

* Base `Alma\API\Client` class can be configured with API key and live/test mode

* TLS is automatically forced to TLS 1.2 to meet Alma's security requirements, but configurable

6 changes: 6 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ARG COMPOSER_VERSION

FROM composer:${COMPOSER_VERSION} as composer
FROM php:${PHP_VERSION}-fpm
ARG PHP_VERSION

ENV DEBIAN_FRONTEND noninteractive

Expand All @@ -16,6 +17,11 @@ RUN apt update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

RUN case ${PHP_VERSION} in \
8.0|8.1|8.2|8.3 ) pecl install xdebug-3.3.2 && docker-php-ext-enable xdebug;; \
*) pecl install xdebug-2.9.8 && docker-php-ext-enable xdebug;; \
esac

RUN usermod -u 1000 www-data
RUN groupmod -g 1000 www-data

Expand Down
4 changes: 4 additions & 0 deletions Dockerfile.legacy
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ RUN apt update && \
apt-get clean && \
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

# Install xdebug for code coverage
RUN pecl install xdebug-2.5.5 \
&& docker-php-ext-enable xdebug

RUN usermod -u 1000 www-data
RUN groupmod -g 1000 www-data

Expand Down
12 changes: 6 additions & 6 deletions Taskfile.php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ tasks:
cmds:
- >-
{{ if eq .PHP_VERSION "5.6" "7.0" }}
docker compose run {{ .COMPOSE_SERVICE }} ./tests/legacy_tests.sh
docker compose run --rm {{ .COMPOSE_SERVICE }} ./tests/legacy_tests.sh
{{ else }}
docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --configuration phpunit.dist.xml --testsuite "Alma PHP Client Unit Test Suite"
docker compose run --rm {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --configuration {{ .PHPUNIT_FILE }} --testsuite "Alma PHP Client Unit Test Suite" --coverage-xml ./.coverage
{{ end }}

tests:integration:
Expand All @@ -39,15 +39,15 @@ tasks:
cmds:
- >-
{{ if eq .PHP_VERSION "5.6" "7.0" }}
docker compose run {{ .COMPOSE_SERVICE }} ./tests/legacy_integration_tests.sh
docker compose run --rm {{ .COMPOSE_SERVICE }} ./tests/legacy_integration_tests.sh
{{ else }}
docker compose run {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --configuration phpunit.dist.xml --testsuite "Alma PHP Client Integration Test Suite"
docker compose run --rm {{ .COMPOSE_SERVICE }} composer exec phpunit --verbose -- --configuration {{ .PHPUNIT_FILE }} --testsuite "Alma PHP Client Integration Test Suite"
{{ end }}

shell:
desc: Connect to PHP container
deps:
- docker:build
cmds:
- sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' phpunit.dist.xml > phpunit.xml
- docker compose run {{ .COMPOSE_SERVICE }} bash
- sed 's/{MYVERSION}/{{ .PHPUNIT_VERSION }}/g' {{ .PHPUNIT_FILE }} > phpunit.xml
- docker compose run --rm {{ .COMPOSE_SERVICE }} bash
3 changes: 3 additions & 0 deletions Taskfile.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ includes:
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "8.1"
PHPUNIT_FILE: phpunit.dist.8.xml
"8.2":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "8.2"
PHPUNIT_FILE: phpunit.dist.8.xml
"8.3":
taskfile: Taskfile.php.yml
vars:
PHP_VERSION: "8.3"
PHPUNIT_FILE: phpunit.dist.8.xml

tasks:
default:
Expand Down
2 changes: 2 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ services:
volumes:
- ./:/app
- /app/vendor
environment:
XDEBUG_MODE: coverage

php-legacy:
user: ${UID:-1000}:${GID:-1000}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "alma/alma-php-client",
"description": "PHP API client for the Alma payments API",
"version": "2.1.0",
"version": "2.2.0",
"type": "library",
"require": {
"php": "^5.6 || ~7.0 || ~7.1 || ~7.2 || ~7.3 || ~7.4 || ~8.0 || ~8.1 || ~8.2 || ~8.3",
Expand Down
32 changes: 32 additions & 0 deletions phpunit.ci.8.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="true"
beStrictAboutTestsThatDoNotTestAnything="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">

<testsuites>
<testsuite name="Alma PHP Client Unit Test Suite">
<directory>tests/Unit</directory>
</testsuite>
</testsuites>

<coverage includeUncoveredFiles="true"
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
</coverage>

<source>
<include>
<directory suffix=".php">./src/*</directory>
</include>
</source>

</phpunit>
40 changes: 40 additions & 0 deletions phpunit.dist.8.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
testdox="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
processIsolation="false"
stopOnFailure="false"
beStrictAboutTestsThatDoNotTestAnything="false"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd"
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">

<testsuites>
<testsuite name="Alma PHP Client Unit Test Suite">
<directory>tests/Unit</directory>
</testsuite>
<testsuite name="Alma PHP Client Integration Test Suite">
<directory>tests/Integration</directory>
</testsuite>
</testsuites>

<coverage includeUncoveredFiles="true"
pathCoverage="false"
ignoreDeprecatedCodeUnits="true"
disableCodeCoverageIgnore="true">
</coverage>

<source>
<include>
<directory suffix=".php">./src/*</directory>
</include>
</source>

<php>
<env name="ALMA_API_KEY" value="sk_test_*******"/>
<env name="ALMA_API_ROOT" value="alma-api-url"/>
</php>
</phpunit>
12 changes: 11 additions & 1 deletion phpunit.dist.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" testdox="true" displayDetailsOnTestsThatTriggerDeprecations="true" processIsolation="false" stopOnFailure="false" beStrictAboutTestsThatDoNotTestAnything="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.3/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
colors="true"
processIsolation="false"
stopOnFailure="false"
beStrictAboutTestsThatDoNotTestAnything="false">
<testsuites>
<testsuite name="Alma PHP Client Unit Test Suite">
<directory>tests/Unit</directory>
Expand All @@ -8,6 +13,11 @@
<directory>tests/Integration</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/*</directory>
</whitelist>
</filter>
<php>
<env name="ALMA_API_KEY" value="sk_test_*******"/>
<env name="ALMA_API_ROOT" value="alma-api-url"/>
Expand Down
2 changes: 1 addition & 1 deletion src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

class Client
{
const VERSION = '2.1.0';
const VERSION = '2.2.0';

const LIVE_MODE = 'live';
const TEST_MODE = 'test';
Expand Down
18 changes: 17 additions & 1 deletion src/Lib/PaymentValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
*/
class PaymentValidator
{

const HEADER_SIGNATURE_KEY = 'X-Alma-Signature';

/**
* Ensure that the purchase amount is an integer
*
Expand All @@ -53,4 +56,17 @@ public static function checkPurchaseAmount($data)
));
}
}
}

/**
* @param string $data
* @param string $apiKey
* @param string $signature
* @return bool
*/
public function isHmacValidated($data, $apiKey, $signature)
{
return is_string($data) &&
is_string($apiKey) &&
hash_hmac('sha256', $data, $apiKey) === $signature;
}
}
Loading