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 2.0.2 #76

Merged
merged 23 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1dd7900
add code coverage github action
joyet-simon Feb 1, 2024
ee960c3
use phpunit.ci.xml for code coverage tests
joyet-simon Feb 1, 2024
c71c267
Merge pull request #70 from alma/fix/rebase-develop-on-main
joyet-simon Feb 2, 2024
58d2a83
fix unit tests
joyet-simon Feb 2, 2024
3839b8a
remove double once in unit tests
joyet-simon Feb 2, 2024
3dc686b
Merge pull request #72 from alma/feature/ecom-1299-fix-unit-tests-on-…
joyet-simon Feb 2, 2024
0a80373
add code coverage github action
joyet-simon Feb 2, 2024
a26dabd
code coverage remove permission and change ubuntu version
joyet-simon Feb 5, 2024
f80e2cc
wip : Create call to Get subscriptions
Benjamin-Freoua-Alma Feb 5, 2024
96153eb
Merge pull request #73 from alma/feature/ecom-1284-add-code-coverage
joyet-simon Feb 6, 2024
feacefd
Create call to Get subscriptions
Benjamin-Freoua-Alma Feb 6, 2024
a9ddbcf
sonar: constante path request
Benjamin-Freoua-Alma Feb 6, 2024
2a17e87
add pre-commit config
joyet-simon Feb 6, 2024
618cd49
sonar: limit 120 characters authorized
Benjamin-Freoua-Alma Feb 6, 2024
206e3ab
chore: version bump
Benjamin-Freoua-Alma Feb 6, 2024
98bd3a0
Merge pull request #75 from alma/feature/ECOM-1229/create-call-to-get…
Benjamin-Freoua-Alma Feb 6, 2024
bdd2886
Merge pull request #77 from alma/feature/ecom-1296-add-pre-commit-on-…
joyet-simon Feb 8, 2024
d5a141f
[Security] Enable Vulnerability scanner on PR targeting develop
remic-alma Feb 8, 2024
19a6345
Merge pull request #78 from alma/security/enable_scan_on_pr_develop
joyet-simon Feb 8, 2024
5ad3a24
Insurance: add amount in Subscription data model
joyet-simon Feb 8, 2024
7f7f0c8
fix : use getter
Francois-Gomis Feb 8, 2024
7b859cd
add amount to api endpoint call
joyet-simon Feb 8, 2024
957d451
Merge pull request #79 from alma/fix/ECOM-1327/add_amount_to_subscrip…
joyet-simon Feb 8, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/aqua.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ on:
pull_request:
branches:
- main
- develop

jobs:
aqua:
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/code-coverage.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: PHPUnit Coverage Report
joyet-simon marked this conversation as resolved.
Show resolved Hide resolved
joyet-simon marked this conversation as resolved.
Show resolved Hide resolved
joyet-simon marked this conversation as resolved.
Show resolved Hide resolved
joyet-simon marked this conversation as resolved.
Show resolved Hide resolved
joyet-simon marked this conversation as resolved.
Show resolved Hide resolved

on:
push:
branches: [develop, master]
pull_request:
branches: [develop, master]
workflow_dispatch: ~

jobs:
ci:
runs-on: ubuntu-22.04
joyet-simon marked this conversation as resolved.
Show resolved Hide resolved
defaults:
run:
working-directory: ./

steps:
- uses: actions/checkout@v4

joyet-simon marked this conversation as resolved.
Show resolved Hide resolved
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 5.6
tools: composer:v1

- name: Validate composer.json and composer.lock
run: composer validate

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-suggest

- name: Ensure source code is linted
run: ./vendor/bin/phpcs src

- name: PHPUnit
run: ./vendor/bin/phpunit -c phpunit.ci.xml --coverage-xml ./.coverage
env:
XDEBUG_MODE: coverage

- name: PHPUnit threshold
run: php ./phpunit-threshold.php
59 changes: 59 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# See https://pre-commit.com for more information
# See https://pre-commit.com/hooks.html for more hooks
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: check-added-large-files
args: ["--maxkb=1024"]
- id: detect-private-key
- id: check-merge-conflict
- id: no-commit-to-branch
args: [--branch, develop, --branch, main]


# - repo: local
# hooks:
# - id: coding-standard-fixer
# name: PHP coding standards Fixer test
# language: script
# entry: ./scripts/coding-standard-fixer.sh
# stages: [commit]
#
# - repo: local
# hooks:
# - id: coding-standard
# name: Check the PHP and Prestashop coding standards
# language: script
# entry: ./scripts/coding-standard.sh
# stages: [commit]
#
# - repo: local
# hooks:
# - id: php-compatibility
# name: Check the PHP compatibility
# language: script
# entry: ./scripts/php-compatibility.sh
# stages: [commit]
#
# - repo: https://github.com/returntocorp/semgrep
# rev: v1.27.0
# hooks:
# - id: semgrep
# args:
# - --error
# - --config
# - semgrep/rules/
# - --metrics
# - "off"
# - --quiet
# - --disable-version-check
# - --skip-unknown-extensions
# pass_filenames: false # Passing files explicitely override semgremignore

- repo: https://github.com/alma/pre-commit-hooks
rev: 1.1.2
hooks:
- id: check-branch-name
args:
- "-r^((chore|ci|dependabot|devx|docs|feature|fix|hotfix|hotfix-backport|infra|other|perf|refactor|security|test)\/.+|(snyk)-.+|main|develop|HEAD)$$"
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

v2.0.2
-------
* Added getSubscription endpoint Insurance
* Fix Subscription amount model

