Sincroniza tus ventas en Stripe con Google Sheets
Los detalles
En este caso te enseñaremos a sincronizar las ventas de Stripe y las guardaremos en una hoja de Google Sheets para tener una copia de todas las ventas.
👥 Para quién es
Este ejemplo es para tí, si:
- Trabajas en Ventas o Marketing.
- Vendes productos online utilizando la pasarela Stripe.
- Quieres guardar un histórico de compras únicas en otro sitio (una hoja de Google por ejemplo).
- Quieres montar un sistema en 15 minutos, en lugar de 4 horas.
🎯 Tus objetivos
Con este ejemplo:
- Crearás una tarea para extraer las compras de Stripe con Google Sheets.
- Crearás una tarea para hacer lo mismo sin duplicados.
⚙️ Requisitos
Has de estar dado de alta en los siguientes servicios:
- Stripe, para recuperar los pagos.
- Google Sheets, para guardar el histórico de pagos.
Puedes modificar la tarea para guardar el histórico en una base de datos MySQL, Airtable o donde quieras.
Sigue el tutorial
A continuación puedes ver el video tutorial del caso concreto.
Hazlo fácil: copia y pega
Recuerda que puedes copiar los ejemplos a tu n8n clicando en “Copy” para copiar, y apretando Control + V para enganchar.
Ejemplo para extraer las ventas con duplicados
{
"meta": {
"instanceId": "14c5980141526fbb38db85208103f515afa76de9c8760a23a1771b4ed940dc7b"
},
"nodes": [
{
"parameters": {
"resource": "charge",
"operation": "getAll",
"limit": 10
},
"name": "Últimos 10 cargos",
"type": "n8n-nodes-base.stripe",
"typeVersion": 1,
"position": [
260,
300
],
"id": "bbc4d509-af3d-4fd3-97cb-7ca405351e7f",
"credentials": {
"stripeApi": {
"id": "47",
"name": "Stripe - test"
}
}
},
{
"parameters": {
"keepOnlySet": true,
"values": {
"string": [
{
"name": "id_compra",
"value": "={{$json[\"id\"]}}"
},
{
"name": "moneda",
"value": "={{$json[\"currency\"].toUpperCase()}}"
},
{
"name": "timestamp",
"value": "={{$json[\"created\"]}}"
},
{
"name": "modo_real",
"value": "={{$json[\"livemode\"]}}"
},
{
"name": "tarjeta",
"value": "={{$json[\"payment_method_details\"][\"card\"][\"network\"]}}"
},
{
"name": "nombre",
"value": "={{$json[\"billing_details\"][\"name\"]}}"
},
{
"name": "correo",
"value": "={{$json[\"billing_details\"][\"email\"]}}"
},
{
"name": "telefono",
"value": "={{$json[\"billing_details\"][\"phone\"]}}"
},
{
"name": "pais",
"value": "={{$json[\"billing_details\"][\"address\"][\"country\"]}}"
},
{
"name": "ciudad",
"value": "={{$json[\"billing_details\"][\"address\"][\"city\"]}}"
},
{
"name": "direccion",
"value": "={{$json[\"billing_details\"][\"address\"][\"line1\"]}} {{$json[\"billing_details\"][\"address\"][\"line2\"]}}"
},
{
"name": "codigo_postal",
"value": "={{$json[\"billing_details\"][\"address\"][\"postal_code\"]}}"
},
{
"name": "provincia",
"value": "={{$json[\"billing_details\"][\"address\"][\"state\"]}}"
},
{
"name": "estado",
"value": "={{$json[\"status\"]}}"
}
],
"number": [
{
"name": "cantidad",
"value": "={{parseFloat($json[\"amount\"]) / 100}}"
}
]
},
"options": {
"dotNotation": false
}
},
"name": "Definimos columnas",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
660,
300
],
"id": "3b32a4cb-5692-4294-8b02-2e7aba185efd"
},
{
"parameters": {
"value": "={{$json[\"timestamp\"]}}",
"dataPropertyName": "fecha_hora",
"custom": true,
"toFormat": "YYYY-MM-DD HH:mm:ss",
"options": {}
},
"name": "Formateamos fecha/hora",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 1,
"position": [
840,
300
],
"id": "2bea9af2-30d8-4a93-aa95-16f4dcb97e32"
},
{
"parameters": {
"authentication": "oAuth2",
"operation": "append",
"sheetId": "1wCv_wu22POmiDTGiBg6ct4m6-MYLDdP1SNvpcUubnvI",
"range": "A:Z",
"options": {
"valueInputMode": "RAW"
}
},
"name": "Guardamos pagos en Google Sheets",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 1,
"position": [
1020,
300
],
"id": "aa555e11-dab7-4945-976d-121bab9efc67",
"credentials": {
"googleSheetsOAuth2Api": {
"id": "11",
"name": "n8n-localhost"
}
}
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$json[\"status\"]}}",
"value2": "paid"
}
]
}
},
"name": "Filtramos pagos reales",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
460,
300
],
"id": "31661d9e-e9e1-4627-a660-4eb828c42520"
},
{
"parameters": {},
"name": "Inicio",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
60,
300
],
"id": "6a9a1329-44fa-489a-a099-4fe136e58d7a"
},
{
"parameters": {},
"name": "Fin",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1200,
300
],
"id": "7ce634d2-4d2c-4e79-994f-bec2fe324636"
},
{
"parameters": {
"triggerTimes": {
"item": [
{
"mode": "everyHour"
}
]
}
},
"name": "Cron",
"type": "n8n-nodes-base.cron",
"typeVersion": 1,
"position": [
60,
460
],
"id": "182a27ea-2464-45b5-bf91-3938aaefaa31"
}
],
"connections": {
"Últimos 10 cargos": {
"main": [
[
{
"node": "Filtramos pagos reales",
"type": "main",
"index": 0
}
]
]
},
"Definimos columnas": {
"main": [
[
{
"node": "Formateamos fecha/hora",
"type": "main",
"index": 0
}
]
]
},
"Formateamos fecha/hora": {
"main": [
[
{
"node": "Guardamos pagos en Google Sheets",
"type": "main",
"index": 0
}
]
]
},
"Guardamos pagos en Google Sheets": {
"main": [
[
{
"node": "Fin",
"type": "main",
"index": 0
}
]
]
},
"Filtramos pagos reales": {
"main": [
[
{
"node": "Definimos columnas",
"type": "main",
"index": 0
}
]
]
},
"Inicio": {
"main": [
[
{
"node": "Últimos 10 cargos",
"type": "main",
"index": 0
}
]
]
},
"Cron": {
"main": [
[
{
"node": "Últimos 10 cargos",
"type": "main",
"index": 0
}
]
]
}
}
}
Ejemplos para extraer las ventas sin duplicados
{
"meta": {
"instanceId": "14c5980141526fbb38db85208103f515afa76de9c8760a23a1771b4ed940dc7b"
},
"nodes": [
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$node[\"Hacemos loop por cada pago\"].context[\"noItemsLeft\"] + \"\"}}",
"value2": "false"
}
]
}
},
"name": "Quedan filas?",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1760,
80
],
"id": "182e96d0-6337-4f11-b74b-721ad88d663e"
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$json[\"id_compra\"]}}",
"operation": "isNotEmpty"
}
]
}
},
"name": "Existe?",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
1500,
300
],
"id": "a3e278dc-de99-47ce-bf70-6ab3ab7aeedc"
},
{
"parameters": {
"functionCode": "return $node['Hacemos loop por cada pago'].json;"
},
"name": "Recuperar fila actual",
"type": "n8n-nodes-base.functionItem",
"typeVersion": 1,
"position": [
1780,
320
],
"id": "ae414827-fe45-436e-80d6-05e49bedb619"
},
{
"parameters": {
"amount": 5,
"unit": "seconds"
},
"name": "Esperamos 5 segundos",
"type": "n8n-nodes-base.wait",
"typeVersion": 1,
"position": [
2180,
320
],
"webhookId": "7c8b7c92-6ec0-42b8-a8d7-0c5982ff12f6",
"id": "241566d5-2fa4-4018-b4b6-f3218fc80076"
},
{
"parameters": {
"authentication": "oAuth2",
"operation": "append",
"sheetId": "1wCv_wu22POmiDTGiBg6ct4m6-MYLDdP1SNvpcUubnvI",
"range": "Historico de compras únicas!A:Z",
"options": {
"valueInputMode": "RAW"
}
},
"name": "Agregamos pago a Sheets",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 1,
"position": [
1980,
320
],
"retryOnFail": true,
"waitBetweenTries": 5000,
"id": "78ae0808-58da-4afc-9ac2-3170e252a246",
"credentials": {
"googleSheetsOAuth2Api": {
"id": "11",
"name": "n8n-localhost"
}
}
},
{
"parameters": {
"authentication": "oAuth2",
"operation": "lookup",
"sheetId": "1wCv_wu22POmiDTGiBg6ct4m6-MYLDdP1SNvpcUubnvI",
"range": "Historico de compras únicas!A:Z",
"lookupColumn": "id_compra",
"lookupValue": "={{$json[\"id_compra\"]}}",
"options": {
"continue": false
}
},
"name": "Recuperamos pago de Sheets",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 1,
"position": [
1320,
300
],
"alwaysOutputData": true,
"retryOnFail": true,
"waitBetweenTries": 5000,
"id": "a843a1c5-713e-4a6e-9868-418a77912bf4",
"credentials": {
"googleSheetsOAuth2Api": {
"id": "11",
"name": "n8n-localhost"
}
}
},
{
"parameters": {
"batchSize": 1,
"options": {}
},
"name": "Hacemos loop por cada pago",
"type": "n8n-nodes-base.splitInBatches",
"typeVersion": 1,
"position": [
1100,
300
],
"id": "bb0d0098-ebc2-4a55-b98b-0c27e7fd0a8c"
},
{
"parameters": {
"value": "={{$json[\"timestamp\"]}}",
"dataPropertyName": "fecha_hora",
"custom": true,
"toFormat": "YYYY-MM-DD HH:mm:ss",
"options": {}
},
"name": "Formateamos fecha/hora",
"type": "n8n-nodes-base.dateTime",
"typeVersion": 1,
"position": [
900,
300
],
"id": "d2566370-0dd6-40dd-a26b-8ef2ddb72471"
},
{
"parameters": {
"keepOnlySet": true,
"values": {
"string": [
{
"name": "id_compra",
"value": "={{$json[\"id\"]}}"
},
{
"name": "moneda",
"value": "={{$json[\"currency\"].toUpperCase()}}"
},
{
"name": "timestamp",
"value": "={{$json[\"created\"]}}"
},
{
"name": "modo_real",
"value": "={{$json[\"livemode\"]}}"
},
{
"name": "tarjeta",
"value": "={{$json[\"payment_method_details\"][\"card\"][\"network\"]}}"
},
{
"name": "nombre",
"value": "={{$json[\"billing_details\"][\"name\"]}}"
},
{
"name": "correo",
"value": "={{$json[\"billing_details\"][\"email\"]}}"
},
{
"name": "telefono",
"value": "={{$json[\"billing_details\"][\"phone\"]}}"
},
{
"name": "pais",
"value": "={{$json[\"billing_details\"][\"address\"][\"country\"]}}"
},
{
"name": "ciudad",
"value": "={{$json[\"billing_details\"][\"address\"][\"city\"]}}"
},
{
"name": "direccion",
"value": "={{$json[\"billing_details\"][\"address\"][\"line1\"]}} {{$json[\"billing_details\"][\"address\"][\"line2\"]}}"
},
{
"name": "codigo_postal",
"value": "={{$json[\"billing_details\"][\"address\"][\"postal_code\"]}}"
},
{
"name": "provincia",
"value": "={{$json[\"billing_details\"][\"address\"][\"state\"]}}"
},
{
"name": "estado",
"value": "={{$json[\"status\"]}}"
}
],
"number": [
{
"name": "cantidad",
"value": "={{parseFloat($json[\"amount\"]) / 100}}"
}
]
},
"options": {
"dotNotation": false
}
},
"name": "Definimos columnas",
"type": "n8n-nodes-base.set",
"typeVersion": 1,
"position": [
700,
300
],
"id": "3dbea0fb-32ef-4156-bcf2-bac03c1a0e45"
},
{
"parameters": {
"conditions": {
"string": [
{
"value1": "={{$json[\"status\"]}}",
"value2": "paid"
}
]
}
},
"name": "Filtramos pagos reales",
"type": "n8n-nodes-base.if",
"typeVersion": 1,
"position": [
500,
300
],
"id": "9c748159-d765-4547-8875-277ad04c9edc"
},
{
"parameters": {
"resource": "charge",
"operation": "getAll",
"limit": 10
},
"name": "Últimos 10 cargos",
"type": "n8n-nodes-base.stripe",
"typeVersion": 1,
"position": [
320,
300
],
"id": "ed420a10-8615-499f-8195-327862810fd1",
"credentials": {
"stripeApi": {
"id": "47",
"name": "Stripe - test"
}
}
},
{
"parameters": {},
"name": "Fin",
"type": "n8n-nodes-base.noOp",
"typeVersion": 1,
"position": [
1980,
100
],
"id": "5a0a6058-cbc2-4cd9-93c1-0592093534ee"
},
{
"parameters": {},
"name": "Inicio",
"type": "n8n-nodes-base.start",
"typeVersion": 1,
"position": [
160,
300
],
"id": "34492980-6f8a-4491-ba38-92e939ab715c"
},
{
"parameters": {
"triggerTimes": {
"item": [
{
"mode": "everyX",
"value": 5,
"unit": "minutes"
}
]
}
},
"name": "Cron",
"type": "n8n-nodes-base.cron",
"typeVersion": 1,
"position": [
160,
460
],
"id": "852f82a3-a87f-4c1a-b6f4-b2c633a40c54"
}
],
"connections": {
"Quedan filas?": {
"main": [
[
{
"node": "Hacemos loop por cada pago",
"type": "main",
"index": 0
}
],
[
{
"node": "Fin",
"type": "main",
"index": 0
}
]
]
},
"Existe?": {
"main": [
[
{
"node": "Quedan filas?",
"type": "main",
"index": 0
}
],
[
{
"node": "Recuperar fila actual",
"type": "main",
"index": 0
}
]
]
},
"Recuperar fila actual": {
"main": [
[
{
"node": "Agregamos pago a Sheets",
"type": "main",
"index": 0
}
]
]
},
"Esperamos 5 segundos": {
"main": [
[
{
"node": "Quedan filas?",
"type": "main",
"index": 0
}
]
]
},
"Agregamos pago a Sheets": {
"main": [
[
{
"node": "Esperamos 5 segundos",
"type": "main",
"index": 0
}
]
]
},
"Recuperamos pago de Sheets": {
"main": [
[
{
"node": "Existe?",
"type": "main",
"index": 0
}
]
]
},
"Hacemos loop por cada pago": {
"main": [
[
{
"node": "Recuperamos pago de Sheets",
"type": "main",
"index": 0
}
]
]
},
"Formateamos fecha/hora": {
"main": [
[
{
"node": "Hacemos loop por cada pago",
"type": "main",
"index": 0
}
]
]
},
"Definimos columnas": {
"main": [
[
{
"node": "Formateamos fecha/hora",
"type": "main",
"index": 0
}
]
]
},
"Filtramos pagos reales": {
"main": [
[
{
"node": "Definimos columnas",
"type": "main",
"index": 0
}
]
]
},
"Últimos 10 cargos": {
"main": [
[
{
"node": "Filtramos pagos reales",
"type": "main",
"index": 0
}
]
]
},
"Inicio": {
"main": [
[
{
"node": "Últimos 10 cargos",
"type": "main",
"index": 0
}
]
]
},
"Cron": {
"main": [
[
{
"node": "Últimos 10 cargos",
"type": "main",
"index": 0
}
]
]
}
}
}
Si no quieres más popups, apúntate a la membresía!