Payments Overview

The Batchmates payment system processes donations through Magpie, supporting GCash, Maya, and card payments via a hosted checkout flow, as well as direct charges against vaulted cards.


Stack

LayerTechnology
BackendLaravel 12
FrontendReact 19 + TypeScript
DatabasePostgreSQL
Payment gatewayMagpie

Two Payment Paths

PathWhen usedMechanism
Magpie CheckoutOne-time donations (GCash, Maya, card)Redirect to Magpie-hosted page
Charge saved cardOne-time or recurring with a vaulted cardDirect API charge via customer + source

Key Backend Services

FileResponsibility
app/Services/MagpieService.phpRaw HTTP calls to Magpie API
app/Services/MagpieTransactionService.phpBusiness logic — initiate, charge, webhook handling
app/Services/FeeCalculator.phpFee computation

Checkout Flow (High Level)

  1. User selects a campaign and donation amount on /donate
  2. Frontend posts to POST /api/v1/donations with payment_gateway: 'magpie'
  3. Backend creates a pending Donation record and calls Magpie Checkout API
  4. Backend returns { redirectUrl } — frontend redirects the browser to Magpie's hosted page
  5. User completes payment (GCash / Maya / card)
  6. Magpie redirects back and fires a webhook
  7. Webhook handler marks the donation completed and increments campaign balances

See Donation Flow for the full step-by-step sequence.


Saved Card Flow (High Level)

  1. User adds a card via a two-step flow: frontend tokenizes via POST /api/v1/payments/magpie/create-source, then saves the resulting source ID via POST /api/v1/payment-methods
  2. User initiates a donation via POST /api/v1/donations/charge-saved with the saved payment method ID
  3. Backend charges the vaulted card directly — no redirect needed
  4. Webhook charge.succeeded marks the donation complete

See Saved Cards for full vaulting and charging details.


API Endpoint Reference

MethodPathAuthDescription
POST/api/v1/donationsSanctumCreate donation + initiate Magpie checkout
POST/api/v1/donations/charge-savedSanctumCharge a vaulted card directly
POST/api/v1/payments/magpie/create-sourceSanctumTokenize a card with Magpie (step 1 of card vaulting)
POST/api/v1/payment-methodsSanctumVault a tokenized card source (step 2 of card vaulting)
GET/api/v1/payment-methodsSanctumList user's saved cards
DELETE/api/v1/payment-methods/{id}SanctumRemove a saved card
POST/api/v1/payment-methods/{id}/set-defaultSanctumSet default card
GET/api/v1/payments/magpie/successPublicPost-checkout success redirect
GET/api/v1/payments/magpie/cancelPublicPost-checkout cancel redirect
POST/api/v1/payments/magpie/webhookWebhook sigMagpie event webhook

Further Reading

Was this page helpful?