Skip to content

Commit f265bd8

Browse files
authored
Update to 3DSv2 and implement recovery, cancel and refund (#13)
1 parent 1689a16 commit f265bd8

38 files changed

+3312
-338
lines changed

.coveralls.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
service_name: travis-ci
2+
coverage_clover: build/clover.xml
3+
json_path: build/coveralls.json

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ composer.phar
77
# composer.lock
88
tests/Credentials.php
99
coverage
10+
build
1011
.php_cs.cache

.scrutinizer.yml

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
filter:
2+
excluded_paths: [tests/*]
3+
4+
checks:
5+
php:
6+
remove_extra_empty_lines: true
7+
remove_php_closing_tag: true
8+
remove_trailing_whitespace: true
9+
fix_use_statements:
10+
remove_unused: true
11+
preserve_multiple: false
12+
preserve_blanklines: true
13+
order_alphabetically: true
14+
fix_php_opening_tag: true
15+
fix_linefeed: true
16+
fix_line_ending: true
17+
fix_identation_4spaces: true
18+
fix_doc_comments: true
19+
20+
tools:
21+
external_code_coverage:
22+
timeout: 600
23+
runs: 4

.travis.yml

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
language: php
2+
3+
php:
4+
- 7.2
5+
6+
before_script:
7+
- travis_retry composer self-update
8+
- travis_retry composer update --no-interaction --prefer-source
9+
- composer require --dev scrutinizer/ocular --no-interaction
10+
- composer require --dev php-coveralls/php-coveralls --no-interaction
11+
12+
script:
13+
- vendor/bin/phpunit
14+
15+
after_script:
16+
- php vendor/bin/ocular code-coverage:upload --format=php-clover build/clover.xml
17+
- php vendor/bin/php-coveralls

ReadMe.md

+110-3
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
# Monetico PHP SDK
22

3-
This library aims to facilitate the usage of Monetico Payment Service
3+
[![Latest Version](https://img.shields.io/packagist/v/DansMaCulotte/monetico-php.svg?style=flat-square)](https://packagist.org/packages/dansmaculotte/monetico-php)
4+
[![Total Downloads](https://img.shields.io/packagist/dt/DansMaCulotte/monetico-php.svg?style=flat-square)](https://packagist.org/packages/dansmaculotte/monetico-php)
5+
[![Build Status](https://img.shields.io/travis/DansMaCulotte/monetico-php/master.svg?style=flat-square)](https://travis-ci.org/dansmaculotte/monetico-php)
6+
[![Quality Score](https://img.shields.io/scrutinizer/g/DansMaCulotte/monetico-php.svg?style=flat-square)](https://scrutinizer-ci.com/g/dansmaculotte/monetico-php)
7+
[![Code Coverage](https://img.shields.io/coveralls/github/DansMaCulotte/monetico-php.svg?style=flat-square)](https://coveralls.io/github/dansmaculotte/monetico-php)
8+
9+
This library aims to facilitate the usage of Monetico Service Methods
410

511
## Installation
612

713
### Requirements
814

9-
- PHP 7.0
15+
- PHP 7.2
1016

1117
You can install the package via composer:
1218

13-
``` bash
19+
```bash
1420
composer require dansmaculotte/monetico-php
1521
```
1622

1723
## Usage
1824

25+
### Monetico
26+
1927
```php
2028
use DansMaCulotte\Monetico\Monetico;
2129

@@ -29,8 +37,13 @@ $monetico = new Monetico(
2937
);
3038
```
3139

40+
### Payment
41+
3242
```php
3343
use DansMaCulotte\Monetico\Payment\Payment;
44+
use DansMaCulotte\Monetico\Resources\AddressBilling;
45+
use DansMaCulotte\Monetico\Resources\AddressShipping;
46+
use DansMaCulotte\Monetico\Resources\Client;
3447

3548
$payment = new Payment(array(
3649
'reference' => 'ABCDEF123',
@@ -42,6 +55,15 @@ $payment = new Payment(array(
4255
'datetime' => Carbon::create(2019, 1, 1),
4356
));
4457

58+
$addressBilling = new AddressBilling('7 rue melingue', 'Caen', '14000', 'France');
59+
$payment->setAddressBilling($addressBilling);
60+
61+
$addressShipping = new AddressShipping('7 rue melingue', 'Caen', '14000', 'France');
62+
$payment->setAddressShipping($addressShipping);
63+
64+
$client = new Client('MR', 'John', 'Stark', 'Snow');
65+
$payment->setClient($client);
66+
4567
$url = $monetico->getPaymentUrl();
4668
$fields = $monetico->getPaymentFields($payment);
4769
```
@@ -59,6 +81,91 @@ $result = $monetico->validateSeal($response);
5981
$receipt = new Receipt($result);
6082
```
6183

84+
### Recovery
85+
86+
```php
87+
Use DansMaCulotte\Monetico\Recovery\Recovery;
88+
use DansMaCulotte\Monetico\Recovery\Response;
89+
90+
$recovery = new Recovery([
91+
'reference' => 'AXCDEF123',
92+
'language' => 'FR',
93+
'amount' => 42.42,
94+
'amountToRecover' => 0,
95+
'amountRecovered' => 0,
96+
'amountLeft' => 42.42,
97+
'currency' => 'EUR',
98+
'orderDate' => Carbon::create(2019, 07, 17),
99+
'dateTime' => Carbon::create(2019, 07, 17),
100+
]);
101+
102+
$url = $monetico->getRecoveryUrl();
103+
$fields = $monetico->getRecoveryFields($recovery);
104+
105+
$client = new GuzzleHttp\Client();
106+
$data = $client->request('POST', $url, $fields);
107+
108+
// $data = json_decode($data, true);
109+
110+
$response = new Response($data);
111+
```
112+
113+
### Cancel
114+
115+
```php
116+
use DansMaCulotte\Monetico\Cancel\Cancel;
117+
use DansMaCulotte\Monetico\Cancel\Response;
118+
119+
$cancel = new Cancel([
120+
'dateTime' => Carbon::create(2019, 2, 1),
121+
'orderDate' => Carbon::create(2019, 1, 1),
122+
'reference' => 'ABC123',
123+
'language' => 'FR',
124+
'currency' => 'EUR',
125+
'amount' => 100,
126+
'amountRecovered' => 0,
127+
]);
128+
129+
$url = $monetico->getCancelUrl();
130+
$fields = $monetico->getCancelFields($recovery);
131+
132+
$client = new GuzzleHttp\Client();
133+
$data = $client->request('POST', $url, $fields);
134+
135+
// $data = json_decode($data, true);
136+
137+
$response = new Response($data);
138+
```
139+
140+
### Refund
141+
142+
```php
143+
use DansMaCulotte\Monetico\Refund\Refund;
144+
use DansMaCulotte\Monetico\Refund\Response;
145+
146+
$refund = new Refund([
147+
'datetime' => Carbon::create(2019, 2, 1),
148+
'orderDatetime' => Carbon::create(2019, 1, 1),
149+
'recoveryDatetime' => Carbon::create(2019, 1, 1),
150+
'authorizationNumber' => '1222',
151+
'reference' => 'ABC123',
152+
'language' => 'FR',
153+
'currency' => 'EUR',
154+
'amount' => 100,
155+
'refundAmount' => 50,
156+
'maxRefundAmount' => 80,
157+
]);
158+
159+
$url = $monetico->getRefundUrl();
160+
$fields = $monetico->getRefundFields($recovery);
161+
162+
$client = new GuzzleHttp\Client();
163+
$data = $client->request('POST', $url, $fields);
164+
165+
// $data = json_decode($data, true);
166+
167+
$response = new Response($data);
168+
```
62169
## License
63170

64171
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

composer.json

+6-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
{
1212
"name": "Gaël Reyrol",
1313
"email": "gael@dansmaculotte.fr"
14+
},
15+
{
16+
"name": "Martin Potel",
17+
"email": "martin@dansmaculotte.fr"
1418
}
1519
],
1620
"autoload": {
@@ -19,7 +23,8 @@
1923
}
2024
},
2125
"require": {
22-
"php": "^7.0"
26+
"php": "^7.2",
27+
"ext-json": "*"
2328
},
2429
"require-dev": {
2530
"phpunit/phpunit": "^8.2",

composer.lock

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpunit.xml

+9
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit
33
bootstrap="vendor/autoload.php"
4+
backupGlobals="false"
5+
backupStaticAttributes="false"
46
colors="true"
7+
verbose="true"
58
convertErrorsToExceptions="true"
69
convertNoticesToExceptions="true"
710
convertWarningsToExceptions="true"
11+
processIsolation="false"
812
stopOnFailure="true">
913
<testsuites>
1014
<testsuite name="Unit Tests">
@@ -16,4 +20,9 @@
1620
<directory suffix=".php">src/</directory>
1721
</whitelist>
1822
</filter>
23+
<logging>
24+
<log type="coverage-html" target="build/coverage"/>
25+
<log type="coverage-text" target="build/coverage.txt"/>
26+
<log type="coverage-clover" target="build/clover.xml"/>
27+
</logging>
1928
</phpunit>

src/BaseMethod.php

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace DansMaCulotte\Monetico;
4+
5+
trait BaseMethod
6+
{
7+
public function generateSeal($securityKey, $fields)
8+
{
9+
ksort($fields);
10+
11+
$query = http_build_query($fields, null, '*');
12+
$query = urldecode($query);
13+
14+
return strtoupper(hash_hmac(
15+
'sha1',
16+
$query,
17+
$securityKey
18+
));
19+
}
20+
21+
public function generateFields($seal, $fields)
22+
{
23+
return array_merge(
24+
$fields,
25+
['MAC' => $seal]
26+
);
27+
}
28+
}

src/Cancel/Cancel.php

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<?php
2+
3+
namespace DansMaCulotte\Monetico\Cancel;
4+
5+
use DansMaCulotte\Monetico\Exceptions\Exception;
6+
use DansMaCulotte\Monetico\Recovery\Recovery;
7+
use DateTime;
8+
9+
class Cancel extends Recovery
10+
{
11+
public function __construct(array $data = [])
12+
{
13+
$data['amountLeft'] = 0;
14+
$data['amountToRecover'] = 0;
15+
parent::__construct($data);
16+
}
17+
18+
/**
19+
* @throws Exception
20+
*/
21+
public function validate()
22+
{
23+
if (!$this->dateTime instanceof DateTime) {
24+
throw Exception::invalidDatetime();
25+
}
26+
27+
if (!$this->orderDate instanceof DateTime) {
28+
throw Exception::invalidOrderDate();
29+
}
30+
31+
if (strlen($this->reference) > 12) {
32+
throw Exception::invalidReference($this->reference);
33+
}
34+
35+
if (strlen($this->language) != 2) {
36+
throw Exception::invalidLanguage($this->language);
37+
}
38+
}
39+
}

src/Cancel/Response.php

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace DansMaCulotte\Monetico\Cancel;
4+
5+
use DansMaCulotte\Monetico\Recovery\Response as RecoveryResponse;
6+
7+
class Response extends RecoveryResponse
8+
{
9+
}

0 commit comments

Comments
 (0)