Stripe Live Key Setup
March 24, 2025 · AI Conversations
—
### ✅ 1. **Get Your Live API Keys**
– Go to [https://dashboard.stripe.com](https://dashboard.stripe.com)
– Switch to **Live Mode** (toggle on the left sidebar)
– Get your:
– **Publishable key**
– **Secret key**
—
### ✅ 2. **Install Stripe PHP SDK**
If you haven’t already:
composer require stripe/stripe-php
—
### ✅ 3. **Set Your Stripe Keys**
In your `.env` file:
STRIPE_KEY=pk_live_xxxxxxxxxxxxxxxxxx
STRIPE_SECRET=sk_live_xxxxxxxxxxxxxxxxxx
In your `config/services.php`:
'stripe' => [
'key' => env('STRIPE_KEY'),
'secret' => env('STRIPE_SECRET'),
],
—
### ✅ 4. **Create a Basic Payment Controller**
use IlluminateHttpRequest;
use StripeStripe;
use StripeCharge;
public function charge(Request $request)
{
StripeStripe::setApiKey(config('services.stripe.secret'));
$charge = StripeCharge::create([
'amount' => 1000, // amount in cents ($10.00)
'currency' => 'usd',
'source' => $request->stripeToken,
'description' => 'Test charge using live key',
]);
return response()->json($charge);
}
—
### ✅ 5. **Frontend Integration (Stripe Elements)**
Use Stripe Elements or a prebuilt checkout. Here's an example using Stripe.js:
<script src="https://js.stripe.com/v3/"></script>
<script>
const stripe = Stripe("{{ config('services.stripe.key') }}");
const elements = stripe.elements();
const card = elements.create('card');
card.mount('#card-element');
document.querySelector('#payment-form').addEventListener('submit', async (e) => {
e.preventDefault();
const { token, error } = await stripe.createToken(card);
if (error) {
alert(error.message);
} else {
const form = document.getElementById('payment-form');
const hiddenInput = document.createElement('input');
hiddenInput.setAttribute('type', 'hidden');
hiddenInput.setAttribute('name', 'stripeToken');
hiddenInput.setAttribute('value', token.id);
form.appendChild(hiddenInput);
form.submit();
}
});
</script>
—
### ✅ 6. **Optional: Webhooks for Status Updates**
You can listen for `payment_intent.succeeded` or `charge.succeeded` events for better confirmation.
—
Let me know:
– Are you using Laravel or plain PHP?
– Do you want to use **Stripe Checkout**, **Elements**, or **direct API calls**?
– Do you need support for **subscriptions**, **one-time payments**, or both?
I'll tailor it more for your setup if needed.