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

Whop Php Sdk Laravel Package

devmatchable/whop-php-sdk

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Installation

    composer require devmatchable/whop-php-sdk
    

    Add the SDK to your config/services.php:

    'whop' => [
        'secret_key' => env('WHOP_SECRET_KEY'),
        'api_url' => env('WHOP_API_URL', 'https://api.whop.com'),
    ],
    
  2. First Use Case: Create a Customer

    use Whop\Whop;
    
    $whop = new Whop(config('services.whop.secret_key'));
    $customer = $whop->customers()->create([
        'email' => 'user@example.com',
        'name' => 'John Doe',
    ]);
    
  3. Where to Look First

    • Documentation: Check the Whop API Docs for endpoints.
    • SDK Source: Browse vendor/devmatchable/whop-php-sdk/src/Whop/ for available methods.
    • Examples: Look for tests/ in the SDK for usage patterns.

Implementation Patterns

Core Workflows

  1. Customer Management

    • Create/Update: Use customers()->create() or customers()->update().
    • Fetch: Retrieve with customers()->get($id) or list via customers()->all().
    • Webhooks: Subscribe to events like customer.created via Whop dashboard.
  2. Subscription Handling

    • Create Subscription:
      $subscription = $whop->subscriptions()->create([
          'customer_id' => $customer->id,
          'plan_id' => 'monthly_plan_123',
      ]);
      
    • Cancel/Resume:
      $whop->subscriptions()->cancel($subscription->id);
      $whop->subscriptions()->resume($subscription->id);
      
  3. Payment Processing

    • Charge a Customer:
      $charge = $whop->charges()->create([
          'customer_id' => $customer->id,
          'amount' => 1000, // cents
          'currency' => 'USD',
      ]);
      
    • Refunds:
      $whop->charges()->refund($charge->id);
      
  4. Webhook Handling

    • Middleware: Create a Laravel middleware to verify Whop webhook signatures:
      public function handle($request, Closure $next) {
          $whop = new Whop(config('services.whop.secret_key'));
          if (!$whop->verifyWebhook($request->getContent(), $request->header('whop-signature'))) {
              abort(403);
          }
          return $next($request);
      }
      
    • Route:
      Route::post('/whop-webhook', [WhopWebhookController::class, 'handle']);
      
  5. Integration with Laravel Ecosystem

    • Events: Dispatch Laravel events on Whop webhook receipt:
      event(new SubscriptionCreated($subscription));
      
    • Jobs: Queue async tasks (e.g., sending emails) after Whop actions:
      SubscriptionCreated::dispatch($subscription)->onQueue('whop');
      

Gotchas and Tips

Common Pitfalls

  1. API Key Security

    • Never hardcode WHOP_SECRET_KEY in your code. Always use .env.
    • Restrict webhook IPs in Whop dashboard to your server’s IP.
  2. Idempotency

    • Whop supports idempotency keys for POST requests (e.g., X-Idempotency-Key). Use them for retries:
      $whop->withOptions(['idempotency_key' => 'unique_key_123'])->customers()->create(...);
      
  3. Rate Limiting

    • Whop enforces rate limits (~1000 requests/minute). Cache frequent API calls (e.g., customer lists) in Laravel’s cache:
      $customers = Cache::remember('whop_customers', 60, function() {
          return $whop->customers()->all();
      });
      
  4. Webhook Delays

    • Webhooks may take up to 5 minutes to deliver. Use exponential backoff in retries:
      $attempts = 0;
      while ($attempts < 3) {
          try {
              $whop->verifyWebhook(...);
              break;
          } catch (Exception $e) {
              sleep(2 ** $attempts);
              $attempts++;
          }
      }
      
  5. Currency/Amount Handling

    • Whop expects amounts in cents (not dollars). Convert carefully:
      $amountInDollars = 9.99;
      $amountInCents = $amountInDollars * 100; // 999
      

Debugging Tips

  1. Enable SDK Logging Add to config/services.php:

    'whop' => [
        'debug' => env('WHOP_DEBUG', false),
    ],
    

    Logs will appear in Laravel’s log channel.

  2. Test with Sandbox Use Whop’s sandbox mode for testing:

    $wh
    
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.
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
spatie/mailcoach-vapor