Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions components/braintree/actions/create-customer/create-customer.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import braintree from "../../braintree.app.mjs";
import mutations from "../../common/mutations.mjs";

export default {
key: "braintree-create-customer",
name: "Create Customer",
description: "Create a new customer in Braintree. [See the documentation](https://developer.paypal.com/braintree/graphql/guides/customers/#create)",
version: "0.0.1",
annotations: {
destructiveHint: false,
openWorldHint: true,
readOnlyHint: false,
},
type: "action",
props: {
braintree,
firstName: {
type: "string",
label: "First Name",
description: "First name of the customer",
optional: true,
},
lastName: {
type: "string",
label: "Last Name",
description: "Last name of the customer",
optional: true,
},
company: {
type: "string",
label: "Company",
description: "Company name of the customer",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "Email of the customer",
optional: true,
},
phoneNumber: {
type: "string",
label: "Phone Number",
description: "Phone number of the customer",
optional: true,
},
fax: {
type: "string",
label: "Fax",
description: "Fax number of the customer",
optional: true,
},
website: {
type: "string",
label: "Website",
description: "Website of the customer",
optional: true,
},
},
async run({ $ }) {
const response = await this.braintree.makeGraphQLRequest({
$,
data: {
query: mutations.createCustomer,
variables: {
input: {
customer: {
firstName: this.firstName,
lastName: this.lastName,
company: this.company,
email: this.email,
phoneNumber: this.phoneNumber,
fax: this.fax,
website: this.website,
},
},
},
},
});
$.export("$summary", `Customer successfully created with ID ${response.data.createCustomer.customer.id}`);
return response;
},
};
27 changes: 24 additions & 3 deletions components/braintree/braintree.app.mjs
Original file line number Diff line number Diff line change
@@ -1,11 +1,32 @@
import {
axios, ConfigurationError,
} from "@pipedream/platform";

export default {
type: "app",
app: "braintree",
propDefinitions: {},
methods: {
// this.$auth contains connected account data
authKeys() {
console.log(Object.keys(this.$auth));
async makeGraphQLRequest({
$ = this, ...opts
}) {
const response = await axios($, {
method: "post",
url: `https://${this.$auth.environment}.braintree-api.com/graphql`,
headers: {
"Braintree-Version": "2019-01-01",
"Content-Type": "application/json",
},
auth: {
username: this.$auth.public_key,
password: this.$auth.private_key,
},
...opts,
});
if (response.errors) {
throw new ConfigurationError(response.errors[0].message);
}
return response;
},
},
};
21 changes: 21 additions & 0 deletions components/braintree/common/mutations.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const createCustomer = `
mutation createCustomer($input: CreateCustomerInput!) {
createCustomer(input: $input) {
customer {
id
firstName
lastName
company
email
phoneNumber
fax
website
createdAt
}
}
}
`;

export default {
createCustomer,
};
69 changes: 69 additions & 0 deletions components/braintree/common/queries.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const searchCustomers = `
query Search($input: CustomerSearchInput!) {
search {
customers(input: $input) {
edges {
node {
id
firstName
lastName
company
email
phoneNumber
fax
website
createdAt
customFields {
name
value
}
}
}
}
}
}
`;

const searchTransactions = `
query ($input: TransactionSearchInput!) {
search {
transactions(input: $input) {
edges {
node {
id
status
amount {
value
currencyCode
}
paymentMethod {
id
}
orderId
merchantId
merchantName
customFields {
name
value
}
channel
customer {
id
}
lineItems {
name
quantity
totalAmount
}
createdAt
}
}
}
}
}
`;

export default {
searchCustomers,
searchTransactions,
};
5 changes: 4 additions & 1 deletion components/braintree/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/braintree",
"version": "0.0.3",
"version": "0.1.0",
"description": "Pipedream Braintree Components",
"main": "braintree.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,8 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^3.1.1"
}
}
63 changes: 63 additions & 0 deletions components/braintree/sources/common/base-polling.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import braintree from "../../braintree.app.mjs";
import {
DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, ConfigurationError,
} from "@pipedream/platform";

export default {
props: {
braintree,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_yesterday() {
const now = new Date();
const yesterday = new Date(now);
yesterday.setDate(now.getDate() - 1);
return yesterday.toISOString();
},
_getLastCreatedAt() {
return this.db.get("createdAt") || this._yesterday();
},
_setLastCreatedAt(lastCreatedAt) {
this.db.set("createdAt", lastCreatedAt);
},
emitEvent(result) {
const meta = this.generateMeta(result);
this.$emit(result, meta);
},
generateMeta(result) {
return {
id: result.id,
summary: this.getSummary(result),
ts: Date.parse(result.createdAt),
};
},
getResults() {
throw new ConfigurationError("getResults is not implemented");
},
getSummary() {
throw new ConfigurationError("getSummary is not implemented");
},
},
async run() {
const lastCreatedAt = this._getLastCreatedAt();
let maxCreatedAt = lastCreatedAt;

const results = await this.getResults(lastCreatedAt);
for (const result of results) {
const createdAt = result.createdAt;
this.emitEvent(result);
if (Date.parse(createdAt) > Date.parse(maxCreatedAt)) {
maxCreatedAt = createdAt;
}
}

this._setLastCreatedAt(maxCreatedAt);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import base from "../common/base-polling.mjs";
import queries from "../../common/queries.mjs";

export default {
...base,
key: "braintree-new-customer-created",
name: "New Customer Created",
description: "Emit new event when a new customer is created.",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...base.methods,
async getResults(lastCreatedAt) {
const { braintree } = this;
const response = await braintree.makeGraphQLRequest({
data: {
query: queries.searchCustomers,
variables: {
input: {
createdAt: {
greaterThanOrEqualTo: lastCreatedAt,
},
},
},
},
});
const edges = response?.data?.search?.customers?.edges ?? [];
return edges.map((edge) => edge.node);
},
getSummary(result) {
return `New Customer Created: ${result.id}`;
},
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import common from "../common/base-polling.mjs";
import queries from "../../common/queries.mjs";

export default {
...common,
key: "braintree-new-transaction-created",
name: "New Transaction Created",
description: "Emit new event when a new transaction is created.",
version: "0.0.1",
type: "source",
dedupe: "unique",
methods: {
...common.methods,
async getResults(lastCreatedAt) {
const { braintree } = this;
const response = await braintree.makeGraphQLRequest({
data: {
query: queries.searchTransactions,
variables: {
input: {
createdAt: {
greaterThanOrEqualTo: lastCreatedAt,
},
},
},
},
});
const edges = response?.data?.search?.transactions?.edges ?? [];
return edges.map((edge) => edge.node);
},
getSummary(result) {
return `New Transaction Created: ${result.id}`;
},
},
};
2 changes: 1 addition & 1 deletion components/upsales/upsales.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
2 changes: 1 addition & 1 deletion components/xero_payroll/xero_payroll.app.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ export default {
console.log(Object.keys(this.$auth));
},
},
};
};
6 changes: 5 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading