← Twilio + Stripe integrations

Cancel Or Reverse a Payout with Stripe API on New Incoming SMS (Instant) from Twilio API

Pipedream makes it easy to connect APIs for Stripe, Twilio and 800+ other apps remarkably fast.

Trigger workflow on
New Incoming SMS (Instant) from the Twilio API
Next, do this
Cancel Or Reverse a Payout with the Stripe API
No credit card required
Into to Pipedream
Watch us build a workflow
Watch us build a workflow
7 min
Watch now ➜
Trusted by 250,000+ developers from startups to Fortune 500 companies:
Trusted by 250,000+ developers from startups to Fortune 500 companies

Developers Pipedream

Getting Started

This integration creates a workflow with a Twilio trigger and Stripe action. When you configure and deploy the workflow, it will run on Pipedream's servers 24x7 for free.

  1. Select this integration
  2. Configure the New Incoming SMS (Instant) trigger
    1. Connect your Twilio account
    2. Select a Incoming Phone Number
    3. Configure Twilio Auth Token
    4. Optional- Configure Response Message
  3. Configure the Cancel Or Reverse a Payout action
    1. Connect your Stripe account
    2. Select a Payout ID
  4. Deploy the workflow
  5. Send a test event to validate your setup
  6. Turn on the trigger

Details

This integration uses pre-built, open source components from Pipedream's GitHub repo. These components are developed by Pipedream and the community, and verified and maintained by Pipedream.

To contribute an update to an existing component or create a new component, create a PR on GitHub. If you're new to Pipedream component development, you can start with quickstarts for trigger span and action development, and then review the component API reference.

Trigger

Description:Configures a webhook in Twilio, tied to an incoming phone number, and emits an event each time an SMS is sent to that number
Version:0.0.7
Key:twilio-new-incoming-sms

Trigger Code

import common from "../common-webhook.mjs";
import twilio from "twilio";
const MessagingResponse = twilio.twiml.MessagingResponse;

export default {
  ...common,
  key: "twilio-new-incoming-sms",
  name: "New Incoming SMS (Instant)",
  description:
    "Configures a webhook in Twilio, tied to an incoming phone number, and emits an event each time an SMS is sent to that number",
  version: "0.0.7",
  type: "source",
  dedupe: "unique",
  props: {
    ...common.props,
    responseMessage: {
      propDefinition: [
        common.props.twilio,
        "responseMessage",
      ],
    },
  },
  methods: {
    ...common.methods,
    async setWebhook(...args) {
      return await this.twilio.setIncomingSMSWebhookURL(...args);
    },
    getResponseBody() {
      const twiml = new MessagingResponse();
      let responseBody = "<Response></Response>";
      if (this.responseMessage) {
        twiml.message(this.responseMessage);
        responseBody = twiml.toString();
      }
      return responseBody;
    },
    generateMeta(body, headers) {
      return {
        /** if Twilio retries a message, but we've already emitted, dedupe */
        id: headers["i-twilio-idempotency-token"],
        summary: body.Body,
        ts: Date.now(),
      };
    },
  },
};

Trigger Configuration

This component may be configured based on the props defined in the component code. Pipedream automatically prompts for input values in the UI and CLI.
LabelPropTypeDescription
TwiliotwilioappThis component uses the Twilio app.
Incoming Phone NumberincomingPhoneNumberstringSelect a value from the drop down menu.
Twilio Auth TokenauthTokenstring

Your Twilio auth token, found in your Twilio console. Required for validating Twilio events.

N/Ahttp$.interface.httpThis component uses $.interface.http to generate a unique URL when the component is first instantiated. Each request to the URL will trigger the run() method of the component.
Response MessageresponseMessagestring

The message you want to send in response to incoming messages. Leave this blank if you don't need to issue a response.

Trigger Authentication

Twilio uses API keys for authentication. When you connect your Twilio account, Pipedream securely stores the keys so you can easily authenticate to Twilio APIs in both code and no-code steps.

1) Create an API key in Twilio. There are two types of keys: Master and Standard. You'll need a Master key to interact with certain API endpoints, like /Accounts. If you don't need to interact with those endpoints, you can use a Standard key.

2) After creating your key, you'll see an Sid and Secret. Enter those in the fields below.

3) Visit your Twilio Dashboard. You'll see your Account SID listed near the top. Enter that in the AccountSid field below.

About Twilio

Cloud communications platform for building SMS, Voice & Messaging applications on an API built for global scale

Action

Description:Cancel or reverse a [payout](https://stripe.com/docs/payouts). A payout can be canceled only if it has not yet been paid out. A payout can be reversed only if it has already been paid out. Funds will be refunded to your available balance. [See the docs](https://stripe.com/docs/api/payouts/cancel) for more information
Version:0.0.2
Key:stripe-cancel-or-reverse-payout

Action Code

const stripe = require("../../stripe.app.js");

module.exports = {
  key: "stripe-cancel-or-reverse-payout",
  name: "Cancel Or Reverse a Payout",
  type: "action",
  version: "0.0.2",
  description: "Cancel or reverse a [payout](https://stripe.com/docs/payouts). " +
    "A payout can be canceled only if it has not yet been paid out. A payout can be reversed " +
    "only if it has already been paid out. Funds will be refunded to your available balance. [See" +
    " the docs](https://stripe.com/docs/api/payouts/cancel) for more information",
  props: {
    stripe,
    id: {
      propDefinition: [
        stripe,
        "payout",
      ],
      optional: false,
    },
  },
  async run({ $ }) {
    const payout = await this.stripe.sdk().payouts.retrieve(this.id);
    let resp;
    switch (payout.status) {
    case "paid":
      resp = await this.stripe.sdk().payouts.reverse(this.id);
      $.export("$summary", "Successfully reversed paid payout");
      return resp;
    case "pending":
      resp = await this.stripe.sdk().payouts.cancel(this.id);
      $.export("$summary", "Successfully cancelled pending payout");
      return resp;
    case "in_transit":
      throw new Error("Payment is in transit");
    case "canceled":
      throw new Error("Payment has already been canceled");
    case "failed":
      throw new Error("Payment has already failed");
    }
  },
};

Action Configuration

This component may be configured based on the props defined in the component code. Pipedream automatically prompts for input values in the UI.

LabelPropTypeDescription
StripestripeappThis component uses the Stripe app.
Payout IDidstringSelect a value from the drop down menu.

Action Authentication

Stripe uses API keys for authentication. When you connect your Stripe account, Pipedream securely stores the keys so you can easily authenticate to Stripe APIs in both code and no-code steps.

1) Create a Stripe API key. We recommend you restrict this API key to only operations you need to execute from Pipedream (e.g. a read-only key).

2) Enter the API key below

About Stripe

Payment Platform

More Ways to Connect Stripe + Twilio