GP API-based card payment processing with multi-currency and multi-language support using Global Payments PHP SDK.
- Client-Side Tokenization: Secure card data capture using GP API JavaScript SDK
- Server-Side Payment Processing: Token-based payment charging via GP API
- Multi-Currency Support: Process payments in USD, EUR, GBP, CAD, AUD, JPY
- Multi-Language Support: Interface available in English, Spanish, French, German, Portuguese
- Independent Selection: Currency and language can be chosen independently
- Automatic Locale Detection: Browser language detection with manual override
- Currency Formatting: Locale-aware number and currency formatting using Intl API
- Session Persistence: User preferences saved across sessions
- Card Details Management: Automatic extraction and return of card metadata
- CORS Support: Cross-origin request handling for frontend integration
- Error Handling: Comprehensive exception handling with localized error messages
- Postal Code Validation: Input sanitization for billing addresses
config.php- Generates GP API access tokens with locale/currency informationprocess-payment.php- Processes payments with localization supportget-locale.php- API endpoint for locale and currency managementPaymentUtils.php- Utility class for SDK configuration and payment operations.env.sample- Environment configuration templateindex.html- Frontend payment form with localization features
services/LocaleService.php- Locale detection, validation, and session managementservices/CurrencyConfig.php- Currency metadata and formatting rulesservices/TranslationService.php- Server-side translation handling
translations/en.json- English translationstranslations/es.json- Spanish translationstranslations/fr.json- French translationstranslations/de.json- German translationstranslations/pt.json- Portuguese translations
js/translations.js- Client-side i18n modulejs/currency-formatter.js- Currency formatting utilities
Generates GP API access token with locale/currency configuration.
Response:
{
"success": true,
"data": {
"accessToken": "PMT_...",
"locale": "en",
"currency": "USD",
"supportedLocales": {
"en": {"code": "en", "name": "English", "defaultCurrency": "USD"},
"es": {"code": "es", "name": "Spanish", "defaultCurrency": "EUR"}
},
"supportedCurrencies": {
"USD": {"code": "USD", "symbol": "$", "decimals": 2, "country": "US"},
"EUR": {"code": "EUR", "symbol": "€", "decimals": 2, "country": "GB"}
}
}
}Retrieves current locale and currency settings with translations.
Response:
{
"success": true,
"data": {
"locale": "en",
"currency": "USD",
"supportedLocales": {...},
"supportedCurrencies": {...},
"translations": {
"form.amount": "Amount",
"button.process_payment": "Process Payment"
}
}
}Updates user locale and currency preferences.
Request:
{
"locale": "es",
"currency": "EUR"
}Response:
{
"success": true,
"data": {
"locale": "es",
"currency": "EUR",
"translations": {
"form.amount": "Monto",
"button.process_payment": "Procesar Pago"
}
}
}Processes card payment with localization support.
Request:
{
"payment_token": "PMT_...",
"amount": 25.00,
"currency": "EUR",
"locale": "es",
"billing_zip": "12345",
"cardDetails": {
"cardType": "visa",
"cardLast4": "9299",
"expiryMonth": "12",
"expiryYear": "2025",
"cardholderName": "Test User"
}
}Response:
{
"success": true,
"locale": "es",
"message": "¡Pago Exitoso!",
"data": {
"transactionId": "TRN_...",
"amount": 25.00,
"currency": "EUR",
"status": "captured",
"paymentMethod": {
"brand": "Visa",
"last4": "9299",
"expiryMonth": "12",
"expiryYear": "2025"
}
}
}- PHP 7.4+ with extensions:
json- JSON encoding/decodingsession- Session managementintl(optional) - Enhanced locale support
- Composer - Dependency management
- Global Payments PHP SDK - Payment processing
- Symfony Translation Component - Localization
- GP API Credentials - Sandbox or production
-
Copy environment configuration
cp .env.sample .env
-
Add GP API credentials to
.envGP_API_APP_ID=your_app_id GP_API_APP_KEY=your_app_key
-
Install dependencies
composer install
This will install:
globalpayments/php-sdk- Global Payments SDKsymfony/translation- Translation frameworkvlucas/phpdotenv- Environment configuration
-
Configure web server
- Point document root to
php/directory - Ensure PHP session support is enabled
- Enable URL rewriting if needed
- Point document root to
-
Verify localization setup
# Check translation files exist ls translations/ # Should show: en.json es.json fr.json de.json pt.json # Check services directory ls services/ # Should show: LocaleService.php CurrencyConfig.php TranslationService.php
- English (en) - Default currency: USD
- Spanish (es) - Default currency: EUR
- French (fr) - Default currency: EUR
- German (de) - Default currency: EUR
- Portuguese (pt) - Default currency: EUR
- USD - US Dollar ($) - Country: US
- EUR - Euro (€) - Country: GB
- GBP - British Pound (£) - Country: GB
- CAD - Canadian Dollar (C$) - Country: CA
- AUD - Australian Dollar (A$) - Country: AU
- JPY - Japanese Yen (¥) - Country: JP
- Locale Detection: System detects user language from
Accept-Languageheader - Currency Selection: Users can choose any currency independently of language
- Session Persistence: Preferences saved in PHP session
- Dynamic Configuration: GP API country code automatically set based on currency
- Translation: All messages (errors, success, forms) translated to selected language
- Formatting: Currency amounts formatted according to locale rules (decimal separators, etc.)
// Frontend automatically detects English browser
// Default currency: USD
// User enters: 25.00
// Transaction processed in USD with US country code// User selects Spanish (es) and Euro (EUR)
// Form labels appear in Spanish
// Amount input uses comma for decimal: "25,00"
// Transaction processed in EUR with GB country code
// Success message: "¡Pago Exitoso!"// User selects German (de) but keeps USD
// Form labels appear in German
// Amount formatted as US: "25.00"
// Transaction processed in USD with US country code
// Demonstrates independent currency/language selection-
Create translation file
cp translations/en.json translations/it.json
-
Translate all strings in
it.json{ "form.amount": "Importo", "button.process_payment": "Elabora Pagamento", ... } -
Add locale to
LocaleService.phpprivate static $supportedLocales = [ // ... existing locales 'it' => [ 'code' => 'it', 'name' => 'Italian', 'nativeName' => 'Italiano', 'flag' => '🇮🇹', 'defaultCurrency' => 'EUR' ] ];
-
Update frontend
translations.jsconst translations = { // ... existing translations it: { "form.amount": "Importo", "button.process_payment": "Elabora Pagamento", ... } };
-
Add currency to
CurrencyConfig.php'CHF' => [ 'code' => 'CHF', 'name' => 'Swiss Franc', 'symbol' => 'CHF', 'symbolPosition' => 'after', 'decimals' => 2, 'decimalSeparator' => '.', 'thousandsSeparator' => ',', 'country' => 'CH', 'flag' => '🇨🇭' ]
-
Update frontend
currency-formatter.jsconst currencyConfig = { // ... existing currencies CHF: { code: 'CHF', symbol: 'CHF', decimals: 2, country: 'CH', flag: '🇨🇭' } };
-
Verify GP API supports the currency - Check with Global Payments that your merchant account supports the new currency
-
Test different languages
- Open browser console
- Change
Accept-Languageheader - Verify correct language detected
-
Test different currencies
- Select each currency from dropdown
- Verify symbol and formatting correct
- Process test payment
-
Test combinations
- English + EUR
- Spanish + USD
- French + GBP
- Verify independence of selection
Use Global Payments test cards:
- Visa: 4263 9826 4026 9299 (CVV: 123, Exp: 12/25)
- Mastercard: 5425 2334 2424 1200 (CVV: 123, Exp: 12/25)
- Amex: 374101000000608 (CVV: 1234, Exp: 12/25)
Symptom: UI appears in English regardless of language selection
Solution: Check translation files exist and are valid JSON
php -r "json_decode(file_get_contents('translations/es.json'));"Symptom: Amount shows wrong decimal separator or symbol
Solution: Verify currency config matches CurrencyConfig.php
print_r(CurrencyConfig::getCurrency('EUR'));Symptom: Locale/currency resets on page reload
Solution: Ensure sessions are enabled
// Add to beginning of scripts
if (session_status() === PHP_SESSION_NONE) {
session_start();
}Symptom: Payment fails with currency or country error
Solution: Verify country code mapping is correct
USD → US
EUR → GB (for GP API multi-currency)
GBP → GB
CAD → CA
AUD → AU
JPY → JP