-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Braintree - new components #19407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Braintree - new components #19407
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
components/braintree/actions/create-customer/create-customer.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }, | ||
| auth: { | ||
| username: this.$auth.public_key, | ||
| password: this.$auth.private_key, | ||
| }, | ||
| ...opts, | ||
| }); | ||
| if (response.errors) { | ||
| throw new ConfigurationError(response.errors[0].message); | ||
| } | ||
| return response; | ||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| phoneNumber | ||
| fax | ||
| website | ||
| createdAt | ||
| } | ||
| } | ||
| } | ||
| `; | ||
|
|
||
| export default { | ||
| createCustomer, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
| phoneNumber | ||
| fax | ||
| website | ||
| createdAt | ||
| customFields { | ||
| name | ||
| value | ||
| } | ||
| } | ||
| } | ||
| } | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| } | ||
| `; | ||
|
|
||
| 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, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.1.1" | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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), | ||
| }; | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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); | ||
| }, | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
35 changes: 35 additions & 0 deletions
35
components/braintree/sources/new-customer-created/new-customer-created.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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}`; | ||
| }, | ||
| }, | ||
| }; |
35 changes: 35 additions & 0 deletions
35
components/braintree/sources/new-transaction-created/new-transaction-created.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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", | ||
michelle0927 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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}`; | ||
| }, | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,4 +8,4 @@ export default { | |
| console.log(Object.keys(this.$auth)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.