Lambda functions to create an object in dynamo after invocation using react inputs

I have setup a front end using react that takes some data and will, with graphql, create objects in a aws dynamo database using amplify. I now have had to include stripe payments into the application. Once a user enters data I would like to charge them using stripe, then once a successful payment has been made I would like to use the data they provided on the react inputs to create a corresponding item in the dynamo database (only if the payment was successful).

I have setup a stripe webhook to hit a lambda function which has access to the graphql api so can create an object in the DB I just cant think how to get the object built from the react front end to be included so it can be used to build the object in the Dynamo DB?

What would be the best way to go about this? Thanks 🙂

The way I see it, you have two options depending on the type of data provided via the React inputs (I believe the second option will work better to keep you flexible):

API Metadata

Use this option if the data provided by users is not sensitive. Stripe supports appending metadata to your requests as key-value pairs. This metadata is then added to the `Charge` object created by your `PaymentIntent`, which you can retrieve in your webhook function.

From the documentation:

// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
const stripe = require('stripe')('sk_test_CGGvfNiIPwLXiDwaOfZ3oX6Y');

const intent = await stripe.paymentIntents.retrieve('{{PAYMENT_INTENT_ID}}');
const latest_charge = intent.latest_charge;

The main limitation is, per the documentation,

You can specify up to 50 keys, with key names up to 40 characters long
and values up to 500 characters long

And most importantly, do not store sensitive or PII data here.

Two-step process

Alternatively, and probably the solution which will work better for you, you can add a step to the payment process:

  1. Create the object with the React inputs in your database by adding an endpoint in your Amplify code. Add a field to this object such as fulfilled and set it to false.
  2. Your webhook has to update this item when the payment is fulfilled.

It is a simple addition to your code, you can make use of Stripe’s metadata for tracking and managing additional information about your transactions and customers.

It (metadata) is basically a key-value pair, which will perfectly suit your requirements here.

metadata sample code:

    "metadata": {
    "order_id": "6735",
    "customer_id": "CUST12345",
    "product_category": "electronics",
    "delivery_date": "2024-07-25",
    "affiliate_code": "AFF2024"
  }

You can use it with paymentintents, checkouts, subscriptions etc.

New contributor

kalyan goud is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật