|
3 | 3 | ScanCommand, |
4 | 4 | TransactWriteItemsCommand, |
5 | 5 | UpdateItemCommand, |
| 6 | + PutItemCommand, |
6 | 7 | } from "@aws-sdk/client-dynamodb"; |
7 | 8 | import { marshall, unmarshall } from "@aws-sdk/util-dynamodb"; |
8 | 9 | import { withRoles, withTags } from "api/components/index.js"; |
@@ -332,6 +333,7 @@ const stripeRoutes: FastifyPluginAsync = async (fastify, _options) => { |
332 | 333 | sig, |
333 | 334 | secretApiConfig.stripe_links_endpoint_secret as string, |
334 | 335 | ); |
| 336 | + // event = JSON.parse(request.rawBody.toString()); <-- this is for testing without a stripe account via Curl |
335 | 337 | } catch (err: unknown) { |
336 | 338 | if (err instanceof BaseError) { |
337 | 339 | throw err; |
@@ -715,7 +717,57 @@ Please contact Officer Board with any questions.`, |
715 | 717 | return reply |
716 | 718 | .code(200) |
717 | 719 | .send({ handled: false, requestId: request.id }); |
| 720 | + case "customer_cash_balance_transaction.created": { |
| 721 | + const txn = event.data.object as any; |
718 | 722 |
|
| 723 | + if (txn.funding_method === "bank_transfer") { |
| 724 | + const customerId = txn.customer?.toString() ?? "UNKNOWN"; |
| 725 | + const amount = txn.net_amount; |
| 726 | + const currency = txn.currency; |
| 727 | + const status = txn.status; |
| 728 | + const eventId = event.id; |
| 729 | + |
| 730 | + request.log.info( |
| 731 | + `Received ACH push ${status} txn ${txn.id} for ${customerId} (${amount} ${currency})`, |
| 732 | + ); |
| 733 | + |
| 734 | + await fastify.dynamoClient.send( |
| 735 | + new PutItemCommand({ |
| 736 | + TableName: genericConfig.StripePaymentsDynamoTableName, |
| 737 | + Item: marshall({ |
| 738 | + primaryKey: `CUSTOMER#${customerId}`, |
| 739 | + sortKey: `PAY#${txn.id}`, |
| 740 | + amount, |
| 741 | + currency, |
| 742 | + status, |
| 743 | + createdAt: Date.now(), |
| 744 | + eventId, |
| 745 | + }), |
| 746 | + }), |
| 747 | + ); |
| 748 | + |
| 749 | + // if (status === "succeeded") { |
| 750 | + // await fastify.dynamoClient.send( |
| 751 | + // new UpdateItemCommand({ |
| 752 | + // TableName: genericConfig.StripePaymentsDynamoTableName, |
| 753 | + // Key: marshall({ |
| 754 | + // primaryKey: `CUSTOMER#${customerId}`, |
| 755 | + // sortKey: "SUMMARY", |
| 756 | + // }), |
| 757 | + // UpdateExpression: "ADD totalPaid :amount SET lastUpdated = :ts", |
| 758 | + // ExpressionAttributeValues: marshall({ |
| 759 | + // ":amount": amount, |
| 760 | + // ":ts": Date.now(), |
| 761 | + // }), |
| 762 | + // }) |
| 763 | + // ); |
| 764 | + // } |
| 765 | + } |
| 766 | + |
| 767 | + return reply |
| 768 | + .status(200) |
| 769 | + .send({ handled: true, requestId: request.id }); |
| 770 | + } |
719 | 771 | default: |
720 | 772 | request.log.warn(`Unhandled event type: ${event.type}`); |
721 | 773 | } |
|
0 commit comments