How to Create a Line Item in an Invoice for a Workflow Using Google Form and Stripe?

This topic was automatically generated from Slack. You can find the original thread here.

I am creating a workflow where a person fills out a GOOGLE FORM to place an order.

I want to use STRIPE to process the order.

My next step is to CREATE CUSTOMER.

Then I need to CREATE INVOICE. However, I don’t see how to make a LINE ITEM to invoice.

To create a customer and an invoice with line items in Stripe, you can use the pre-built Stripe actions in Pipedream. Here’s how to do it: 1. Search for the Stripe app from the step menu and select the “Create Customer” action. Connect your Stripe account and configure the required fields. 2. To create an invoice line item, search for the Stripe app from the step menu again and select the “Create Invoice Line Item” action. Connect your Stripe account and configure the required fields, including the Customer ID from the previous step. 3. Finally, to create the invoice, search for the Stripe app from the step menu once more and select the “Create Invoice” action. Connect your Stripe account and configure the required fields, including the Customer ID from the first step. Remember to visit https://pipedream.com/pricing for the latest pricing information.

I need an action to total up the amount of items found in the spreadsheet.

The items are in COLUMNS H-AC.

I need the total returned.

Then I need another action to multiply the total return * the price that I give it. So ITEMS and PRICE should be the fields.

To achieve this, you can use the Google Sheets app in Pipedream and create a custom code step to perform the calculations. Here’s a step-by-step guide: 1. Search for the Google Sheets app from the step menu and select the “Get Sheet Values” action. Connect your Google Sheets account and configure the required fields, such as the Spreadsheet ID and the Range (e.g., “Sheet1!H1:AC100” for columns H-AC and rows 1-100). 2. Add a custom code step to calculate the total items and multiply it by the price. Here’s an example code snippet: export default defineComponent({ props: { items: { type: "string[]", label: "Items", }, price: { type: "integer", label: "Price", }, }, async run({ steps }) { const itemsArray = steps.get_sheet_values.values; let totalItems = 0; for (const row of itemsArray) { for (const item of row) { totalItems += parseInt(item, 10); } } const totalPrice = totalItems * this.price; return { totalItems, totalPrice }; }, }); In this code snippet, replace steps.get_sheet_values.values with the actual step reference from the “Get Sheet Values” action. Make sure to configure the items and price props as needed. This custom code step will return the total items and the total price based on the provided price.

So I used the GOOGLE SHEET Get Sheet Values and I pulled it using:

H{{steps.trigger.event.rowNumber}}:AC{{steps.trigger.event.rowNumber}}

The problem is that it returns and ARRAY. I need it as a whole number.

I understand that you want to sum the values in the array and get a whole number. You can achieve this by adding a custom code step after the “Get Sheet Values” step. Here’s an example code snippet: export default defineComponent({ async run({ steps }) { const rowValues = steps.get_sheet_values.values[0]; let total = 0; for (const value of rowValues) { total += parseInt(value, 10); } return { total }; }, }); Replace steps.get_sheet_values.values with the actual step reference from the “Get Sheet Values” action. This custom code step will sum the values in the array and return the total as a whole number.

The code:

export default defineComponent({
  async run({ steps }) {
    const rowValues = steps.get_sheet_values.values[0];
    let total = 0;

    for (const value of rowValues) {
      total += parseInt(value, 10);
    }

    return { total };
  },
});
  1. I would like a FIELD where I can put the VALUE.
  2. This code does not add up the ARRAY.
    Let’s say this is the ARRAY:
0[3]
0: 1
1: 1
2: 1

The code returned:

1

It should have returned 3.

I apologize for the confusion. I’ve made adjustments to the code to include a field for the value and to correctly sum the array values. export default defineComponent({ props: { value: { type: "integer", label: "Value", }, }, async run({ steps }) { const rowValues = steps.get_sheet_values.values[0]; let total = 0; for (const value of rowValues) { total += Number(value); } return { total }; }, }); In this updated code, I’ve added a value prop to allow you to input a value. Additionally, I’ve changed parseInt(value, 10) to Number(value) to correctly sum the array values.

I must be doing something wrong.

Here is the array:

get_values_in_range{1}
    $return_value[1]
    0[3]
        0:1
        1:1
        2:1

Here is what is being returned.

[ [ "1", "1", "1" ] ]

In the field, I am putting: {{steps.get_values_in_range.$return_value}}

I apologize for the confusion earlier. Based on the array you provided, let’s modify the custom code step to correctly sum the values: export default defineComponent({ async run({ steps }) { const rowValues = steps.get_values_in_range.$return_value[0]; let total = 0; for (const value of rowValues) { total += Number(value); } return { total }; }, }); In this updated code, I’ve changed the reference to steps.get_values_in_range.$return_value[0] to correctly access the array. This should now sum the values in the array and return the correct total.

Please add the INPUT FIELD for the VALUE.

export default defineComponent({
  async run({ steps }) {
    const rowValues = steps.get_values_in_range.$return_value[0];
    let total = 0;

    for (const value of rowValues) {
      total += Number(value);
    }

    return { total };
  },
});

I apologize for the oversight. Here’s the updated code with the input field for the value: export default defineComponent({ props: { values: { type: "string[]", label: "Values", }, }, async run({ steps }) { const rowValues = this.values || steps.get_values_in_range.$return_value[0]; let total = 0; for (const value of rowValues) { total += Number(value); } return { total }; }, }); In this updated code, I’ve added a values prop that accepts an array of strings. You can input the values in the Pipedream UI by using this field. If the values prop is not provided, it will fall back to using the steps.get_values_in_range.$return_value[0].