Explore real-world examples of SubLoop integrations across different platforms.
Complete subscription management
A full-featured Laravel application with Stripe integration and SubLoop analytics.
Modern e-commerce with analytics
Next.js e-commerce platform with real-time revenue tracking and analytics dashboard.
Analytics dashboard with hooks
React application showcasing SubLoop's React hooks and pre-built components.
WooCommerce integration
WordPress plugin that integrates SubLoop with WooCommerce for subscription analytics.
Cross-platform mobile app
Flutter mobile app with in-app purchases and subscription analytics.
Native mobile experience
React Native app demonstrating payment tracking and analytics integration.
Handle payment webhooks from various providers:
// Stripe webhook handler
Route::post('/webhooks/stripe', function (Request $request) {
$payload = $request->getContent();
$sig_header = $request->header('Stripe-Signature');
$endpoint_secret = config('services.stripe.webhook_secret');
try {
$event = \Stripe\Webhook::constructEvent($payload, $sig_header, $endpoint_secret);
} catch(\Exception $e) {
return response('Webhook signature verification failed.', 400);
}
if ($event->type === 'payment_intent.succeeded') {
$paymentIntent = $event->data->object;
// Track with SubLoop
$subloop = new SubLoop(config('services.subloop.api_key'));
$subloop->payments->createSuccessful(
customerId: $paymentIntent->customer,
amount: $paymentIntent->amount_received / 100,
currency: strtoupper($paymentIntent->currency),
subscriptionId: $paymentIntent->metadata->subscription_id ?? null
);
}
return response('Success', 200);
});
Ready-to-use dashboard components:
// React Analytics Dashboard
import { SubLoopProvider, AnalyticsDashboard } from 'subloop-react';
function App() {
return (
Revenue Analytics
);
}
Process payments in background jobs:
// Laravel Job for processing payments
class ProcessPaymentAnalytics implements ShouldQueue
{
public function __construct(
private string $customerId,
private float $amount,
private string $currency,
private ?string $subscriptionId = null
) {}
public function handle()
{
$subloop = new SubLoop(config('services.subloop.api_key'));
try {
$subloop->payments->createSuccessful(
customerId: $this->customerId,
amount: $this->amount,
currency: $this->currency,
subscriptionId: $this->subscriptionId
);
} catch (Exception $e) {
Log::error('SubLoop payment tracking failed', [
'customer_id' => $this->customerId,
'amount' => $this->amount,
'error' => $e->getMessage()
]);
// Retry the job
$this->fail($e);
}
}
}
// PHPUnit test example
class SubLoopIntegrationTest extends TestCase
{
public function test_successful_payment_tracking()
{
$subloop = new SubLoop('sk_test_key');
$payment = $subloop->payments->createSuccessful(
customerId: 'test_customer',
amount: 29.99,
currency: 'USD',
subscriptionId: 'test_subscription'
);
$this->assertArrayHasKey('id', $payment);
$this->assertEquals('succeeded', $payment['status']);
$this->assertEquals(29.99, $payment['amount']);
}
}
// Jest test example
describe('SubLoop Integration', () => {
test('should track payment successfully', async () => {
const subloop = new SubLoop('sk_test_key');
const payment = await subloop.payments.createSuccessful(
'test_customer',
29.99,
'USD',
'test_subscription'
);
expect(payment.id).toBeDefined();
expect(payment.status).toBe('succeeded');
expect(payment.amount).toBe(29.99);
});
});
Ready to implement SubLoop in your application?