globalpayments / php-sdk

GNU General Public License v2.0
49 stars 66 forks source link

Hosted payment supplementary data not parsed into request #30

Closed 14nd90 closed 2 years ago

14nd90 commented 5 years ago

For example, as documented here, you should be able to pass through pairs which are provided in the response:

$hostedPaymentData = new HostedPaymentData();
$hostedPaymentData->supplementaryData = ["key" => "value"];

However, in Gateways\RealexConnector.php, there is no setSerializeData for "SUPPLEMENTARY_DATA".

A quick and dirty workaround would be to add the following

RealexConnecter.php, around line 572:

if (isset($builder->hostedPaymentData->supplementaryData)) {
    $this->setSerializeData('SUPPLEMENTARY_DATA', $builder->hostedPaymentData->supplementaryData);
}

And then provide your data in the following way $hostedPaymentData->supplementaryData = addslashes(json_encode(["key" => "value"]));

Then you can just json_decode "SUPPLEMENTARY_DATA" in the response.

It would be good if supplementary data could be included in the SDK with a user friendly way to set it (such as just provide an array in the request) and for the pairs to be automatically converted back to an array in the response.

rodrigobb commented 5 years ago

It seems like a missed feature from realexpayments/rxp-hpp-php as can be seen in https://github.com/realexpayments/rxp-hpp-php/search?q=supplementaryData&unscoped_q=supplementaryData

It should be implemented or removed from the doc

Is there a way to provide additional information to the transaction?

altcom-neil commented 4 years ago

We use this parameter in our existing calls using the old RealExPayments version so it is needed for us to maintain backwards compatibility with the existing code to move to the latest GlobalPayments (version 2.0.0).

We have done a slighlty different solution to the one proposed by @14nd90

In the HostedPaymentData class, the $supplementaryData var is defined as an array so we set the data as an array when creating the HostedPaymentData object.

$hostedPaymentData = new HostedPaymentData();
// Add supplementary data array
$hostedPaymentData->supplementaryData = $this->supplementaryData; // ["key" => "value"]

But this requires the supplementaryData array to be converted into a string in the RealexConnector.php code before being sent to setSerializeData. In RealexConnecter.php, around line 570:

// PATCH: Fix missing suplementary data in request - see https://github.com/globalpayments/php-sdk/issues/30
if (isset($builder->hostedPaymentData->supplementaryData)) {
  $this->setSerializeData('SUPPLEMENTARY_DATA', json_encode($builder->hostedPaymentData->supplementaryData));
}

The data is then returned in the response json as a json encoded string.