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 explicitly designed for Laravel (facades, service providers, Artisan commands) while maintaining framework-agnostic core functionality. This reduces friction for Laravel-based e-commerce systems.
  • Modular API surface: Clear separation of concerns between Checkout, Admin, Subscriptions, and Webhooks aligns with Svea’s API design and simplifies adoption for specific use cases (e.g., starting with Checkout-only).
  • Fluent, expressive API: The builder pattern (when(), unless(), chaining) mirrors Laravel’s query builder and form request patterns, easing adoption for PHP/Laravel developers.
  • Idempotency and retries: Built-in support for idempotency keys and exponential backoff addresses common payment API challenges (e.g., race conditions, transient failures).

Integration Feasibility

  • Laravel-first but flexible: Auto-discovery and facades reduce boilerplate, but the core SveaClient can be instantiated manually for non-Laravel contexts (e.g., CLI scripts, testing).
  • Webhook integration: First-class support for HMAC-SHA256 verification, subscription management, and Laravel events (SveaWebhookReceived) enables seamless event-driven workflows (e.g., order fulfillment, fraud detection).
  • Testing layer: Svea::fake() with assertion helpers mirrors Laravel’s Http::fake(), accelerating test-driven development for payment flows.
  • Minor-unit convention: Svea’s requirement for minor-unit values (e.g., 29900 = 299.00 SEK) is explicitly documented, reducing surprises during integration.

Technical Risk

  • Dependency on Svea’s API: Changes to Svea’s API (e.g., new endpoints, deprecated fields) may require package updates. The package’s maturity (releases, changelog) mitigates this risk.
  • Laravel version lock: Supports Laravel 11–13, which may limit adoption for teams using older/new versions. However, the core library is framework-agnostic.
  • Webhook reliability: Inbound webhook handling depends on:
    • Correct webhook_secret configuration.
    • Network reliability (e.g., retries for failed deliveries).
    • Application responsiveness to process events (e.g., database locks, slow handlers).
  • Performance overhead: Exponential retries and async task polling (HTTP 202) may introduce latency for time-sensitive operations (e.g., real-time inventory updates).

Key Questions

  1. Authentication:
    • How will shared_secret and webhook_secret be secured? (e.g., vault, environment variables, Laravel’s config).
    • Are there plans to rotate secrets, and how will this impact the SDK?
  2. Error Handling:
    • How will SveaApiException be logged/monitored? (e.g., Sentry, Laravel’s App\Exceptions\Handler).
    • What fallback mechanisms exist for critical failures (e.g., retry deadlines, manual intervention)?
  3. Testing:
    • Will Svea::fake() be used for unit/feature tests, or will a dedicated test environment be preferred?
    • How will webhook tests be implemented (e.g., mocking SveaWebhookReceived events)?
  4. Scaling:
    • How will the application handle high volumes of webhook events? (e.g., queue workers, batch processing).
    • Are there plans to use Svea’s async task polling for long-running operations (e.g., refunds)?
  5. Compliance:
    • Does the package support PCI-DSS or GDPR requirements (e.g., data encryption, audit logs)?
    • How will sensitive data (e.g., shared_secret) be handled in logs or monitoring tools?

Integration Approach

Stack Fit

  • Laravel: Ideal for teams already using Laravel’s ecosystem (facades, queues, events). The package’s Laravel integration (service provider, Artisan commands) reduces setup time.
  • Non-Laravel PHP: The core SveaClient can be used in any PHP 8.2+ application, but loses Laravel-specific conveniences (e.g., facades, event dispatching).
  • Microservices: The package’s modularity makes it suitable for splitting payment logic into a dedicated service (e.g., using the core SveaClient in a Go/Python service).
  • Testing: The Svea::fake() layer integrates with Laravel’s testing tools (e.g., Http::fake()), enabling rapid test development.

