Skip to content

Commit d697ea6

Browse files
authored
Merge pull request #176 from CyberSource/feature/add-mle-encrypt
PHP SDK MLE Implementation
2 parents 6461b26 + 8e6fc13 commit d697ea6

File tree

68 files changed

+589
-239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+589
-239
lines changed

MLE.md

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
[![Generic badge](https://img.shields.io/badge/MLE-NEW-GREEN.svg)](https://shields.io/)
2+
3+
# Message Level Encryption (MLE) Feature
4+
5+
This feature provides an implementation of Message Level Encryption (MLE) for APIs provided by CyberSource, integrated within our SDK. This feature ensures secure communication by encrypting messages at the application level before they are sent over the network.
6+
7+
## Configuration
8+
9+
### Global MLE Configuration
10+
11+
In the `merchantConfig` object, set the `useMLEGlobally` variable to enable or disable MLE for all supported APIs for the Rest SDK.
12+
13+
- **Variable**: `useMLEGlobally`
14+
- **Type**: `boolean`
15+
- **Default**: `false`
16+
- **Description**: Enables MLE globally for all APIs when set to `true`. If set to `true`, it will enable MLE for all API calls that support MLE by CyberSource, unless overridden by `mapToControlMLEonAPI`.
17+
18+
### API-level MLE Control
19+
20+
Optionally, you can control the MLE feature at the API level using the `mapToControlMLEonAPI` variable in the `merchantConfig` object.
21+
22+
- **Variable**: `mapToControlMLEonAPI`
23+
- **Type**: `map = [string, boolean]`
24+
- **Description**: Overrides the global MLE setting for specific APIs. The key is the function name of the API in the SDK, and the value is a boolean indicating whether MLE should be enabled (`true`) or disabled (`false`) for that specific API call.
25+
26+
### MLE Key Alias
27+
28+
Another optional parameter for MLE is `mleKeyAlias`, which specifies the key alias used to retrieve the MLE certificate from the JWT P12 file.
29+
30+
- **Variable**: `mleKeyAlias`
31+
- **Type**: `string`
32+
- **Default**: `CyberSource_SJC_US`
33+
- **Description**: By default, CyberSource uses the `CyberSource_SJC_US` public certificate to encrypt the payload. However, users can override this default value by setting their own key alias.
34+
35+
## Notes
36+
- If `useMLEGlobally` is set to true, it will enable MLE for all API calls that support MLE by CyberSource, unless overridden by mapToControlMLEonAPI.
37+
- If `mapToControlMLEonAPI` is not provided or does not contain a specific API function name, the global useMLEGlobally setting will be applied.
38+
- The `mleKeyAlias` parameter is optional and defaults to CyberSource_SJC_US if not specified by the user. Users can override this default value by setting their own key alias.
39+
40+
## Example Configuration
41+
42+
```php
43+
// Enable MLE globally for all supported APIs
44+
$merchantConfig->setUseMLEGlobally(true);
45+
```
46+
47+
Or
48+
49+
```php
50+
// Enable MLE globally for all supported APIs
51+
$merchantConfig->setUseMLEGlobally(true);
52+
53+
// Optionally, control MLE at the API level
54+
$merchantConfig->setMapToControlMLEonAPI([
55+
'apiFunctionName1' => false, // Disable MLE for this specific API
56+
'apiFunctionName2' => true // Enable MLE for this specific API
57+
]);
58+
59+
// Optionally, set a custom MLE key alias
60+
$merchantConfig->setMleKeyAlias('Custom_Key_Alias');
61+
```
62+
63+
Or
64+
65+
```php
66+
// Disable MLE globally for all supported APIs
67+
$merchantConfig->setUseMLEGlobally(false);
68+
69+
// Optionally, enable MLE for some APIs
70+
$merchantConfig->setMapToControlMLEonAPI([
71+
'apiFunctionName1' => true, // Enable MLE for this specific API
72+
'apiFunctionName2' => true // Enable MLE for this specific API
73+
]);
74+
75+
// Optionally, set a custom MLE key alias
76+
$merchantConfig->setMleKeyAlias('Custom_Key_Alias');
77+
```
78+
79+
In the above examples:
80+
- MLE is enabled/disabled globally (`useMLEGlobally` is true/false).
81+
- `apiFunctionName1` will have MLE disabled/enabled based on value provided.
82+
- `apiFunctionName2` will have MLE enabled.
83+
- `mleKeyAlias` is set to `Custom_Key_Alias`, overriding the default value.
84+
85+
Please refer given link for sample codes with MLE:
86+
https://github.com/CyberSource/cybersource-rest-samples-php/tree/master/Samples/MLEFeature
87+
88+
## Additional Information
89+
90+
### API Support
91+
- MLE is initially designed to support a few APIs.
92+
- It can be extended to support more APIs in the future based on requirements and updates.
93+
### Authentication Type
94+
- MLE is only supported with `JWT (JSON Web Token)` authentication type within the SDK.
95+
### Using the SDK
96+
To use the MLE feature in the SDK, configure the `merchantConfig` object as shown above and pass it to the SDK initialization.
97+
98+
## Contact
99+
For any issues or further assistance, please open an issue on the GitHub repository or contact our support team.

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,13 @@ More information about this new logging framework can be found in this file : [L
100100

101101
## Features
102102

103+
### Message Level Encryption (MLE) Feature
104+
[![Generic badge](https://img.shields.io/badge/MLE-NEW-GREEN.svg)](https://shields.io/)
105+
106+
This feature provides an implementation of Message Level Encryption (MLE) for APIs provided by CyberSource, integrated within our SDK. This feature ensures secure communication by encrypting messages at the application level before they are sent over the network.
107+
108+
More information about this new MLE feature can be found in this file : [MLE.md](MLE.md)
109+
103110
### MetaKey Support
104111

105112
A Meta Key is a single key that can be used by one, some, or all merchants (or accounts, if created by a Portfolio user) in the portfolio.

generator/cybersource-php-template/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ use \Exception;
243243
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
244244
} catch (Exception $e) {
245245
self::$logger->error("Failed to encrypt request body: $e");
246-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
246+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
247247
}
248248
}
249249

lib/Api/BatchesApi.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ public function getBatchReportWithHttpInfo($batchId)
167167
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
168168
} catch (Exception $e) {
169169
self::$logger->error("Failed to encrypt request body: $e");
170-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
170+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
171171
}
172172
}
173173

@@ -289,7 +289,7 @@ public function getBatchStatusWithHttpInfo($batchId)
289289
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
290290
} catch (Exception $e) {
291291
self::$logger->error("Failed to encrypt request body: $e");
292-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
292+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
293293
}
294294
}
295295

