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

Api Php Sdk Laravel Package

cryptomus/api-php-sdk

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Microservice/Modular Fit: The SDK is lightweight and modular, ideal for Laravel’s service-layer architecture. It can be encapsulated as a dedicated CryptomusService or integrated into existing payment gateways (e.g., PaymentGatewayInterface).
  • Event-Driven Potential: Supports webhook callbacks (url_callback), enabling async event handling (e.g., transaction status updates) via Laravel’s queue:work or Horizon (Laravel Echo).
  • Domain-Specific: Tightly coupled to Cryptomus’s API, reducing abstraction overhead for crypto-specific use cases (e.g., payouts, wallets). Avoids generic crypto SDKs (e.g., Coinbase) if Cryptomus is the exclusive provider.
  • Laravel Synergy:
    • Service Providers: Can be bootstrapped as a Laravel service provider for dependency injection.
    • Facades: Wrap the SDK in a facade (e.g., Cryptomus) for cleaner syntax (e.g., Cryptomus::payout()->create($data)).
    • Eloquent Models: Pair with Eloquent models for transaction persistence (e.g., CryptoTransaction).

Integration Feasibility

  • Low Friction: Composer-based installation with minimal setup (keys + UUID). No database migrations required for basic usage.
  • API Alignment: Cryptomus’s API is RESTful, but the SDK abstracts HTTP clients (likely Guzzle under the hood). Laravel’s Http client can replace it if needed.
  • Error Handling: Built-in RequestBuilderException integrates with Laravel’s exception handling (e.g., render() in App\Exceptions\Handler).
  • Testing: Mockable interfaces for unit testing (e.g., PaymentGateway contract). Use Laravel’s Mockery or Pest for SDK interactions.

Technical Risk

Risk Mitigation Strategy Severity
Deprecated API Monitor Cryptomus’s API docs for breaking changes. Use a wrapper layer to isolate SDK calls. Medium
No Type Safety Add PHP 8.0+ type hints to SDK methods via a decorator pattern or fork. Low
Webhook Reliability Implement retry logic (e.g., Laravel’s retry() helper) for failed callbacks. High
PHP Version Support Drop PHP 5.6 support; enforce PHP 8.0+ in composer.json for modern Laravel (v9+). Medium
No Rate Limiting Add exponential backoff in a Laravel middleware or SDK wrapper. Medium
Lack of Observability Instrument SDK calls with Laravel’s logging (\Log::debug()) or OpenTelemetry. High

Key Questions

  1. API Stability: Has Cryptomus’s API changed since the SDK’s last update (2022)? If yes, what’s the backfill effort?
  2. Webhook Security: How does Cryptomus validate callback requests? (e.g., HMAC signatures). If unsupported, implement a middleware validator.
  3. Idempotency: Does the SDK support idempotent requests for payments/payouts? If not, add a Laravel IdempotencyMiddleware.
  4. Multi-Tenancy: Can the SDK handle multiple merchant UUIDs/keys? If not, extend the Client class or use a config-based approach.
  5. Offline Support: Are there local transaction state checks (e.g., caching payment->info())? If not, implement Laravel’s cache() or Redis.
  6. Compliance: Does the SDK log required data for PCI-DSS/SOC2? If not, wrap calls in a compliance layer (e.g., CryptoTransactionObserver).
  7. Performance: What’s the latency of SDK calls vs. direct API requests? Benchmark with Laravel’s benchmark() helper.
  8. Fallbacks: How to handle Cryptomus API downtime? Implement a circuit breaker (e.g., spatie/fruitful) or fallback to another gateway.

Integration Approach

Stack Fit

  • Laravel Native: The SDK’s simplicity aligns with Laravel’s conventions:
    • Service Container: Register the SDK as a singleton binding:
      $this->app->singleton(CryptomusClient::class, function ($app) {
          return new \Cryptomus\Api\Client(
              config('services.cryptomus.payment_key'),
              config('services.cryptomus.merchant_uuid')
          );
      });
      
    • Config Files: Store keys in config/services.php:
      'cryptomus' => [
          'payment_key' => env('CRYPTOMUS_PAYMENT_KEY'),
          'payout_key' => env('CRYPTOMUS_PAYOUT_KEY'),
          'merchant_uuid' => env('CRYPTOMUS_MERCHANT_UUID'),
          'callback_url' => env('CRYPTOMUS_CALLBACK_URL'),
      ],
      
    • Environment Variables: Use Laravel’s .env for secrets (never commit keys).
  • Queue Workers: Offload async operations (e.g., payouts, webhook processing) to Laravel Queues:
    // Dispatch a job for payout creation
    PayoutJob::dispatch($data)->onQueue('cryptomus');
    
  • Event System: Trigger Laravel events for transaction lifecycle:
    event(new CryptoPaymentCreated($paymentData));
    
    Listen with:
    CryptoPaymentCreated::subscribe(CryptoPaymentSubscriber::class);
    

Migration Path

  1. Phase 1: Proof of Concept (1–2 weeks)

    • Integrate the SDK in a staging environment.
    • Test core flows: payment creation, payouts, and webhook callbacks.
    • Validate against Cryptomus’s sandbox.
    • Deliverable: A CryptomusService class with basic methods.
  2. Phase 2: Laravel Integration (2–3 weeks)

    • Wrap the SDK in Laravel-specific components:
      • Service provider for dependency injection.
      • Facade for cleaner syntax.
      • Eloquent models for transaction persistence (e.g., CryptoTransaction).
    • Implement error handling and logging.
    • Deliverable: SDK fully integrated into Laravel’s ecosystem.
  3. Phase 3: Production Readiness (1–2 weeks)

    • Add monitoring (e.g., Laravel Telescope for SDK metrics).
    • Implement retry logic for failed requests.
    • Configure webhook validation and processing.
    • Deliverable: Production-ready package with documentation.

Compatibility

Component Compatibility Notes
Laravel Version Tested on Laravel 8+ (PHP 8.0+). Use laravel/framework:^9.0 for PHP 8.1+ features.
PHP Extensions Requires json and curl. Ensure these are enabled in php.ini.
Database No strict requirements, but recommend PostgreSQL/MySQL for transaction tables.
Caching Use Laravel’s cache (Redis/Memcached) for rate-limiting or frequent API calls.
Queues Supports Laravel Queues for async operations (e.g., database, redis, beanstalkd).
Webhooks Requires a public endpoint for callbacks. Use Laravel’s route:model or a dedicated controller.

Sequencing

  1. Prerequisites:

    • Cryptomus merchant account and API keys.
    • Laravel project with PHP 8.0+ and Composer.
    • Environment variables configured (.env).
  2. Installation:

    composer require cryptomus/api-php-sdk
    
  3. Configuration:

    • Add keys to config/services.php.
    • Publish config if using a package:
      php artisan vendor:publish --provider="CryptomusServiceProvider"
      
  4. Core Integration:

    • Create a service class (e.g., app/Services/CryptomusService.php):
      namespace App\Services;
      
      use Cryptomus\Api\Client;
      
      class CryptomusService {
          public function __construct(
              protected Client $paymentClient,
              protected Client $payoutClient
          ) {}
      
          public function createPayment(array $data) {
              return $this->paymentClient->create($data);
          }
      }
      
    • Bind the service in AppServiceProvider:
      $this->app->bind(CryptomusService::class, function ($app) {
          return new CryptomusService(
              Client::payment(config('services.cryptomus.payment_key'), config('services.cryptomus.merchant_uuid')),
              Client::payout(config('services.cryptomus.payout_key'), config('services.cryptomus.merchant_uuid'))
          );
      });
      
  5. Webhook Handling:

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