-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New Components - ifthenpay #16393
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
New Components - ifthenpay #16393
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
1578b90
ifthenpay init
luancazarine 2dbcfec
[Components] ifthenpay #16383
luancazarine a6c7ef3
pnpm update
luancazarine b9b8911
Merge branch 'master' into issue-16383
luancazarine a5eff78
some adjusts
luancazarine 558c676
some adjusts
luancazarine 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
There are no files selected for viewing
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)); | ||
| }, | ||
| }, | ||
| }; | ||
| }; | ||
153 changes: 153 additions & 0 deletions
153
components/ifthenpay/actions/create-payment-reference/create-payment-reference.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,153 @@ | ||
| import { PAYMENT_METHOD_OPTIONS } from "../../common/constants.mjs"; | ||
| import ifthenpay from "../../ifthenpay.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "ifthenpay-create-payment-reference", | ||
| name: "Create Payment Reference", | ||
| description: "Generates a Multibanco or MB WAY payment reference with a specified amount, entity code, and deadline. [See the documentation](https://ifthenpay.com/docs/en/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| ifthenpay, | ||
| paymentMethod: { | ||
| type: "string", | ||
| label: "Payment Method", | ||
| description: "The payment method to use for Ifthenpay (e.g., MB WAY, Multibanco)", | ||
| options: PAYMENT_METHOD_OPTIONS, | ||
| reloadProps: true, | ||
| }, | ||
| mbKey: { | ||
| propDefinition: [ | ||
| ifthenpay, | ||
| "mbKey", | ||
| ], | ||
| hidden: true, | ||
| }, | ||
| mbWayKey: { | ||
| propDefinition: [ | ||
| ifthenpay, | ||
| "mbWayKey", | ||
| ], | ||
| hidden: true, | ||
| }, | ||
| orderId: { | ||
| type: "string", | ||
| label: "Order Id", | ||
| description: "Payment identifier defined by the client (e.g., invoice number, order number, etc.)", | ||
| }, | ||
| amount: { | ||
| type: "string", | ||
| label: "Amount", | ||
| description: "The amount to be paid with decimal separator \".\"", | ||
| }, | ||
| mobileNumber: { | ||
| type: "string", | ||
| label: "Mobile Number", | ||
| description: "Place the country code before the mobile number without any spaces (use '#'' to separate the country code from the mobile number - p.e. 351#912345678)", | ||
| hidden: true, | ||
| }, | ||
| description: { | ||
| type: "string", | ||
| label: "Description", | ||
| description: "Description of the payment, with a maximum length of 200 characters", | ||
| optional: true, | ||
| }, | ||
| url: { | ||
| type: "string", | ||
| label: "URL", | ||
| description: "URL address, with a maximum length of 200 characters", | ||
| optional: true, | ||
| hidden: true, | ||
| }, | ||
| clientCode: { | ||
| type: "string", | ||
| label: "Client Code", | ||
| description: "Client's code, with a maximum length of 200 characters", | ||
| optional: true, | ||
| hidden: true, | ||
| }, | ||
| clientName: { | ||
| type: "string", | ||
| label: "Client Name", | ||
| description: "Client's name, with a maximum length of 200 characters", | ||
| optional: true, | ||
| hidden: true, | ||
| }, | ||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "The Client's name.", | ||
| optional: true, | ||
| }, | ||
| clientUsername: { | ||
| type: "string", | ||
| label: "Client Username", | ||
| description: "Client's username, with a maximum length of 200 characters", | ||
| optional: true, | ||
| hidden: true, | ||
| }, | ||
| clientPhone: { | ||
| type: "string", | ||
| label: "Client Phone", | ||
| description: "Client's cell phone or phone number, with a maximum length of 200 characters", | ||
| optional: true, | ||
| hidden: true, | ||
| }, | ||
| expiryDays: { | ||
| type: "integer", | ||
| label: "Expiry Days", | ||
| description: "How many days the payment reference is valid for. [See the documentation](https://ifthenpay.com/docs/en/api/multibanco/#tag/multibanco/POST/init) for further details.", | ||
| optional: true, | ||
| hidden: true, | ||
| }, | ||
| }, | ||
| async additionalProps(props) { | ||
| const isMb = this.paymentMethod === "Multibanco"; | ||
|
|
||
| props.mbKey.default = isMb | ||
| ? this.ifthenpay.$auth.mb_key | ||
| : null; | ||
| props.mbKey.hidden = !isMb; | ||
|
|
||
| props.mbWayKey.default = !isMb | ||
| ? this.ifthenpay.$auth.mbway_key | ||
| : null; | ||
| props.mbWayKey.hidden = isMb; | ||
| props.mobileNumber.hidden = isMb; | ||
| props.url.hidden = isMb; | ||
| props.clientCode.hidden = isMb; | ||
| props.clientName.hidden = isMb; | ||
| props.email.label = "Client Email"; | ||
| props.email.description = "Client's email address, with a maximum length of 200 characters"; | ||
| props.clientUsername.hidden = isMb; | ||
| props.clientPhone.hidden = isMb; | ||
| props.expiryDays.hidden = isMb; | ||
| return {}; | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.ifthenpay.generatePaymentReference({ | ||
| $, | ||
| paymentMethod: this.paymentMethod, | ||
| data: { | ||
| mbKey: this.mbKey, | ||
| mbWayKey: this.mbWayKey, | ||
| orderId: this.orderId, | ||
| amount: parseFloat(this.amount), | ||
| mobileNumber: this.mobileNumber, | ||
| email: this.email, | ||
| description: this.description, | ||
| url: this.url, | ||
| clientCode: this.clientCode, | ||
| clientName: this.clientName, | ||
| clientUsername: this.clientUsername, | ||
| clientPhone: this.clientPhone, | ||
| expiryDays: this.expiryDays, | ||
| expirationDate: this.expirationDate, | ||
| clientEmail: this.email, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully created payment reference with Order ID: ${response.OrderId}`); | ||
| return response; | ||
| }, | ||
| }; | ||
36 changes: 36 additions & 0 deletions
36
components/ifthenpay/actions/issue-refund/issue-refund.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,36 @@ | ||
| import ifthenpay from "../../ifthenpay.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "ifthenpay-issue-refund", | ||
| name: "Issue Refund", | ||
| description: "Issue a full or partial refund for a previously completed payment via Ifthenpay. [See the documentation](https://ifthenpay.com/docs/en/)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| ifthenpay, | ||
| requestId: { | ||
| propDefinition: [ | ||
| ifthenpay, | ||
| "requestId", | ||
| ], | ||
| }, | ||
| amount: { | ||
| type: "string", | ||
| label: "Amount", | ||
| description: "The amount to be refunded.", | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.ifthenpay.refundPayment({ | ||
| $, | ||
| data: { | ||
| backofficekey: this.ifthenpay.$auth.backoffice_key, | ||
| requestId: this.requestId, | ||
| amount: this.amount, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully issued a refund for payment ID: ${this.requestId}`); | ||
| return response; | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }; | ||
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,4 @@ | ||
| export const PAYMENT_METHOD_OPTIONS = [ | ||
| "MB WAY", | ||
| "Multibanco", | ||
| ]; |
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,101 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "ifthenpay", | ||
| propDefinitions: {}, | ||
| propDefinitions: { | ||
| requestId: { | ||
| type: "string", | ||
| label: "Request ID", | ||
| description: "Token associated with the payment request transaction", | ||
| async options({ prevContext }) { | ||
| const { payments } = await this.listPayments({ | ||
| data: { | ||
| dateStart: prevContext.token, | ||
| }, | ||
| }); | ||
|
|
||
| return { | ||
| options: payments.map(({ | ||
| requestId: value, orderId: label, | ||
| }) => ({ | ||
| label, | ||
| value, | ||
| })), | ||
| context: { | ||
| token: payments.length | ||
| ? payments[0].paymentDate | ||
| : null, | ||
| }, | ||
| }; | ||
| }, | ||
| }, | ||
| mbWayKey: { | ||
| type: "string", | ||
| label: "Mb Way Key", | ||
| description: "The key for the MB Way payment method.", | ||
| secret: true, | ||
| }, | ||
| mbKey: { | ||
| type: "string", | ||
| label: "Mb Key", | ||
| description: "The key for the Multibanco payment method.", | ||
| secret: true, | ||
| }, | ||
| }, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _baseUrl() { | ||
| return "https://api.ifthenpay.com"; | ||
| }, | ||
| _data(data) { | ||
| return { | ||
| "boKey": `${this.$auth.backoffice_key}`, | ||
| ...data, | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, data, ...opts | ||
| }) { | ||
| return axios($, { | ||
| url: this._baseUrl() + path, | ||
| headers: { | ||
| "accept": "application/json", | ||
| }, | ||
| data: this._data(data), | ||
| ...opts, | ||
| }); | ||
| }, | ||
| generatePaymentReference({ | ||
| paymentMethod, data, ...opts | ||
| }) { | ||
| let path; | ||
| if (paymentMethod === "Multibanco") { | ||
| path = "/multibanco/reference/init"; | ||
| } else if (paymentMethod === "MB WAY") { | ||
| path = "/spg/payment/mbway"; | ||
| } | ||
|
|
||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path, | ||
| data, | ||
| ...opts, | ||
| }); | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| refundPayment(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/endpoint/payments/refund", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| listPayments(opts = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "/v2/payments/read", | ||
| ...opts, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
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/ifthenpay", | ||
| "version": "0.0.1", | ||
| "version": "0.1.0", | ||
| "description": "Pipedream ifthenpay Components", | ||
| "main": "ifthenpay.app.mjs", | ||
| "keywords": [ | ||
|
|
@@ -11,5 +11,8 @@ | |
| "author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
| "publishConfig": { | ||
| "access": "public" | ||
| }, | ||
| "dependencies": { | ||
| "@pipedream/platform": "^3.0.3" | ||
| } | ||
| } | ||
| } | ||
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 { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform"; | ||
| import ifthenpay from "../../ifthenpay.app.mjs"; | ||
| import sampleEmit from "./test-event.mjs"; | ||
|
|
||
| export default { | ||
| key: "ifthenpay-new-payment", | ||
| name: "New Payment Completed", | ||
| description: "Emit new event when a payment is successfully completed through Ifthenpay. [See the documentation](https://ifthenpay.com/docs/en/)", | ||
| version: "0.0.1", | ||
| type: "source", | ||
| dedupe: "unique", | ||
| props: { | ||
| ifthenpay, | ||
| db: "$.service.db", | ||
| timer: { | ||
| type: "$.interface.timer", | ||
| default: { | ||
| intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL, | ||
| }, | ||
| }, | ||
| }, | ||
| methods: { | ||
| _getLastDate() { | ||
| return this.db.get("lastDate") || "1970-01-01 00:00:00"; | ||
| }, | ||
| _setLastDate(lastDate) { | ||
| this.db.set("lastDate", lastDate); | ||
| }, | ||
| async emitEvent(maxResults = false) { | ||
| const lastDate = this._getLastDate(); | ||
|
|
||
| const { payments: response } = await this.ifthenpay.listPayments({ | ||
| data: { | ||
| dateStart: lastDate, | ||
| }, | ||
| }); | ||
|
|
||
| if (response.length) { | ||
| if (maxResults && (response.length > maxResults)) { | ||
| response.length = maxResults; | ||
| } | ||
| this._setLastDate(response[0].paymentDate); | ||
| } | ||
|
|
||
| for (const item of response.reverse()) { | ||
| this.$emit(item, { | ||
| id: item.requestId, | ||
| summary: `New Payment: ${parseFloat(item.amount)} ${item.entity}`, | ||
| ts: Date.parse(item.paymentDate), | ||
| }); | ||
| } | ||
| }, | ||
| }, | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| hooks: { | ||
| async deploy() { | ||
| await this.emitEvent(25); | ||
| }, | ||
| }, | ||
| async run() { | ||
| await this.emitEvent(); | ||
| }, | ||
| sampleEmit, | ||
| }; | ||
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.