This repository has been archived by the owner on Feb 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thomas GASC
committed
Sep 20, 2017
1 parent
148a5e7
commit 0b6283f
Showing
12 changed files
with
144 additions
and
203 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
/coverage/ | ||
/vendor/ | ||
/composer.lock | ||
/composer.lock | ||
/examples/credentials.txt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* Web service de création de comptes. | ||
* | ||
* @see https://github.com/NextINpact/LaPresseLibreSDK/wiki/Fonctionnement-des-web-services#web-service-de-cr%C3%A9ation-de-comptes | ||
*/ | ||
|
||
require 'bootstrap.php'; | ||
|
||
use Mediapart\LaPresseLibre\Operation\AccountCreation; | ||
|
||
$handle(AccountCreation::class, function ($data, $is_testing) use ($public_key) { | ||
return [ | ||
'IsValid' => true, | ||
'PartenaireID' => $public_key, | ||
'CodeUtilisateur' => $data['CodeUtilisateur'], | ||
'CodeEtat' => AccountCreation::SUCCESS, | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
/** | ||
* Web service de mise à jour de comptes. | ||
* | ||
* @see https://github.com/NextINpact/LaPresseLibreSDK/wiki/Fonctionnement-des-web-services#web-service-de-mise-%C3%A0-jour-de-comptes | ||
*/ | ||
|
||
require 'bootstrap.php'; | ||
|
||
use Mediapart\LaPresseLibre\Operation\AccountUpdate; | ||
|
||
$handle(AccountUpdate::class, function ($data, $is_testing) use ($public_key) { | ||
return [ | ||
'IsValid' => true, | ||
'PartenaireID' => $public_key, | ||
'CodeUtilisateur' => $data['CodeUtilisateur'], | ||
'CodeEtat' => AccountUpdate::SUCCESS, | ||
]; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
require '../vendor/autoload.php'; | ||
|
||
use Zend\Diactoros\ServerRequestFactory; | ||
use Zend\Diactoros\Response; | ||
use Zend\Diactoros\Response\SapiEmitter; | ||
use Mediapart\LaPresseLibre\Security\Identity; | ||
use Mediapart\LaPresseLibre\Security\Encryption; | ||
use Mediapart\LaPresseLibre\Subscription\Type as SubscriptionType; | ||
use Mediapart\LaPresseLibre\Transaction; | ||
use Mediapart\LaPresseLibre\Endpoint; | ||
|
||
/* | ||
Configuration : | ||
download the file : `https://partenaire.lapresselibre.fr/gestion/credentials` | ||
into `credentials.txt` | ||
*/ | ||
$config = json_decode(file_get_contents('credentials.txt')); | ||
|
||
$public_key = $config->CodePartenaire; | ||
$identity = new Identity($config->secret); | ||
$encryption = new Encryption($config->Aes, $config->Iv); | ||
|
||
/** | ||
* Handle an api endpoint of La Presse Libre. | ||
* | ||
* @param string $operation | ||
* @param callable $callback | ||
*/ | ||
$handle = function($operation, $callback) use ($identity, $encryption, $public_key) | ||
{ | ||
try { | ||
$request = ServerRequestFactory::fromGlobals(); | ||
$transaction = new Transaction($identity, $encryption, $request); | ||
$endpoint = Endpoint::answer($operation, $callback); | ||
$result = $transaction->process($endpoint); | ||
$status = 200; | ||
} catch (\InvalidArgumentException $e) { | ||
$result = $e->getMessage(); | ||
$status = 400; | ||
} catch (\UnexpectedValueException $e) { | ||
$result = $e->getMessage(); | ||
$status = 401; | ||
} catch (\Exception $e) { | ||
$result = 'Internal Error'; | ||
$status = 500; | ||
} finally { | ||
$response = (new Response()) | ||
->withStatus($status) | ||
->withHeader('X-PART', (string) $public_key) | ||
->withHeader('X-LPL', $identity->sign($public_key)) | ||
->withHeader('X-TS', (string) $identity->getDatetime()->getTimestamp()) | ||
; | ||
$response->getBody()->write(200 != $status ? json_encode(['error' => $result]) : $result); | ||
} | ||
|
||
$emitter = new SapiEmitter(); | ||
$emitter->emit($response); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
/** | ||
* Web-Service de vérification de comptes existants. | ||
* | ||
* @see https://github.com/NextINpact/LaPresseLibreSDK/wiki/Fonctionnement-des-web-services#web-service-de-v%C3%A9rification-de-comptes-existants | ||
*/ | ||
|
||
require 'bootstrap.php'; | ||
|
||
use Mediapart\LaPresseLibre\Operation\Verification; | ||
|
||
$handle(Verification::class, function ($data, $is_testing) use ($public_key) { | ||
$now = new DateTime('next year'); | ||
|
||
return [ | ||
'Mail' => $data['Mail'], | ||
'CodeUtilisateur' => $data['CodeUtilisateur'], | ||
'TypeAbonnement' => SubscriptionType::MONTHLY, | ||
'DateExpiration' => $now->format("Y-m-d\TH:i:sO"), | ||
'DateSouscription' => $now->format("Y-m-d\TH:i:sO"), | ||
'AccountExist' => true, | ||
'PartenaireID' => $public_key, | ||
]; | ||
}); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters