Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Svea Laravel Package

nordkit/svea

Modern PHP SDK for Svea Checkout, Payment Admin, webhook subscriptions and inbound webhook verification. Fluent API with typed value objects, retries, idempotency, async task polling, and a robust testing fake. Includes first-class Laravel integration.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Strong alignment with Laravel ecosystem: The package is designed with Laravel in mind, offering a facade, service provider, and Artisan commands, reducing boilerplate for Laravel-based applications.
  • Modular design: Core functionality (Checkout, Admin, Subscriptions, Webhooks) is decoupled, allowing selective adoption (e.g., using only Checkout API without Subscriptions).
  • Fluent API: The fluent builder pattern (when(), unless()) enhances readability and maintainability, especially for complex order flows.
  • Framework-agnostic core: While Laravel-optimized, the package can be used in non-Laravel PHP apps via direct SveaClient instantiation, improving flexibility.

Integration Feasibility

  • Seamless Laravel integration: Auto-discovery of the service provider and facade eliminates manual setup, reducing friction.
  • Webhook handling: Built-in HMAC-SHA256 verification and SveaWebhookReceived event decouple webhook processing from routes, aligning with Laravel’s event-driven architecture.
  • Testing support: Svea::fake() mimics HTTP interactions (similar to Laravel’s Http::fake()), enabling isolated unit/feature tests without external dependencies.
  • Idempotency keys: Critical for retry logic in distributed systems (e.g., queues), ensuring safety during transient failures.

Technical Risk

  • Dependency on Laravel components: Optional illuminate/support for facades/artisans may introduce version constraints (Laravel 11–13). Non-Laravel users must handle configuration manually.
  • Minor-unit convention: Svea’s requirement for minor-unit values (e.g., 29900 for 299.00 SEK) demands careful validation in application logic to avoid arithmetic errors.
  • Webhook security: Misconfiguration of webhook_secret or Svea-Signature handling could expose endpoints to replay attacks. Requires rigorous validation in middleware.
  • Async task polling: HTTP 202 responses require polling logic, which must be implemented by the consumer (e.g., retries with exponential backoff).

Key Questions

  1. Laravel Version Compatibility:

    • How will the team handle potential breaking changes if Laravel 14+ introduces incompatibilities with illuminate/support?
    • Mitigation: Monitor Laravel releases and test early; consider a wrapper layer for facade/artisan logic if needed.
  2. Error Handling Strategy:

    • How will SveaApiException hierarchies be mapped to application-level errors (e.g., retries vs. user notifications)?
    • Mitigation: Define a custom exception handler or middleware to standardize responses.
  3. Webhook Scaling:

    • What mechanisms will ensure webhook endpoints scale under high-volume traffic (e.g., load balancing, rate limiting)?
    • Mitigation: Use Laravel’s queue system to process webhooks asynchronously.
  4. Testing Coverage:

    • Will Svea::fake() suffice for all test scenarios, or are additional mocks needed for edge cases (e.g., retries, async tasks)?
    • Mitigation: Supplement with manual mocks for complex flows.
  5. Idempotency in Queues:

    • How will idempotency keys interact with Laravel’s queue system (e.g., duplicate jobs)?
    • Mitigation: Use Laravel’s unique() or uniqueForJob to deduplicate jobs by idempotency key.

Integration Approach

Stack Fit

  • Laravel: Ideal for Laravel apps due to built-in facades, service providers, and Artisan commands. Non-Laravel PHP apps can use the core SveaClient with minimal overhead.
  • Guzzle HTTP Client: Leverages Guzzle’s middleware stack (e.g., Wiretap for tracing, retries for resilience), which integrates cleanly with Laravel’s HTTP client.
  • Event-Driven Architecture: SveaWebhookReceived events enable decoupled processing, aligning with Laravel’s event system (e.g., broadcasting, queues).

Migration Path

  1. Pilot Phase:
    • Replace existing Svea integrations (e.g., Checkout, Admin) with nordkit/svea in a single feature (e.g., subscriptions).
    • Use Svea::fake() to test in isolation before cutting over.
  2. Gradual Rollout:
    • Migrate webhook handling first (low risk, high visibility).
    • Replace Checkout API calls incrementally, validating responses against the old implementation.
  3. Final Cutover:
    • Update configuration (.env, config/svea.php) and remove legacy Svea SDK code.
    • Run feature tests with Svea::fake() to ensure full coverage.

