Merge pull request #749 from PierreSchwang/feat/stripe
Feature: Stripe integration (triggers)
This commit is contained in:
10
packages/backend/src/apps/stripe/assets/favicon.svg
Normal file
10
packages/backend/src/apps/stripe/assets/favicon.svg
Normal file
@@ -0,0 +1,10 @@
|
||||
<svg id="svg" version="1.1" xmlns="http://www.w3.org/2000/svg" width="400" height="400" viewBox="0, 0, 400,400">
|
||||
<g id="svgg">
|
||||
<path id="path0"
|
||||
d="M198.800 76.002 C 192.960 76.301,187.099 76.918,183.400 77.623 C 177.677 78.714,175.057 79.288,171.600 80.207 C 169.510 80.763,167.440 81.382,167.000 81.583 C 166.560 81.783,165.030 82.342,163.600 82.824 C 142.177 90.045,124.260 107.805,117.820 128.200 C 113.910 140.585,112.933 156.448,115.418 167.200 C 116.306 171.043,116.577 172.064,117.276 174.200 C 117.708 175.520,118.588 177.733,119.231 179.118 C 119.874 180.503,120.400 181.708,120.400 181.797 C 120.400 181.885,121.061 183.092,121.869 184.479 C 127.040 193.356,135.581 201.605,146.011 207.795 C 149.302 209.748,159.236 214.800,159.785 214.800 C 159.892 214.800,161.109 215.310,162.490 215.933 C 165.453 217.270,173.763 220.551,179.400 222.609 C 195.215 228.384,198.386 229.722,205.534 233.636 C 220.392 241.770,219.950 260.095,204.800 264.076 C 199.139 265.564,187.804 266.135,181.833 265.232 C 180.495 265.030,177.870 264.655,176.000 264.398 C 174.130 264.142,172.060 263.788,171.400 263.612 C 170.740 263.436,169.120 263.065,167.800 262.789 C 154.801 260.064,141.875 255.414,126.486 247.928 C 122.463 245.972,118.998 244.478,118.786 244.609 C 118.159 244.996,118.271 308.079,118.900 308.899 C 119.725 309.975,133.794 315.264,142.000 317.584 C 142.990 317.864,144.250 318.235,144.800 318.408 C 145.350 318.582,146.610 318.911,147.600 319.140 C 148.590 319.369,150.930 319.912,152.800 320.347 C 154.670 320.782,157.370 321.348,158.800 321.604 C 160.230 321.860,162.300 322.234,163.400 322.435 C 177.558 325.023,201.685 325.201,214.900 322.815 C 216.165 322.587,218.145 322.227,219.300 322.016 C 225.011 320.971,235.080 317.946,239.600 315.918 C 240.590 315.474,242.390 314.665,243.600 314.121 C 250.325 311.097,259.619 304.705,265.005 299.400 C 285.928 278.789,291.480 241.782,277.725 214.602 C 271.038 201.387,255.237 188.197,238.000 181.440 C 237.010 181.052,235.660 180.488,235.000 180.187 C 232.351 178.979,213.304 172.081,208.000 170.409 C 187.266 163.873,178.497 154.218,183.708 143.661 C 190.425 130.050,233.857 133.347,267.600 150.029 C 270.130 151.280,272.335 152.225,272.500 152.128 C 272.665 152.032,272.800 137.647,272.800 120.162 L 272.800 88.372 270.900 87.554 C 268.928 86.705,259.102 83.332,257.000 82.781 C 256.340 82.609,254.075 82.016,251.967 81.464 C 240.954 78.580,228.764 76.709,217.800 76.220 C 207.102 75.743,204.456 75.712,198.800 76.002 "
|
||||
stroke="none" fill="#ffffff" fill-rule="evenodd"/>
|
||||
<path id="path1"
|
||||
d="M0.000 200.000 L 0.000 400.000 200.000 400.000 L 400.000 400.000 400.000 200.000 L 400.000 0.000 200.000 0.000 L 0.000 0.000 0.000 200.000 M217.800 76.220 C 228.764 76.709,240.954 78.580,251.967 81.464 C 254.075 82.016,256.340 82.609,257.000 82.781 C 259.102 83.332,268.928 86.705,270.900 87.554 L 272.800 88.372 272.800 120.162 C 272.800 137.647,272.665 152.032,272.500 152.128 C 272.335 152.225,270.130 151.280,267.600 150.029 C 233.857 133.347,190.425 130.050,183.708 143.661 C 178.497 154.218,187.266 163.873,208.000 170.409 C 213.304 172.081,232.351 178.979,235.000 180.187 C 235.660 180.488,237.010 181.052,238.000 181.440 C 255.237 188.197,271.038 201.387,277.725 214.602 C 291.480 241.782,285.928 278.789,265.005 299.400 C 259.619 304.705,250.325 311.097,243.600 314.121 C 242.390 314.665,240.590 315.474,239.600 315.918 C 235.080 317.946,225.011 320.971,219.300 322.016 C 218.145 322.227,216.165 322.587,214.900 322.815 C 201.685 325.201,177.558 325.023,163.400 322.435 C 162.300 322.234,160.230 321.860,158.800 321.604 C 157.370 321.348,154.670 320.782,152.800 320.347 C 150.930 319.912,148.590 319.369,147.600 319.140 C 146.610 318.911,145.350 318.582,144.800 318.408 C 144.250 318.235,142.990 317.864,142.000 317.584 C 133.794 315.264,119.725 309.975,118.900 308.899 C 118.271 308.079,118.159 244.996,118.786 244.609 C 118.998 244.478,122.463 245.972,126.486 247.928 C 141.875 255.414,154.801 260.064,167.800 262.789 C 169.120 263.065,170.740 263.436,171.400 263.612 C 172.060 263.788,174.130 264.142,176.000 264.398 C 177.870 264.655,180.495 265.030,181.833 265.232 C 187.804 266.135,199.139 265.564,204.800 264.076 C 219.950 260.095,220.392 241.770,205.534 233.636 C 198.386 229.722,195.215 228.384,179.400 222.609 C 173.763 220.551,165.453 217.270,162.490 215.933 C 161.109 215.310,159.892 214.800,159.785 214.800 C 159.236 214.800,149.302 209.748,146.011 207.795 C 135.581 201.605,127.040 193.356,121.869 184.479 C 121.061 183.092,120.400 181.885,120.400 181.797 C 120.400 181.708,119.874 180.503,119.231 179.118 C 118.588 177.733,117.708 175.520,117.276 174.200 C 116.577 172.064,116.306 171.043,115.418 167.200 C 112.933 156.448,113.910 140.585,117.820 128.200 C 124.260 107.805,142.177 90.045,163.600 82.824 C 165.030 82.342,166.560 81.783,167.000 81.583 C 167.440 81.382,169.510 80.763,171.600 80.207 C 175.057 79.288,177.677 78.714,183.400 77.623 C 187.099 76.918,192.960 76.301,198.800 76.002 C 204.456 75.712,207.102 75.743,217.800 76.220 "
|
||||
stroke="none" fill="#635bff" fill-rule="evenodd"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 5.0 KiB |
31
packages/backend/src/apps/stripe/auth/index.ts
Normal file
31
packages/backend/src/apps/stripe/auth/index.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import verifyCredentials from "./verify-credentials";
|
||||
import isStillVerified from "./is-still-verified";
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'secretKey',
|
||||
label: 'Secret Key',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description: null,
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'displayName',
|
||||
label: 'Account Name',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description: 'The display name that identifies this stripe connection - most likely the associated account name',
|
||||
clickToCopy: false,
|
||||
},
|
||||
],
|
||||
verifyCredentials,
|
||||
isStillVerified
|
||||
};
|
@@ -0,0 +1,9 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import verifyCredentials from "./verify-credentials";
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
await verifyCredentials($);
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
12
packages/backend/src/apps/stripe/auth/verify-credentials.ts
Normal file
12
packages/backend/src/apps/stripe/auth/verify-credentials.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
await $.http.get(
|
||||
`/v1/events`,
|
||||
);
|
||||
await $.auth.set({
|
||||
screenName: $.auth.data?.displayName,
|
||||
});
|
||||
};
|
||||
|
||||
export default verifyCredentials;
|
@@ -0,0 +1,8 @@
|
||||
import {TBeforeRequest} from "@automatisch/types";
|
||||
|
||||
const addAuthHeader: TBeforeRequest = ($, requestConfig) => {
|
||||
requestConfig.headers['Authorization'] = `Bearer ${$.auth.data?.secretKey}`
|
||||
return requestConfig
|
||||
}
|
||||
|
||||
export default addAuthHeader;
|
19
packages/backend/src/apps/stripe/index.ts
Normal file
19
packages/backend/src/apps/stripe/index.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
import defineApp from "../../helpers/define-app";
|
||||
import addAuthHeader from "./common/add-auth-header";
|
||||
import auth from "./auth"
|
||||
import triggers from "./triggers"
|
||||
|
||||
export default defineApp({
|
||||
name: 'Stripe',
|
||||
key: 'stripe',
|
||||
iconUrl: '{BASE_URL}/apps/stripe/assets/favicon.svg',
|
||||
authDocUrl: 'https://automatisch.io/docs/apps/stripe/connection',
|
||||
supportsConnections: true,
|
||||
baseUrl: 'https://stripe.com',
|
||||
apiBaseUrl: 'https://api.stripe.com',
|
||||
primaryColor: '635bff',
|
||||
beforeRequest: [addAuthHeader],
|
||||
auth,
|
||||
triggers,
|
||||
actions: [],
|
||||
})
|
@@ -0,0 +1,32 @@
|
||||
import {IGlobalVariable, IJSONObject} from "@automatisch/types";
|
||||
import {URLSearchParams} from "url";
|
||||
import {isEmpty, omitBy} from "lodash";
|
||||
|
||||
const getBalanceTransactions = async ($: IGlobalVariable) => {
|
||||
let response;
|
||||
let lastId = undefined;
|
||||
|
||||
do {
|
||||
const params: IJSONObject = {
|
||||
starting_after: lastId,
|
||||
ending_before: $.flow.lastInternalId
|
||||
}
|
||||
const queryParams = new URLSearchParams(omitBy(params, isEmpty))
|
||||
const requestPath = `/v1/balance_transactions${
|
||||
queryParams.toString() ? `?${queryParams.toString()}` : ''
|
||||
}`;
|
||||
|
||||
response = (await $.http.get(requestPath)).data
|
||||
for (const entry of response.data) {
|
||||
$.pushTriggerItem({
|
||||
raw: entry,
|
||||
meta: {
|
||||
internalId: entry.id as string
|
||||
}
|
||||
})
|
||||
lastId = entry.id
|
||||
}
|
||||
} while (response.has_more)
|
||||
};
|
||||
|
||||
export default getBalanceTransactions;
|
@@ -0,0 +1,12 @@
|
||||
import defineTrigger from "../../../../helpers/define-trigger";
|
||||
import getBalanceTransactions from "./get-balance-transactions";
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New Balance Transactions',
|
||||
key: 'newBalanceTransactions',
|
||||
description: 'Triggers when a new transaction is processed (refund, payout, adjustment, ...)',
|
||||
pollInterval: 15,
|
||||
async run($) {
|
||||
await getBalanceTransactions($)
|
||||
}
|
||||
})
|
4
packages/backend/src/apps/stripe/triggers/index.ts
Normal file
4
packages/backend/src/apps/stripe/triggers/index.ts
Normal file
@@ -0,0 +1,4 @@
|
||||
import balanceTransaction from "./balance-transaction";
|
||||
import payouts from "./payouts";
|
||||
|
||||
export default [balanceTransaction, payouts];
|
@@ -0,0 +1,32 @@
|
||||
import {IGlobalVariable, IJSONObject} from "@automatisch/types";
|
||||
import {URLSearchParams} from "url";
|
||||
import {isEmpty, omitBy} from "lodash";
|
||||
|
||||
const getPayouts = async ($: IGlobalVariable) => {
|
||||
let response;
|
||||
let lastId = undefined;
|
||||
|
||||
do {
|
||||
const params: IJSONObject = {
|
||||
starting_after: lastId,
|
||||
ending_before: $.flow.lastInternalId
|
||||
}
|
||||
const queryParams = new URLSearchParams(omitBy(params, isEmpty))
|
||||
const requestPath = `/v1/payouts${
|
||||
queryParams.toString() ? `?${queryParams.toString()}` : ''
|
||||
}`;
|
||||
|
||||
response = (await $.http.get(requestPath)).data
|
||||
for (const entry of response.data) {
|
||||
$.pushTriggerItem({
|
||||
raw: entry,
|
||||
meta: {
|
||||
internalId: entry.id as string
|
||||
}
|
||||
})
|
||||
lastId = entry.id
|
||||
}
|
||||
} while (response.has_more)
|
||||
};
|
||||
|
||||
export default getPayouts;
|
12
packages/backend/src/apps/stripe/triggers/payouts/index.ts
Normal file
12
packages/backend/src/apps/stripe/triggers/payouts/index.ts
Normal file
@@ -0,0 +1,12 @@
|
||||
import defineTrigger from "../../../../helpers/define-trigger";
|
||||
import getPayouts from "./get-payouts";
|
||||
|
||||
export default defineTrigger({
|
||||
name: 'New Payouts',
|
||||
key: 'newPayouts',
|
||||
description: 'Triggers when a payout (Stripe <-> Bank account) has been updated',
|
||||
pollInterval: 15,
|
||||
async run($) {
|
||||
await getPayouts($)
|
||||
}
|
||||
})
|
@@ -105,6 +105,14 @@ export default defineConfig({
|
||||
{ text: 'Connection', link: '/apps/smtp/connection' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: 'Stripe',
|
||||
collapsible: true,
|
||||
items: [
|
||||
{ text: 'Triggers', link: '/apps/stripe/triggers' },
|
||||
{ text: 'Connection', link: '/apps/stripe/connection' },
|
||||
],
|
||||
},
|
||||
{
|
||||
text: 'Twilio',
|
||||
collapsible: true,
|
||||
|
14
packages/docs/pages/apps/stripe/connection.md
Normal file
14
packages/docs/pages/apps/stripe/connection.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# Stripe
|
||||
|
||||
:::info
|
||||
This page explains the steps you need to follow to set up the Stripe connection in Automatisch. If any of the steps are outdated, please let us know!
|
||||
:::
|
||||
|
||||
:::info
|
||||
You are free to use the **Testing secret key** instead of the productive secret key as well.
|
||||
:::
|
||||
|
||||
1. Go to the [Stripe Dashboard > Developer > API keys](https://dashboard.stripe.com/apikeys)
|
||||
2. Click on **Reveal live key** in the table row **Secret key** and copy the now shown secret key
|
||||
3. Paste the **Secret key** in the named field in Automatisch and assign a display name for the connection.
|
||||
4. Congrats! You can start using the new Stripe connection!
|
18
packages/docs/pages/apps/stripe/triggers.md
Normal file
18
packages/docs/pages/apps/stripe/triggers.md
Normal file
@@ -0,0 +1,18 @@
|
||||
---
|
||||
favicon: /favicons/stripe.svg
|
||||
items:
|
||||
- name: New Payouts
|
||||
desc: Triggers when stripe sent a payout to a third-party bank account or vice versa.
|
||||
org: Stripe Documentation
|
||||
orgLink: https://stripe.com/docs/api/payouts/object
|
||||
- name: New Balance Transactions
|
||||
desc: Triggers when a fund has been moved through your stripe account.
|
||||
org: Stripe Documentation
|
||||
orgLink: https://stripe.com/docs/api/balance_transactions/object
|
||||
---
|
||||
|
||||
<script setup>
|
||||
import CustomListing from '../../components/CustomListing.vue'
|
||||
</script>
|
||||
|
||||
<CustomListing />
|
@@ -15,5 +15,6 @@ Following integrations are currently supported by Automatisch.
|
||||
- [Scheduler](/apps/scheduler/triggers)
|
||||
- [Slack](/apps/slack/actions)
|
||||
- [SMTP](/apps/smtp/actions)
|
||||
- [Stripe](/apps/stripe/triggers)
|
||||
- [Twilio](/apps/twilio/triggers)
|
||||
- [Twitter](/apps/twitter/triggers)
|
||||
|
10
packages/docs/pages/public/favicons/stripe.svg
Normal file
10
packages/docs/pages/public/favicons/stripe.svg
Normal file
@@ -0,0 +1,10 @@
|
||||
<svg id="svg" version="1.1" xmlns="http://www.w3.org/2000/svg" width="400" height="400" viewBox="0, 0, 400,400">
|
||||
<g id="svgg">
|
||||
<path id="path0"
|
||||
d="M198.800 76.002 C 192.960 76.301,187.099 76.918,183.400 77.623 C 177.677 78.714,175.057 79.288,171.600 80.207 C 169.510 80.763,167.440 81.382,167.000 81.583 C 166.560 81.783,165.030 82.342,163.600 82.824 C 142.177 90.045,124.260 107.805,117.820 128.200 C 113.910 140.585,112.933 156.448,115.418 167.200 C 116.306 171.043,116.577 172.064,117.276 174.200 C 117.708 175.520,118.588 177.733,119.231 179.118 C 119.874 180.503,120.400 181.708,120.400 181.797 C 120.400 181.885,121.061 183.092,121.869 184.479 C 127.040 193.356,135.581 201.605,146.011 207.795 C 149.302 209.748,159.236 214.800,159.785 214.800 C 159.892 214.800,161.109 215.310,162.490 215.933 C 165.453 217.270,173.763 220.551,179.400 222.609 C 195.215 228.384,198.386 229.722,205.534 233.636 C 220.392 241.770,219.950 260.095,204.800 264.076 C 199.139 265.564,187.804 266.135,181.833 265.232 C 180.495 265.030,177.870 264.655,176.000 264.398 C 174.130 264.142,172.060 263.788,171.400 263.612 C 170.740 263.436,169.120 263.065,167.800 262.789 C 154.801 260.064,141.875 255.414,126.486 247.928 C 122.463 245.972,118.998 244.478,118.786 244.609 C 118.159 244.996,118.271 308.079,118.900 308.899 C 119.725 309.975,133.794 315.264,142.000 317.584 C 142.990 317.864,144.250 318.235,144.800 318.408 C 145.350 318.582,146.610 318.911,147.600 319.140 C 148.590 319.369,150.930 319.912,152.800 320.347 C 154.670 320.782,157.370 321.348,158.800 321.604 C 160.230 321.860,162.300 322.234,163.400 322.435 C 177.558 325.023,201.685 325.201,214.900 322.815 C 216.165 322.587,218.145 322.227,219.300 322.016 C 225.011 320.971,235.080 317.946,239.600 315.918 C 240.590 315.474,242.390 314.665,243.600 314.121 C 250.325 311.097,259.619 304.705,265.005 299.400 C 285.928 278.789,291.480 241.782,277.725 214.602 C 271.038 201.387,255.237 188.197,238.000 181.440 C 237.010 181.052,235.660 180.488,235.000 180.187 C 232.351 178.979,213.304 172.081,208.000 170.409 C 187.266 163.873,178.497 154.218,183.708 143.661 C 190.425 130.050,233.857 133.347,267.600 150.029 C 270.130 151.280,272.335 152.225,272.500 152.128 C 272.665 152.032,272.800 137.647,272.800 120.162 L 272.800 88.372 270.900 87.554 C 268.928 86.705,259.102 83.332,257.000 82.781 C 256.340 82.609,254.075 82.016,251.967 81.464 C 240.954 78.580,228.764 76.709,217.800 76.220 C 207.102 75.743,204.456 75.712,198.800 76.002 "
|
||||
stroke="none" fill="#ffffff" fill-rule="evenodd"/>
|
||||
<path id="path1"
|
||||
d="M0.000 200.000 L 0.000 400.000 200.000 400.000 L 400.000 400.000 400.000 200.000 L 400.000 0.000 200.000 0.000 L 0.000 0.000 0.000 200.000 M217.800 76.220 C 228.764 76.709,240.954 78.580,251.967 81.464 C 254.075 82.016,256.340 82.609,257.000 82.781 C 259.102 83.332,268.928 86.705,270.900 87.554 L 272.800 88.372 272.800 120.162 C 272.800 137.647,272.665 152.032,272.500 152.128 C 272.335 152.225,270.130 151.280,267.600 150.029 C 233.857 133.347,190.425 130.050,183.708 143.661 C 178.497 154.218,187.266 163.873,208.000 170.409 C 213.304 172.081,232.351 178.979,235.000 180.187 C 235.660 180.488,237.010 181.052,238.000 181.440 C 255.237 188.197,271.038 201.387,277.725 214.602 C 291.480 241.782,285.928 278.789,265.005 299.400 C 259.619 304.705,250.325 311.097,243.600 314.121 C 242.390 314.665,240.590 315.474,239.600 315.918 C 235.080 317.946,225.011 320.971,219.300 322.016 C 218.145 322.227,216.165 322.587,214.900 322.815 C 201.685 325.201,177.558 325.023,163.400 322.435 C 162.300 322.234,160.230 321.860,158.800 321.604 C 157.370 321.348,154.670 320.782,152.800 320.347 C 150.930 319.912,148.590 319.369,147.600 319.140 C 146.610 318.911,145.350 318.582,144.800 318.408 C 144.250 318.235,142.990 317.864,142.000 317.584 C 133.794 315.264,119.725 309.975,118.900 308.899 C 118.271 308.079,118.159 244.996,118.786 244.609 C 118.998 244.478,122.463 245.972,126.486 247.928 C 141.875 255.414,154.801 260.064,167.800 262.789 C 169.120 263.065,170.740 263.436,171.400 263.612 C 172.060 263.788,174.130 264.142,176.000 264.398 C 177.870 264.655,180.495 265.030,181.833 265.232 C 187.804 266.135,199.139 265.564,204.800 264.076 C 219.950 260.095,220.392 241.770,205.534 233.636 C 198.386 229.722,195.215 228.384,179.400 222.609 C 173.763 220.551,165.453 217.270,162.490 215.933 C 161.109 215.310,159.892 214.800,159.785 214.800 C 159.236 214.800,149.302 209.748,146.011 207.795 C 135.581 201.605,127.040 193.356,121.869 184.479 C 121.061 183.092,120.400 181.885,120.400 181.797 C 120.400 181.708,119.874 180.503,119.231 179.118 C 118.588 177.733,117.708 175.520,117.276 174.200 C 116.577 172.064,116.306 171.043,115.418 167.200 C 112.933 156.448,113.910 140.585,117.820 128.200 C 124.260 107.805,142.177 90.045,163.600 82.824 C 165.030 82.342,166.560 81.783,167.000 81.583 C 167.440 81.382,169.510 80.763,171.600 80.207 C 175.057 79.288,177.677 78.714,183.400 77.623 C 187.099 76.918,192.960 76.301,198.800 76.002 C 204.456 75.712,207.102 75.743,217.800 76.220 "
|
||||
stroke="none" fill="#635bff" fill-rule="evenodd"/>
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 5.0 KiB |
Reference in New Issue
Block a user