PHP Sample Code For MLE?

Highlighted
Regular Visitor

PHP Sample Code For MLE?

My company needs to update it's PHP application to work with message level encryption. I've been able to send some successful requests using the Developer Center Playground, but I'm a bit confused as to how to encrypt the message and such. Are there any docs or code examples that explain how this can be done with PHP? Any help would be much appreciated.

2 REPLIES 2
Highlighted
Regular Visitor

Re: PHP Sample Code For MLE?

Just to add a little more info, here's an example of the code I'm currently trying to use below. I'm using a CURL call to send the data along with the mutual SSL certificates to the https://sandbox.api.visa.com/visadirect/v1/adjustment endpoint.

I can turn off MLE verification for the Adjustment API in the developer center here and remove the encryption in my code, and I get a successful response back. When I re-enable MLE verification and the encryption functions in the code below then I get a responseStatus code of 9501 and error message of "Invalid input found, please correct the input data".

 

 

<?php
$header = [];
$header[] = 'Accept: application/json';
$header[] = 'Content-Type: application/json';

$header[] = "alg: RSA-OAEP-256";
$header[] = "enc: A128GCM";
$header[] = 'iat: ' . (time() * 1000);
$header[] = 'kid: <my key id>';

$header[] = 'x-client-transaction-id: 0';

$this->request = ['http_header' => $header];
$this->request['method'] = 'post';
$params = '{
    "rewardProgramIdentificationCode": "A34324",
    "amount": "124.01",
    "localTransactionDateTime": "2020-10-17T03:12:35",
    "cpsAuthorizationCharacteristicsIndicator": "Y",
    "pointOfServiceData": {
    "panEntryMode": "01",
    "posConditionCode": "00"
    },
    "digitalWalletProviderId": "VCIND",
    "colombiaNationalServiceData": {
    "addValueTaxReturn": "10.00",
    "taxAmountConsumption": "10.00",
    "nationalNetReimbursementFeeBaseAmount": "20.00",
    "addValueTaxAmount": "10.00",
    "nationalNetMiscAmount": "10.00",
    "countryCodeNationalService": "170",
    "nationalChargebackReason": "11",
    "emvTransactionIndicator": "1",
    "nationalNetMiscAmountType": "A",
    "costTransactionIndicator": "0",
    "nationalReimbursementFee": "20.00"
    },
    "cardAcceptor": {
    "address": {
    "country": "USA",
    "zipCode": "94404",
    "county": "San Mateo",
    "state": "CA"
    },
    "idCode": "ABCD1234ABCD123",
    "name": "Visa Inc.",
    "terminalId": "ABCD1234"
    },
    "transactionIdentifier": "381228649430056",
    "acquirerCountryCode": "840",
    "acquiringBin": "408999",
    "senderCurrencyCode": "USD",
    "retrievalReferenceNumber": "433122895499",
    "transactionTypeCode": 22,
    "messageReasonCode": 2150,
    "systemsTraceAuditNumber": "895499",
    "businessApplicationId": "AA",
    "senderPrimaryAccountNumber": "4895070000003551",
    "settlementServiceIndicator": "9",
    "cardProductCode": "15",
    "merchantCategoryCode": "6012",
    "senderCardExpiryDate": "2021-10",
    "dynamicCurrencyConversionIndicator": "Y"
    }';



$key = file_get_contents('<path to my mle public key>');
$cipher = "aes-256-gcm";
if (in_array($cipher, openssl_get_cipher_methods()))
{
    $ivlen = openssl_cipher_iv_length($cipher);
    $iv = openssl_random_pseudo_bytes($ivlen);
    $ciphertext = openssl_encrypt($params, $cipher, $key, 0, $iv, $tag);
    $this->request['params'] = utf8_encode($ciphertext);
}

 

 

Highlighted
Visa Dev Moderator
Visa Dev Moderator

Re: PHP Sample Code For MLE?

Hi @IngoBrian,

 

Our MLE Guide has detailed information and sample code in Java, Python, C# and Node.JS. Please check it out and let us know if you have any other questions. We don't have PHP sample code for MLE yet, but I will pass this request/feedback to our tech team for future inclusion. Thanks.


Best,
Stacey

Was your question answered? Don't forget to click on "Accept as Solution" to help other devs find the answer to the same question.