Compatibility

  • Laravel 11–13: Fully supported. Test for compatibility if using Laravel 10 or 14+.
  • PHP 8.2–8.5: Required. Ensure CI/CD pipelines enforce this constraint.
  • Guzzle 7.8+: Dependency is managed by the package; no action needed unless upgrading Guzzle globally.
  • Svea API: The package abstracts Svea’s API changes, but breaking changes (e.g., new endpoints) may require updates.

Sequencing

  1. Configuration:
    • Publish the config file (php artisan vendor:publish --tag=svea-config) and set .env variables.
  2. Webhooks:
    • Register subscriptions via Artisan (php artisan svea:subscription:add) and implement the SveaWebhookReceived event listener.
  3. Checkout Flow:
    • Replace checkout creation with the fluent API (e.g., Svea::checkout()->create()).
  4. Admin Operations:
    • Migrate deliver/cancel/credit logic to use Svea::admin()->order()->deliver().
  5. Testing:
    • Replace mocks with Svea::fake() and add assertions for Svea-specific responses (e.g., Svea::assertCreated()).

Operational Impact

Maintenance

  • Low-Ceremony Updates:
    • Composer updates (composer update nordkit/svea) are straightforward due to clear versioning and changelog.
    • Laravel’s auto-discovery reduces maintenance overhead for facades/artisans.
  • Configuration Management:
    • Centralized .env and config/svea.php simplify environment-specific tweaks (e.g., test/production URLs).
  • Dependency Updates:
    • Monitor guzzlehttp/guzzle and illuminate/support for breaking changes, especially if using Laravel outside 11–13.

Support

  • Debugging:
    • Wiretap Integration: Enables HTTP request/response logging for troubleshooting (e.g., failed webhooks, retries).
    • Artisan Commands: svea:subscription:list/get provide visibility into subscription statuses.
    • Typed Exceptions: SveaApiException hierarchy aids in pinpointing issues (e.g., 401 Unauthorized vs. 429 Too Many Requests).
  • Error Recovery:
    • Idempotency keys and retries (exponential backoff) mitigate transient failures in Admin operations.
    • Async task polling (TaskResponse) requires application-level handling (e.g., retry queues).

Scaling

  • Webhook Load:
    • Laravel’s queue system can process webhooks asynchronously, scaling horizontally with more workers.
    • Rate limiting (e.g., SVEA_MAX_RETRIES) prevents overload during spikes.
  • Checkout Throughput:
    • Stateless SveaClient instances scale horizontally; no shared state between requests.
    • Consider connection pooling (e.g., Guzzle’s HandlerStack) for high-volume APIs.
  • Database Impact:
    • Minimal; only stores Svea order IDs/snippets (e.g., in orders table). Webhook events can be logged to a svea_webhooks table if auditing is needed.

Failure Modes

Failure Scenario Impact Mitigation
Webhook signature mismatch Silent drops or security breaches Validate Svea-Signature in middleware; log failures.
Svea API downtime Checkout/Admin operations fail Implement retries with exponential backoff; notify users.
Idempotency key collisions Duplicate payments/credits Use UUIDs or database sequences for keys; validate uniqueness.
Async task polling timeout Stuck HTTP 202 responses Set reasonable timeouts; implement dead-letter queues for unresolved tasks.
Configuration errors (e.g., wrong shared_secret) All API calls fail Validate config on boot; use .env.example to prevent misconfigurations.

Ramp-Up

  • Onboarding:
    • For Developers:
      • Start with the example Laravel app to understand the full flow.
      • Focus on Svea::fake() for testing; avoid touching production APIs until ready.
    • For Ops:
      • Document .env requirements and Wiretap
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
iio/libmergepdf
redaxo/project
zatona-eg/zatona-eg-api
patrickbussmann/oauth2-apple
3brs/enterprise-security-bundle
ardenexal/fhir-models
ardenexal/fhir-validation
dpfx/laravel-livewire-wizards
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
crudly/encrypted
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony