automateallthethings

capture payment

Jul 8th, 2022 (edited)
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. // Set your Stripe Secret key and Reader ID
  2. const STRIPE_SECRET_KEY = '';
  3.  
  4. let table = base.getTable("Orders");
  5. let record = await input.recordAsync('Pick a record', table);
  6. if (record) {
  7. console.log(record);
  8. const paymentIntentId = record.getCellValueAsString("ID");
  9. await stripePost(`payment_intents/${paymentIntentId}/capture`);
  10. await table.updateRecordAsync(record.id, {
  11. "Status": {
  12. name: "Completed"
  13. }
  14. })
  15. output.text(`Payment ${paymentIntentId} captured`);
  16. }
  17.  
  18.  
  19. /**
  20. * Wrapper for using fetch to interact with the Stripe API
  21. */
  22. async function stripePost(api, data) {
  23. const urlencodedData = new URLSearchParams(data);
  24. const response = await fetch(`https://api.stripe.com/v1/${api}`, {
  25. method: "POST",
  26. headers: {
  27. "Content-Type": "application/x-www-form-urlencoded",
  28. "Authorization": `Bearer ${STRIPE_SECRET_KEY}`
  29. },
  30. body: urlencodedData
  31. });
  32. const json = await response.json();
  33. return response.ok ? json : Promise.reject(json);
  34. }
Add Comment
Please, Sign In to add comment