Migration Path

  1. Assessment Phase:
    • Audit existing payment flows (e.g., Checkout, refunds, webhooks) to map to Svea’s API.
    • Identify gaps (e.g., custom payment methods, multi-currency support).
  2. Pilot Integration:
    • Start with Checkout and Webhooks in a non-production environment.
    • Use Svea::fake() to test edge cases (e.g., failed payments, duplicate webhooks).
  3. Gradual Rollout:
    • Replace legacy payment logic with the SDK, one feature at a time (e.g., first Checkout, then Admin operations).
    • Use Artisan commands (e.g., svea:subscription:add) to manage webhook subscriptions.
  4. Webhook Implementation:
    • Set up a dedicated endpoint (e.g., /webhooks/svea) to handle inbound events.
    • Dispatch SveaWebhookReceived events for decoupled processing (e.g., via queues).
  5. Monitoring:
    • Integrate Wiretap or similar tools to log API calls/responses for debugging.
    • Set up alerts for failed webhook deliveries or API errors.

Compatibility

  • Laravel Versions: Confirmed compatibility with 11–13. For older/new versions, the core library can be used with minimal adjustments.
  • PHP Versions: Supports 8.2–8.5. Ensure your environment matches this range.
  • Svea API: The package abstracts Svea’s API changes, but breaking changes may require updates. Monitor Svea’s API docs for deprecations.
  • Third-Party Tools:
    • Wiretap: Optional but recommended for HTTP tracing. Requires additional setup.
    • Queues: Laravel’s queue system can process webhook events asynchronously.

Sequencing

  1. Configuration:
    • Publish the config file (php artisan vendor:publish --tag=svea-config).
    • Set environment variables (SVEA_MERCHANT_ID, SVEA_SHARED_SECRET, etc.).
  2. Checkout Integration:
    • Implement order creation (e.g., Svea::checkout()->create()).
    • Embed the Svea snippet in your checkout page.
  3. Webhook Setup:
    • Register subscriptions (php artisan svea:subscription:add).
    • Implement the webhook endpoint and event handling.
  4. Admin Operations:
    • Add refunds, cancellations, or deliveries (e.g., Svea::admin()->order()->deliver()).
  5. Testing:
    • Write tests using Svea::fake().
    • Test webhook scenarios (e.g., successful/failed payments).
  6. Monitoring:
    • Set up logging for API calls and webhook events.
    • Configure alerts for errors or retries.

Operational Impact

Maintenance

  • Package Updates:
    • Monitor for new releases (e.g., via Packagist or GitHub).
    • Test updates in a staging environment before production deployment.
  • Configuration Drift:
    • Centralize Svea config (e.g., Laravel’s config/svea.php) to avoid hardcoded values.
    • Use environment variables for secrets (e.g., SVEA_SHARED_SECRET).
  • Deprecation Handling:
    • Svea’s API changes may require SDK updates. Plan for periodic reviews of the package’s changelog.
  • Artisan Commands:
    • Commands like svea:subscription:list can be used for operational checks (e.g., verifying webhook subscriptions).

Support

  • Troubleshooting:
    • Use Wiretap or Guzzle middleware to inspect API requests/responses.
    • Leverage SveaApiException for structured error handling (e.g., log status codes and responses).
  • Webhook Debugging:
    • Verify Svea-Signature headers match the webhook_secret.
    • Check for duplicate or malformed events (e.g., using Laravel’s SveaWebhookReceived event listeners).
  • Community/Documentation:
    • The package includes a README, changelog, and example Laravel project. For advanced issues, engage with the maintainers or Svea’s support.

Scaling

  • Webhook Volume:
    • Use Laravel queues to process SveaWebhookReceived events asynchronously.
    • Batch processing for high-volume scenarios (e.g., bulk refunds).
  • API Rate Limits:
    • Configure SVEA_MAX_RETRIES and SVEA_TIMEOUT to handle 429/5xx errors.
    • Monitor Svea’s API limits and adjust retries accordingly.
  • Async Tasks:

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.
terminal42/code-quality-tools
codifyo/ts-generator-bundle
andydefer/laravel-cluster
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity
christhompsontldr/laravel-inky