Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/handlers/checkout.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
get_api_key,
get_endpoint_secret,
)
from lib.queue import Queue
from lib.errors import StripeException
import stripe

from lib.types import StripeCheckout

db = Database(url=os.environ["DATABASE_URL"])
queue = Queue(queue_url=os.environ["STRIPE_QUEUE_URL"])
stripe.api_key = get_api_key()


Expand All @@ -24,8 +26,7 @@ def begin_fulfillment(session_id: str):
if not should_process:
return

# TODO: Place this event on the SQS queue for processing.
pass
queue.send({"id": checkout.id})


def process_webhook_request(payload: Any, signature: Any):
Expand Down
12 changes: 12 additions & 0 deletions src/handlers/fulfillment.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import os

import requests
Expand All @@ -19,6 +20,17 @@
stripe.api_key = get_api_key()


def handler(event: dict, context):
"""
Entry point invoked by SQS. Processes each record in the event,
which should contain a checkout session ID in its body.
"""
for record in event["Records"]:
body = json.loads(record["body"])
checkout = StripeCheckout(id=body["id"])
process_fulfillment(checkout)


def process_fulfillment(checkout: StripeCheckout):
"""
Fulfills a successful checkout session.
Expand Down