Skip to content
This repository was archived by the owner on Feb 28, 2024. It is now read-only.

Commit 3d2ff68

Browse files
committed
Added 'Integrating with OpenAPI Generator API Client Libraries' section
1 parent 769a460 commit 3d2ff68

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.md

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [Loading the Encryption Certificate](#loading-the-encryption-certificate)
1616
* [Loading the Decryption Key](#loading-the-decryption-key)
1717
* [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)
1819

1920
## Overview <a name="overview"></a>
2021
Library for Mastercard API compliant payload encryption/decryption.
@@ -383,3 +384,53 @@ Output:
383384
"sensitiveField2": "sensitiveValue2"
384385
}
385386
```
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

Comments
 (0)