shakegwapo / sap-icf-service
A Laravel package for SAP ICF Service
Requires
- php: ^7.2|^8.0
- guzzlehttp/guzzle: ^6.0|^7.0
- illuminate/support: ^6.0|^7.0|^8.0|^9.0|^10.0|^11.0|^12.0
Requires (Dev)
- mockery/mockery: ^1.3.1|^1.6
- orchestra/testbench: ^4.0|^5.0|^6.0|^7.0|^8.0|^9.0|^10.0
- phpunit/phpunit: ^8.5|^9.5|^10.5|^11.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
A robust Laravel package for integrating with SAP ICF (Internet Communication Framework) services with dynamic SAP client support, Facade access, and multi-version compatibility across Laravel 6.x through Laravel 12.x and PHP 7.2 through PHP 8.4.
Features
- Multi-Version Compatibility: Supports Laravel 6, 7, 8, 9, 10, 11, and 12 on PHP 7.2 - 8.4.
- Automatic Client Append: Automatically appends the SAP client parameter to every request (e.g.,
?sap-client=500). - Facade & Dependency Injection Support: Use
SapService::get(...)or injectSapServicedirectly. - Named Clients:
SapService::client('888')switches the SAP client the same wayDB::connection()switches a database. Host and login stay the same. - Per-Request Client Override: A
sap-clientkey in the payload still overrides the client for that one call. - Customizable Parameter Names: Works with any parameter name (e.g.,
sap-client,client,sapclient). - Configurable Timeout & SSL Verification: Easily configure Guzzle options via
.env. - Standardized Error Handling & Logging: Catch and log
ClientException,ServerException,ConnectException, andRequestException.
Compatibility Matrix
| Laravel Version | Supported PHP Versions |
|---|---|
| Laravel 12.x | PHP 8.2 - 8.4 |
| Laravel 11.x | PHP 8.2 - 8.4 |
| Laravel 10.x | PHP 8.1 - 8.3 |
| Laravel 9.x | PHP 8.0 - 8.2 |
| Laravel 8.x | PHP 7.3 - 8.1 |
| Laravel 7.x | PHP 7.2 - 8.0 |
| Laravel 6.x | PHP 7.2 - 8.0 |
Installation
Install the package via Composer:
composer require shakegwapo/sap-icf-service
The package will automatically register its ServiceProvider and SapService Facade alias via Laravel Package Discovery.
Configuration
Publish the configuration file:
php artisan vendor:publish --tag=sap-config
This creates config/sap.php:
return [
'base_url' => env('SAP_BASE_URL', 'https://your-sap-base-url.com'),
'username' => env('SAP_USERNAME', 'your-username'),
'password' => env('SAP_PASSWORD', 'your-password'),
'sap_client' => env('SAP_CLIENT', '500'),
'clients' => [
'888' => [
'sap_client' => env('SAP_CLIENT_888', '888'),
],
'820' => [
'sap_client' => env('SAP_CLIENT_820', '820'),
],
],
'client_parameter' => env('SAP_CLIENT_PARAMETER', 'sap-client'),
'timeout' => env('SAP_TIMEOUT', 30),
'verify' => env('SAP_VERIFY_SSL', true),
];
Configure your .env file:
# SAP Connection
SAP_BASE_URL=https://your-sap-server.com
SAP_USERNAME=your-username
SAP_PASSWORD=your-password
SAP_CLIENT=500
# Optional named clients (same host and login)
SAP_CLIENT_888=888
SAP_CLIENT_820=820
# Optional Settings
SAP_CLIENT_PARAMETER=sap-client
SAP_TIMEOUT=30
SAP_VERIFY_SSL=true
Usage
1. Using the Facade (Recommended)
use Shakegwapo\SapIcfService\Facades\SapService;
// GET request -> https://your-sap-server.com/zproduct_order/list?sap-client=500
$response = SapService::get('zproduct_order/list');
// POST request -> sends JSON body and appends client parameter
$response = SapService::post('zproduct_order/create', [
'product_id' => 123,
'quantity' => 5,
]);
// PUT request
$response = SapService::put('zproduct_order/update/123', [
'quantity' => 10,
]);
// DELETE request
$response = SapService::delete('zproduct_order/delete/123');
2. Using Dependency Injection
use Shakegwapo\SapIcfService\SapService;
class OrderController extends Controller
{
protected $sapService;
public function __construct(SapService $sapService)
{
$this->sapService = $sapService;
}
public function index()
{
return response()->json($this->sapService->get('zproduct_order/list'));
}
}
Named clients
sap_client is the default. clients is the named list, the same idea as connections in config/database.php. Both clients use the same SAP_BASE_URL, username, and password. Only the query value changes.
use Shakegwapo\SapIcfService\Facades\SapService;
// Default client from SAP_CLIENT
SapService::get('zproduct_order/list');
// .../zproduct_order/list?sap-client=500
// Named client from config('sap.clients.888.sap_client')
SapService::client('888')->get('zproduct_order/list');
// .../zproduct_order/list?sap-client=888
SapService::client('820')->post('purchase-orders/cancel', [
'sap_id' => '4200000031',
'rel_code' => '01',
]);
// .../purchase-orders/cancel?sap-client=820
// JSON body: {"sap_id":"4200000031","rel_code":"01"}
client() returns a copy. The shared service, including a singleton injected into a controller, stays on SAP_CLIENT.
public function index(SapService $sap)
{
$from888 = $sap->client('888')->get('zproduct_order/list');
$fromDefault = $sap->get('zproduct_order/list');
}
Add another client by copying the same shape:
'clients' => [
'888' => [
'sap_client' => env('SAP_CLIENT_888', '888'),
],
'820' => [
'sap_client' => env('SAP_CLIENT_820', '820'),
],
'500' => [
'sap_client' => env('SAP_CLIENT_500', '500'),
],
],
client('888') resolves in this order:
config('sap.clients.888.sap_client')- A plain value at
config('sap.clients.888'), if you stored a string instead of an array - The old key
config('sap.sap_client_888') - The name you passed, sent as the client number
A missing clients list does not throw. client('999') sends ?sap-client=999. client('') falls back to sap_client.
If you already published config/sap.php, add the clients array yourself. vendor:publish will not overwrite that file.
Per-Request Client Override
A payload key still overrides the client for that single call, including a call that already used client(). The key is removed from the JSON body before the request is sent.
use Shakegwapo\SapIcfService\Facades\SapService;
$response = SapService::post('purchase-orders/cancel', [
'sap-client' => '888',
'sap_id' => '4200000031',
'rel_code' => '01',
]);
// Endpoint: .../purchase-orders/cancel?sap-client=888
// Body: {"sap_id":"4200000031","rel_code":"01"}
// Payload wins over client('820')
SapService::client('820')->post('purchase-orders/cancel', [
'sap-client' => '888',
'sap_id' => '4200000031',
]);
// Endpoint: .../purchase-orders/cancel?sap-client=888
The override key is client_parameter (sap-client by default). sap-client is also accepted when the configured parameter name is different.
Custom Parameter Names
If your SAP ICF service expects a parameter other than sap-client (e.g. client or sapclient), set SAP_CLIENT_PARAMETER:
SAP_CLIENT_PARAMETER=client
Now requests will automatically append ?client=500.
Inspect Configuration
You can retrieve active non-sensitive configuration parameters:
$config = SapService::getConfig();
// [
// 'base_url' => 'https://...',
// 'sap_client' => '500',
// 'client_parameter' => 'sap-client',
// 'timeout' => 30,
// 'verify' => true,
// 'username_set' => true,
// 'password_set' => true,
// ]
Error Handling
All HTTP exceptions are automatically caught, logged to Laravel's log channel, and returned as standardized array responses:
ClientException(4xx HTTP status) ->['error' => 'Client error occurred.']ServerException(5xx HTTP status) ->['error' => 'Server error occurred.']ConnectException(Network / timeout) ->['error' => 'Connection error occurred.']RequestException(Generic request error) ->['error' => 'Request error occurred.']
Testing
Run the test suite using PHPUnit:
composer test
License
The MIT License (MIT). Please see License File for more information.