Advertisement
automateallthethings

Cancel payment

Jul 8th, 2022
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.05 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. const paymentIntentId = record.getCellValueAsString("ID");
  8. await stripePost(`payment_intents/${paymentIntentId}/cancel`);
  9. await table.updateRecordAsync(record.id, {
  10. "Status": {
  11. name: "Canceled"
  12. }
  13. });
  14. output.text(`Payment ${paymentIntentId} canceled`);
  15. }
  16.  
  17.  
  18. /**
  19. * Wrapper for using fetch to interact with the Stripe API
  20. */
  21. async function stripePost(api, data) {
  22. const urlencodedData = new URLSearchParams(data);
  23. const response = await fetch(`https://api.stripe.com/v1/${api}`, {
  24. method: "POST",
  25. headers: {
  26. "Content-Type": "application/x-www-form-urlencoded",
  27. "Authorization": `Bearer ${STRIPE_SECRET_KEY}`
  28. },
  29. body: urlencodedData
  30. });
  31. const json = await response.json();
  32. return response.ok ? json : Promise.reject(json);
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement