| Home | Getting Started | Core Concepts | Helpers | Extensions | Repo |
The Stripe helper provides a simple interface for integrating Stripe payment processing into your application.
Configure Stripe in your .env file:
STRIPE_SECRET_KEY=sk_test_...
STRIPE_PUBLIC_KEY=pk_test_...
STRIPE_WEBHOOK_SECRET=whsec_...
// Create a payment intent
$intent = tiny::stripe()->createIntent([
'amount' => 2000, // $20.00
'currency' => 'usd',
'payment_method_types' => ['card']
]);
// Process a charge
$charge = tiny::stripe()->charge([
'amount' => 2000,
'currency' => 'usd',
'source' => $tokenId,
'description' => 'Test Charge'
]);
// Create customer
$customer = tiny::stripe()->createCustomer([
'email' => 'customer@example.com',
'source' => $tokenId
]);
// Update customer
tiny::stripe()->updateCustomer($customerId, [
'metadata' => ['order_id' => '123']
]);
// Get customer
$customer = tiny::stripe()->getCustomer($customerId);
// Create subscription
$subscription = tiny::stripe()->subscribe($customerId, [
'price' => 'price_H2ZlLQs9w0cp',
'trial_period_days' => 14
]);
// Update subscription
tiny::stripe()->updateSubscription($subscriptionId, [
'price' => 'price_new_plan'
]);
// Cancel subscription
tiny::stripe()->cancelSubscription($subscriptionId, [
'at_period_end' => true
]);
// Handle webhook
tiny::stripe()->handleWebhook(function($event) {
switch ($event->type) {
case 'payment_intent.succeeded':
// Handle successful payment
break;
case 'customer.subscription.deleted':
// Handle subscription cancellation
break;
}
});
// Attach payment method
tiny::stripe()->attachPaymentMethod($paymentMethodId, $customerId);
// List payment methods
$methods = tiny::stripe()->listPaymentMethods($customerId, [
'type' => 'card'
]);
// Set default payment method
tiny::stripe()->setDefaultPaymentMethod($customerId, $paymentMethodId);
// Create invoice
$invoice = tiny::stripe()->createInvoice($customerId);
// Pay invoice
tiny::stripe()->payInvoice($invoiceId);
// Get invoice PDF
$pdf = tiny::stripe()->getInvoicePDF($invoiceId);
try {
$charge = tiny::stripe()->charge($params);
} catch (TinyStripeException $e) {
// Handle Stripe errors
$error = $e->getMessage();
$code = $e->getStripeCode();
}