|
15 | 15 | * [Loading the Encryption Certificate](#loading-the-encryption-certificate) |
16 | 16 | * [Loading the Decryption Key](#loading-the-decryption-key) |
17 | 17 | * [Performing Field Level Encryption and Decryption](#performing-field-level-encryption-and-decryption) |
| 18 | + * [Integrating with OpenAPI Generator API Client Libraries](#integrating-with-openapi-generator-api-client-libraries) |
18 | 19 |
|
19 | 20 | ## Overview <a name="overview"></a> |
20 | 21 | Library for Mastercard API compliant payload encryption/decryption. |
@@ -383,3 +384,53 @@ Output: |
383 | 384 | "sensitiveField2": "sensitiveValue2" |
384 | 385 | } |
385 | 386 | ``` |
| 387 | + |
| 388 | +### Integrating with OpenAPI Generator API Client Libraries <a name="integrating-with-openapi-generator-api-client-libraries"></a> |
| 389 | + |
| 390 | +[OpenAPI Generator](https://github.com/OpenAPITools/openapi-generator) generates API client libraries from [OpenAPI Specs](https://github.com/OAI/OpenAPI-Specification). |
| 391 | +It provides generators and library templates for supporting multiple languages and frameworks. |
| 392 | + |
| 393 | +This project provides you with some interceptor classes you can use when configuring your API client. |
| 394 | +These classes will take care of encrypting request and decrypting response payloads, but also of updating HTTP headers when needed. |
| 395 | + |
| 396 | +Generators currently supported: |
| 397 | ++ [php](#php) |
| 398 | + |
| 399 | +#### php <a name="php"></a> |
| 400 | + |
| 401 | +##### OpenAPI Generator |
| 402 | + |
| 403 | +Client libraries can be generated using the following command: |
| 404 | +```shell |
| 405 | +java -jar openapi-generator-cli.jar generate -i openapi-spec.yaml -g php -o out |
| 406 | +``` |
| 407 | +See also: |
| 408 | +* [OpenAPI Generator (executable)](https://mvnrepository.com/artifact/org.openapitools/openapi-generator-cli) |
| 409 | +* [CONFIG OPTIONS for php](https://github.com/OpenAPITools/openapi-generator/blob/master/docs/generators/php.md) |
| 410 | + |
| 411 | +##### Usage of the `PsrHttpMessageEncryptionInterceptor` |
| 412 | + |
| 413 | +```php |
| 414 | +use GuzzleHttp; |
| 415 | +use OpenAPI\Client\Api\ServiceApi; |
| 416 | +use OpenAPI\Client\Configuration |
| 417 | +use Mastercard\Developer\Signers\PsrHttpMessageSigner; |
| 418 | +use Mastercard\Developer\Interceptors\PsrHttpMessageEncryptionInterceptor; |
| 419 | +// ... |
| 420 | + |
| 421 | +$stack = new GuzzleHttp\HandlerStack(); |
| 422 | +$stack->setHandler(new GuzzleHttp\Handler\CurlHandler()); |
| 423 | +$fieldLevelEncryptionConfig = FieldLevelEncryptionConfigBuilder::aFieldLevelEncryptionConfig() |
| 424 | + // ... |
| 425 | + ->build(); |
| 426 | +$fieldLevelEncryptionInterceptor = new PsrHttpMessageEncryptionInterceptor($fieldLevelEncryptionConfig); |
| 427 | +$stack->push(GuzzleHttp\Middleware::mapRequest([$fieldLevelEncryptionInterceptor, 'interceptRequest'])); |
| 428 | +$stack->push(GuzzleHttp\Middleware::mapResponse([$fieldLevelEncryptionInterceptor, 'interceptResponse'])); |
| 429 | +$stack->push(GuzzleHttp\Middleware::mapRequest([new PsrHttpMessageSigner($consumerKey, $signingKey), 'sign'])); |
| 430 | +$options = ['handler' => $stack]; |
| 431 | +$client = new GuzzleHttp\Client($options); |
| 432 | +$config = new Configuration(); |
| 433 | +$config->setHost('https://sandbox.api.mastercard.com'); |
| 434 | +$serviceApi = new ServiceApi($client, $config); |
| 435 | +// ... |
| 436 | +``` |
0 commit comments