Skip to content

Undefined array keys in Services/HostedService.php parseResponse() - version 14.0.4 #139

@paulstenning

Description

@paulstenning

We have this entry in error_log - only once so far, otherwise things are working fine.

PHP Warning:  Undefined array key "TIMESTAMP" in globalpayments/php-sdk-14.0.4/src/Services/HostedService.php on line 144
PHP Warning:  Undefined array key "MERCHANT_ID" in globalpayments/php-sdk-14.0.4/src/Services/HostedService.php on line 145
PHP Warning:  Undefined array key "ORDER_ID" in globalpayments/php-sdk-14.0.4/src/Services/HostedService.php on line 146
PHP Warning:  Undefined array key "RESULT" in globalpayments/php-sdk-14.0.4/src/Services/HostedService.php on line 147
PHP Warning:  Undefined array key "MESSAGE" in globalpayments/php-sdk-14.0.4/src/Services/HostedService.php on line 148
PHP Warning:  Undefined array key "PASREF" in globalpayments/php-sdk-14.0.4/src/Services/HostedService.php on line 149

We are using hosted payment page in a lightbox. The relevant parts of our response code (PHP 8.5) are:

	require '../globalpayments/php-sdk-14.0.4/autoload_standalone.php';

	use GlobalPayments\Api\ServiceConfigs\Gateways\GpEcomConfig;
	use GlobalPayments\Api\Services\HostedService;
	use GlobalPayments\Api\Entities\Exceptions\ApiException;

	// fail if no response
	if (empty($_POST['hppResponse'])) {
		// error handler
	}

	// get response
	$responseJson = trim($_POST['hppResponse']);

	// fail if not valid json
	if (!str_starts_with($responseJson, '{') || !str_ends_with($responseJson, '}')) {
		// error handler
	} elseif (empty(json_decode($responseJson)) || json_last_error() != JSON_ERROR_NONE) {
		// error handler
	}

	// configure client settings
	$config = new GpEcomConfig();
	$config->merchantId = $merchantid;
	$config->accountId = $account;
	$config->sharedSecret = $secret;
	$config->serviceUrl = 'https://pay.realexpayments.com/pay';

	try {
		$service = new HostedService($config);
		// create the response object from the response JSON
		$parsedResponse = $service->parseResponse($responseJson, true);
		$responseCode = $parsedResponse->responseCode;
		$responseMessage = $parsedResponse->responseMessage;
		$responseValues = $parsedResponse->responseValues;
	} catch (ApiException $e) {
		// error handler
	}

I have compared with 14.1.15 but Services/HostedService.php has not changed, so I see no benefit to updating to that version.

The server logs show that the page was accessed by an IP address of a logged in customer (who's order is showing as unpaid) at the exact time of the error. I don't know what the post was but that it was most likely not malicious.

I don't know if there is enough here to work out the cause.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions