Skip to content

Feat/65 stripe webhook handler#75

Open
hajunk05 wants to merge 7 commits into
mainfrom
feat/65-stripe-webhook-handler
Open

Feat/65 stripe webhook handler#75
hajunk05 wants to merge 7 commits into
mainfrom
feat/65-stripe-webhook-handler

Conversation

@hajunk05

Copy link
Copy Markdown
Contributor

Description

Adds a stripe webhook handler that reconciles payment state onto registrations. Handles completed payments, expired payments, failed payments, and refunded payments.

Closes #65

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Manual testing (requires screenshots or videos)

5 Test cases: 5/5

Setup:

  • Created a Stripe test account, then added the API key and secret key to .env
  • Triggered events via the stripe CLI against the local endpoint
  • Also initiated a Stripe CLI listener

There was already an existing social session, so I used this, with a new User I created using my email, to create registrations for that social session.

Test 1: Successful payment checkout

Created a new registration for a social session
image

Then ran:

stripe trigger checkout.session.completed \
    --override checkout_session:metadata.registrationId=6a1a24abb771e5d0ad258c9a

Payment Status: Pending -> Paid, with amount paid populated from nothing to 30.
image

Confirmed via Stripe CLI listener output:
image

Test 2: Idempotency

On the paid registration from Test 1, re-ran the same command

stripe trigger checkout.session.completed \
    --override `checkout_session:metadata.registrationId=6a1a24abb771e5d0ad258c9a`

Temporarily added a console.log to check it’s skipped here if paymentStatus is already paid.
image

Then confirmed it skips:
image

Test 3: Checkout Expired

New social session registration
image

Then ran:

stripe trigger checkout.session.expired \
    --override checkout_session:metadata.registrationId=6a1a269ab771e5d0ad258d0d

Registration status: Pending -> Cancelled:
image

Confirmed via Stripe CLI listener output:
image

Test 4: Payment Failed

Another new social session registration
image

Then ran:

stripe trigger payment_intent.payment_failed \
    --override payment_intent:metadata.registrationId=6a1a27feb771e5d0ad258dd1

Registration Status: Pending -> Cancelled
image

Confirmed via Stripe CLI listener output:
image

Test 5: Refund

Last new social session registration:
image

Then ran these two commands in series:

# 1. Create + confirm PaymentIntent (NZD 20.00)
stripe payment_intents create \
    --amount=2000 --currency=nzd \
    -d "metadata[registrationId]=6a1a2992b771e5d0ad258e1f" \
    -d "payment_method=pm_card_visa" -d "confirm=true" \
    -d "return_url=http://localhost:3000"
# → pi_3TcaYmRQexddMwff1Hqna327 (amount_received 2000)

# 2. Refund it
stripe refunds create -d "payment_intent=pi_3TcaYmRQexddMwff1Hqna327"

Registration Status: Registered -> Cancelled
Payment Status: Paid (After first command) -> Refunded (After second command)
image

Checklist before requesting a review

  • My code follows the style guidelines of this project
  • [ ] I have commented my code in hard-to-understand areas
  • I have made corresponding changes to the documentation if needed
  • I've requested a review from another team member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BACKEND] Stripe webhook handler to reconcile payment state onto registrations

1 participant