@@ -420,7 +420,7 @@ public function getBatchesListWithHttpInfo($offset = '0', $limit = '20', $fromDa
420420
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
421421
} catch (Exception $e) {
422422
self::$logger->error("Failed to encrypt request body: $e");
423-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
423+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
424424
}
425425
}
426426

@@ -549,7 +549,7 @@ public function postBatchWithHttpInfo($body)
549549
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
550550
} catch (Exception $e) {
551551
self::$logger->error("Failed to encrypt request body: $e");
552-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
552+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
553553
}
554554
}
555555

lib/Api/BillingAgreementsApi.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function billingAgreementsDeRegistrationWithHttpInfo($modifyBillingAgreem
181181
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
182182
} catch (Exception $e) {
183183
self::$logger->error("Failed to encrypt request body: $e");
184-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
184+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
185185
}
186186
}
187187

@@ -321,7 +321,7 @@ public function billingAgreementsIntimationWithHttpInfo($intimateBillingAgreemen
321321
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
322322
} catch (Exception $e) {
323323
self::$logger->error("Failed to encrypt request body: $e");
324-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
324+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
325325
}
326326
}
327327

@@ -446,7 +446,7 @@ public function billingAgreementsRegistrationWithHttpInfo($createBillingAgreemen
446446
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
447447
} catch (Exception $e) {
448448
self::$logger->error("Failed to encrypt request body: $e");
449-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
449+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
450450
}
451451
}
452452

lib/Api/BinLookupApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ public function getAccountInfoWithHttpInfo($createBinLookupRequest)
168168
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
169169
} catch (Exception $e) {
170170
self::$logger->error("Failed to encrypt request body: $e");
171-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
171+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
172172
}
173173
}
174174

lib/Api/CaptureApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ public function capturePaymentWithHttpInfo($capturePaymentRequest, $id)
181181
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
182182
} catch (Exception $e) {
183183
self::$logger->error("Failed to encrypt request body: $e");
184-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
184+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
185185
}
186186
}
187187

lib/Api/ChargebackDetailsApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function getChargebackDetailsWithHttpInfo($startTime, $endTime, $organiza
180180
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
181181
} catch (Exception $e) {
182182
self::$logger->error("Failed to encrypt request body: $e");
183-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
183+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
184184
}
185185
}
186186

lib/Api/ChargebackSummariesApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function getChargebackSummariesWithHttpInfo($startTime, $endTime, $organi
180180
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
181181
} catch (Exception $e) {
182182
self::$logger->error("Failed to encrypt request body: $e");
183-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
183+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
184184
}
185185
}
186186

lib/Api/ConversionDetailsApi.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public function getConversionDetailWithHttpInfo($startTime, $endTime, $organizat
180180
$httpBody = MLEUtility::encryptRequestPayload($this->apiClient->merchantConfig, $httpBody);
181181
} catch (Exception $e) {
182182
self::$logger->error("Failed to encrypt request body: $e");
183-
throw new ApiException("Failed to encrypt request body : " + $e->getMessage());
183+
throw new ApiException("Failed to encrypt request body : " . $e->getMessage());
184184
}
185185
}
186186

0 commit comments

Comments
 (0)