v2.0.1
-------
* Fix : Don't remove amount in refund if value equal zero
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"php": "^5.6 || ~7.0 || ~7.1 || ~7.2 || ~7.3 || ~7.4 || ~8.0 || ~8.1 || ~8.2",
"psr/log": "^1 || ^2 || ^3",
"ext-curl": "*",
"ext-json": "*"
"ext-json": "*",
"ext-simplexml": "*"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.0",
Expand Down
53 changes: 53 additions & 0 deletions phpunit-threshold.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

$file = "./.coverage/index.xml";
$coverage = simplexml_load_file($file);
$coverageIsOk = true;
$errorMessage = "";
$totals = [
[
'name' => "Lines",
'threshold' => 51,
'ratio' => (double)$coverage->project->directory->totals->lines["percent"]
],
[
'name' => "Methods",
'threshold' => 47,
'ratio' => (double)$coverage->project->directory->totals->methods["percent"]
],
[
'name' => "Functions",
'threshold' => 0,
'ratio' => (double)$coverage->project->directory->totals->functions["percent"]
],
[
'name' => "Classes",
'threshold' => 22,
'ratio' => (double)$coverage->project->directory->totals->classes["percent"]
],
[
'name' => "Traits",
'threshold' => 0,
'ratio' => (double)$coverage->project->directory->totals->traits["percent"]
]
];

foreach ($totals as $total) {
if ($total['ratio'] < $total['threshold']) {
echo "{$total['name']} coverage failed! \r\n";
echo "{$total['name']} coverage: {$total['ratio']}% \r\n";
echo "Threshold: {$total['threshold']}% \r\n";
$coverageIsOk = false;
$errorMessage .= "{$total['name']} coverage failed! \r\n";
} else {
echo "{$total['name']} coverage success: {$total['ratio']}% \r\n";
}
}

if (!$coverageIsOk) {
echo "Coverage failed! \r\n";
echo $errorMessage;
exit(1);
} else {
echo "Coverage success! \r\n";
}
9 changes: 8 additions & 1 deletion phpunit.ci.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,12 @@
<directory>tests/Unit/Legacy</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src/*</directory>
<exclude>
<directory suffix=".php">./src/vendor/*</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
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.0.1';
const VERSION = '2.0.2';

const LIVE_MODE = 'live';
const TEST_MODE = 'test';
Expand Down
24 changes: 23 additions & 1 deletion src/Endpoints/Insurance.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class Insurance extends Base
/**
* @var InsuranceValidator
*/
protected $insuranceValidator;
public $insuranceValidator;

public function __construct($client_context)
{
Expand Down Expand Up @@ -130,7 +130,28 @@ public function subscription($subscriptionArray, $paymentId = null, $customerSes
$response = $request->post();

if ($response->isError()) {
throw new RequestException($response->errorMessage, null, $response);
}

return $response->json;
}

/**
* @throws RequestError
* @throws RequestException
* @throws ParametersException
* @return array json_decode in response constructor
*/
public function getSubscription($subscriptionIds)
{
$this->insuranceValidator->checkSubscriptionIds($subscriptionIds);
$response = $this->request(
self::INSURANCE_PATH . 'subscriptions'
)->setQueryParams(
$subscriptionIds
)->get();

if ($response->isError()) {
throw new RequestException($response->errorMessage, null, $response);
}

Expand Down Expand Up @@ -161,6 +182,7 @@ protected function buildSubscriptionData($subscriptionArray, $paymentId = null)

$subscriptionData['subscriptions'][] = [
'insurance_contract_id' => $subscription->getContractId(),
'amount' => $subscription->getAmount(),
'cms_reference' => $subscription->getCmsReference(),
'product_price' => $subscription->getProductPrice(),
'cms_callback_url' => $subscription->getCallbackUrl(),
Expand Down
26 changes: 21 additions & 5 deletions src/Entities/Insurance/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class Subscription
* @var string
*/
private $contractId;
/**
* @var int
*/
private $amount;
/**
* @var string
*/
Expand All @@ -33,20 +37,23 @@ class Subscription

/**
* @param string $contractId
* @param int $amount
* @param string $cmsReference
* @param int $productPrice
* @param Subscriber $subscriber
* @param string $callbackUrl
*/
public function __construct(
$contractId,
$amount,
$cmsReference,
$productPrice,
$subscriber,
$callbackUrl
)
{
$this->contractId = $contractId;
$this->amount = $amount;
$this->cmsReference = $cmsReference;
$this->productPrice = $productPrice;
$this->subscriber = $subscriber;
Expand All @@ -56,11 +63,12 @@ public function __construct(
public function getAll()
{
return [
$this->contractId,
$this->cmsReference,
$this->productPrice,
$this->subscriber,
$this->callbackUrl,
$this->getContractId(),
$this->getAmount(),
$this->getCmsReference(),
$this->getProductPrice(),
$this->getSubscriber(),
$this->getCallbackUrl(),
];
}

Expand Down Expand Up @@ -103,4 +111,12 @@ public function getSubscriber()
{
return $this->subscriber;
}

/**
* @return int
*/
public function getAmount()
{
return $this->amount;
}
}
13 changes: 13 additions & 0 deletions src/Lib/InsuranceValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ public function checkParamFormat($param, $name)
));
}
}

/**
* @throws ParametersException
*/
public function checkSubscriptionIds($subscriptionIds)
{
if (!is_array($subscriptionIds)) {
throw new ParametersException(sprintf(
'The subscription ids need to be an array, "%s" given',
gettype($subscriptionIds)
));
}
}
}
Loading