Installation:
composer require sumup/sumup-ecom-php-sdk
(Note: This SDK is deprecated; consider migrating to sumup-php for new projects.)
First Use Case: Initialize the SDK with credentials and create a checkout:
$sumup = new \SumUp\SumUp([
'app_id' => env('SUMUP_APP_ID'),
'app_secret' => env('SUMUP_APP_SECRET'),
'code' => env('SUMUP_AUTH_CODE'), // From OAuth flow
]);
$checkout = $sumup->getCheckoutService()->create(1000, 'EUR', 'order_123', 'merchant_456');
return $checkout->getBody()->id; // Return to frontend for processing
Where to Look First:
Checkouts.md, Customers.md).SumUpAuthenticationException, SumUpResponseException, and SumUpServerException in controllers..env for credentials (e.g., SUMUP_APP_ID, SUMUP_APP_SECRET).OAuth Flow Integration:
getAuthorizationService() to handle token refresh:
$auth = $sumup->getAuthorizationService();
$token = $auth->refreshToken($refreshToken);
Checkout Processing:
$checkout = $sumup->getCheckoutService()->create(
$amount, $currency, $reference, $merchantCode
);
$transaction = $sumup->getTransactionService()->capture($checkoutId);
Customer Management:
$customer = $sumup->getCustomerService()->create(
'customer_123',
['email' => '[email protected]'],
['street' => '123 Main St']
);
$instruments = $sumup->getCustomerService()->getPaymentInstruments('customer_123');
Custom API Calls:
Custom service for unsupported endpoints:
$custom = new \SumUp\Services\Custom($sumup->getHttpClient(), $sumup->getAccessToken());
$response = $custom->request('GET', '/v0.1/me');
Service Container Binding: Bind the SDK to Laravel’s container for dependency injection:
$app->singleton(\SumUp\SumUp::class, function ($app) {
return new \SumUp\SumUp([
'app_id' => $app['config']['services.sumup.app_id'],
'app_secret' => $app['config']['services.sumup.app_secret'],
'access_token' => $app['cache']->get('sumup_access_token'),
]);
});
Middleware for Auth: Create middleware to validate SumUp tokens:
public function handle($request, Closure $next) {
try {
$sumup = app(\SumUp\SumUp::class);
$sumup->getAccessToken(); // Throws if invalid
return $next($request);
} catch (\SumUp\Exceptions\SumUpAuthenticationException $e) {
return redirect()->route('sumup.auth');
}
}
Event Listeners:
Listen for payment events (e.g., checkout.created) and trigger Laravel events:
public function handle($event) {
event(new SumUpCheckoutCreated($event->checkout));
}
Queue Jobs:
Offload SumUp API calls to queues (e.g., SumUpCaptureJob):
class SumUpCaptureJob implements ShouldQueue {
public function handle() {
$sumup->getTransactionService()->capture($this->checkoutId);
}
}
Deprecation Warning:
sumup-php for long-term support.Token Management:
SumUpAuthenticationException and refresh tokens.$token = $sumup->getAccessToken();
Cache::put('sumup_access_token', $token->getToken(), $token->getExpiresIn());
HTTP Client Issues:
ca_bundle_path:
$sumup = new \SumUp\SumUp([
'ca_bundle_path' => storage_path('certs/ca.pem'),
]);
$sumup = new \SumUp\SumUp(['use_guzzlehttp_over_curl' => true]);
Idempotency:
POST requests (e.g., Idempotency-Key: abc123). Use Laravel’s Str::uuid() for unique keys:
$headers = ['Idempotency-Key' => Str::uuid()];
$response = $custom->request('POST', '/v0.1/checkouts', $payload, $headers);
Rate Limiting:
use Symfony\Component\RateLimiter\RateLimiter;
$limiter = new RateLimiter(100, 60);
if (!$limiter->consume()) {
sleep($limiter->waitTime());
}
Enable SDK Logging:
$sumup = new \SumUp\SumUp([
'logger' => new \Monolog\Logger('sumup', [
new \Monolog\Handler\StreamHandler(storage_path('logs/sumup.log'))
]),
]);
Inspect Raw Responses:
$client = new \SumUp\HttpClients\GuzzleHttpClient([
'debug' => fopen(storage_path('logs/sumup_debug.log'), 'w'),
]);
$sumup = new \SumUp\SumUp(['http_client' => $client]);
Common Errors:
scopes in config.Custom HTTP Client:
SumUpHttpClientInterface for custom logic (e.g., retries, proxies):
class CustomHttpClient implements SumUpHttpClientInterface {
public function request($method, $url, $options) {
// Add custom logic (e.g., proxy, signing)
return GuzzleHttp::request($method, $url, $options);
}
}
Response Decorators:
\SumUp\HttpClients\Response to add Laravel-specific data:
class LaravelResponse extends \SumUp\HttpClients\Response {
public function toLaravelCollection() {
return collect($this->getBody())->map(fn($item) => new PaymentModel($item));
}
}
Service Decorators:
class LoggingCheckoutService implements \SumUp\Services\CheckoutsInterface {
protected $decorated;
public function __construct(\SumUp\Services\Checkouts $checkout) {
$this->decorated = $checkout;
}
public function create($amount, $currency, $reference, $merchantCode) {
Log::info("Creating checkout for {$reference}");
return $this->decorated->create($amount, $currency, $reference, $merchantCode);
}
}
How can I help you explore Laravel packages today?