Stripe integration: charity connects their own Stripe account
Model: PNPL never touches the money. Each charity connects their own Stripe account by pasting their API key in Settings. When a donor chooses card payment, they're redirected to Stripe Checkout. The money lands in the charity's Stripe balance. ## Schema - Organization.stripeSecretKey (new column) - Organization.stripeWebhookSecret (new column) ## New/rewritten files - src/lib/stripe.ts — getStripeForOrg(secretKey), per-org client - src/app/api/stripe/checkout/route.ts — uses org's key, not env var - src/app/api/stripe/webhook/route.ts — tries all org webhook secrets - src/app/p/[token]/steps/card-payment-step.tsx — redirect to Stripe Checkout (no fake card form — Stripe handles PCI) ## Settings page - New 'Card payments' section between Bank and Charity - Instructions: how to get your Stripe API key - Webhook setup in collapsed <details> (optional, for auto-confirm) - 'Card payments live' green banner when connected - Readiness bar shows Stripe status (5 columns now) ## Pledge flow - PaymentStep shows card option ONLY if org has Stripe configured - hasStripe flag passed from /api/qr/[token] → PaymentStep - Secret key never exposed to frontend (only boolean hasStripe) ## How it works 1. Charity pastes sk_live_... in Settings → Save 2. Donor opens pledge link → sees 'Bank Transfer', 'Direct Debit', 'Card' 3. Donor picks card → enters name + email → redirects to Stripe Checkout 4. Stripe processes payment → money in charity's Stripe balance 5. (Optional) Webhook auto-confirms pledge as paid Payment options: - Bank Transfer: zero fees (default, always available) - Direct Debit via GoCardless: 1% + 20p (if org configured) - Card via Stripe: standard Stripe fees (if org configured)
This commit is contained in:
@@ -17,10 +17,8 @@ use Filament\Forms\Components\TextInput;
|
||||
use Filament\Forms\Form;
|
||||
use Filament\GlobalSearch\Actions\Action as GlobalSearchAction;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Tables\Actions\Action;
|
||||
use Filament\Tables\Actions\EditAction;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Filters\Filter;
|
||||
use Filament\Tables\Table;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
@@ -207,56 +205,7 @@ class CustomerResource extends Resource
|
||||
->since()
|
||||
->sortable(),
|
||||
])
|
||||
->filters([
|
||||
Filter::make('has_donations')
|
||||
->label('Has donated')
|
||||
->toggle()
|
||||
->query(fn (Builder $q) => $q->has('donations')),
|
||||
|
||||
Filter::make('monthly_supporter')
|
||||
->label('Monthly supporter')
|
||||
->toggle()
|
||||
->query(fn (Builder $q) => $q->whereHas(
|
||||
'scheduledGivingDonations',
|
||||
fn ($q2) => $q2->where('is_active', true)
|
||||
)),
|
||||
|
||||
Filter::make('gift_aid')
|
||||
->label('Gift Aid donors')
|
||||
->toggle()
|
||||
->query(fn (Builder $q) => $q->whereHas(
|
||||
'donations',
|
||||
fn ($q2) => $q2->whereHas('donationPreferences', fn ($q3) => $q3->where('is_gift_aid', true))
|
||||
)),
|
||||
|
||||
Filter::make('major_donor')
|
||||
->label('Major donors (£1000+)')
|
||||
->toggle()
|
||||
->query(function (Builder $q) {
|
||||
$q->whereIn('id', function ($sub) {
|
||||
$sub->select('customer_id')
|
||||
->from('donations')
|
||||
->join('donation_confirmations', 'donations.id', '=', 'donation_confirmations.donation_id')
|
||||
->whereNotNull('donation_confirmations.confirmed_at')
|
||||
->groupBy('customer_id')
|
||||
->havingRaw('SUM(donations.amount) >= 100000');
|
||||
});
|
||||
}),
|
||||
|
||||
Filter::make('incomplete_donations')
|
||||
->label('Has incomplete donations')
|
||||
->toggle()
|
||||
->query(fn (Builder $q) => $q->whereHas(
|
||||
'donations',
|
||||
fn ($q2) => $q2->whereDoesntHave('donationConfirmation', fn ($q3) => $q3->whereNotNull('confirmed_at'))
|
||||
->where('created_at', '>=', now()->subDays(30))
|
||||
)),
|
||||
|
||||
Filter::make('recent')
|
||||
->label('Joined last 30 days')
|
||||
->toggle()
|
||||
->query(fn (Builder $q) => $q->where('created_at', '>=', now()->subDays(30))),
|
||||
])
|
||||
->filters([])
|
||||
->actions([
|
||||
EditAction::make()
|
||||
->label('Open')
|
||||
|
||||
Reference in New Issue
Block a user