The following configuration code samples are applicable to each feature we provide SDK code samples for. This includes Card Payments, Card Storage, Digital Wallets, Payment Methods, and so forth.
// configure client & request settings
GpEcomConfigconfig = new GpEcomConfig();
config.setMerchantId("MerchantId");
config.setAccountId("internet");
config.setSharedSecret("secret");
config.setServiceUrl("https://api.sandbox.realexpayments.com/epage-remote.cgi");
ServicesContainer.configureService(config);
<?php
require_once('vendor/autoload.php');
use GlobalPayments\Api\ServiceConfigs\Gateways\GpEcomConfig;
use GlobalPayments\Api\ServicesContainer;
use GlobalPayments\Api\Entities\Exceptions\ApiException;
use GlobalPayments\Api\PaymentMethods\CreditCardData;
$config = new GpEcomConfig();
$config->merchantId = "MerchantId";
$config->accountId = "internet";
$config->sharedSecret = "secret";
$config->serviceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi";
ServicesContainer::configureService($config);
// configure client & request settings
var config = new GpEcomConfig();
config.MerchantId = "MerchantId";
config.AccountId = "internet";
config.SharedSecret = "secret";
config.ServiceUrl = "https://api.sandbox.realexpayments.com/epage-remote.cgi";
Rebate/Refund passwords
For the Ecommerce gateway, a separate Rebate and Refund password needs to be supplied to the configuration for those transaction types.
config.setRebatePassword("rebate");
config.setRefundPassword("refund");
$config->rebatePassword = 'rebate';
$config->refundPassword = 'refund';
config.RebatePassword = "rebate";
config.RefundPassword = "refund";
Multiple/named configurations
An optional configuration name parameter can be passed to the ConfigureService method of the ServicesContainer object to differentiate between configurations and allow multiple configurations for a single service to be held and referenced simultaneously within the ServicesContainer singleton. If no configuration name is provided, the default value of “default” will be used. If the configuration name is already referenced within the collection of the ServicesContainer, the existing configuration with that name will be replaced by the new one.
ServicesContainer.configureService(config, “default”);
ServicesContainer::configureService($config, "default");
ServicesContainer.ConfigureService(config, "default");
The configuration names can then be passed to the Execute method of any builder to specify which configuration the transaction should use when processing the request.
Transaction response = card.charge(...)
…
.execute(“default”);
$response = $card->charge(...)
…
->execute("default");
Transaction response = card.Charge(...)
...
.Execute("default");
Removing named configurations
Named configurations can be removed from the collection by passing a null configuration object with the configuration name you want to remove.
ServicesContainer.configureService(null, ‘default’);
ServicesContainer::configureService(null, "default");
GpEcomConfig config = new GpEcomConfig();
config = null;
ServicesContainer.ConfigureService(config, "default");
Best practices
The ServicesContainer object is a singleton, which means object instantiation is restricted to a singular instance and all references to this object return the same instance throughout the life of the application. Given this design pattern, the SDK is best configured once at application startup.
It is not necessary, nor recommended, to configure the SDK prior to every interaction.
Logging
Enable logging flag
Some of the SDKs support the EnableLogging property. Setting this flag to true will cause the SDK to output the raw request and response messages to the IDE console. By example, this would be the debug window for .NET, or the system.io.out for Java. The EnableLogging flag is not available on all SDKs as the style of logging is not available on all IDEs.
config.enableLogging(true);
$config->requestLogger = new SampleRequestLogger(new Logger("logs"));
config.RequestLogger = new RequestConsoleLogger();
IRequestLogger interface
The SDK provides the IRequestLogger interface, an implementation of which is accepted by the SDK configuration. This interface allows the SDK to work with an application's existing logging system to capture the raw request and response messages generated by the SDK.
The interface defines two methods:
RequestSent– The raw request generated by the SDK will be passed to this method as a string.ResponseReceived– The raw response received from the gateway will be passed to this method as a string.
For PCI compliance, the raw requests and responses provided through the EnableLogging flag and the IRequestLogger interface only contain masked card numbers.