Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Set your Stripe Secret key and Reader ID
- const STRIPE_SECRET_KEY = '';
- let table = base.getTable("Orders");
- let record = await input.recordAsync('Pick a record', table);
- if (record) {
- console.log(record);
- const paymentIntentId = record.getCellValueAsString("ID");
- await stripePost(`payment_intents/${paymentIntentId}/capture`);
- await table.updateRecordAsync(record.id, {
- "Status": {
- name: "Completed"
- }
- })
- output.text(`Payment ${paymentIntentId} captured`);
- }
- /**
- * Wrapper for using fetch to interact with the Stripe API
- */
- async function stripePost(api, data) {
- const urlencodedData = new URLSearchParams(data);
- const response = await fetch(`https://api.stripe.com/v1/${api}`, {
- method: "POST",
- headers: {
- "Content-Type": "application/x-www-form-urlencoded",
- "Authorization": `Bearer ${STRIPE_SECRET_KEY}`
- },
- body: urlencodedData
- });
- const json = await response.json();
- return response.ok ? json : Promise.reject(json);
- }
Add Comment
Please, Sign In to add comment