-
Notifications
You must be signed in to change notification settings - Fork 5.5k
8427 components mamo business #8510
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
Changes from all commits
Commits
Show all changes
3 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
There are no files selected for viewing
251 changes: 251 additions & 0 deletions
251
components/mamo_business/actions/create-payment-link/create-payment-link.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,251 @@ | ||
| import { parseObject } from "../../common/utils.mjs"; | ||
| import app from "../../mamo_business.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "mamo_business-create-payment-link", | ||
| name: "Create Payment Link", | ||
| version: "0.0.1", | ||
| description: "Generate a vanilla or subscription payment link. [See the documentation](https://mamopay.readme.io/reference/post_links)", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| title: { | ||
| type: "string", | ||
| label: "Title", | ||
| description: "The title of the payment link.", | ||
| }, | ||
| description: { | ||
| type: "string", | ||
| label: "Description", | ||
| description: "Payment description. This will appear on the payment checkout page.", | ||
| optional: true, | ||
| }, | ||
| capacity: { | ||
| type: "integer", | ||
| label: "Capacity", | ||
| description: "The capacity will be ignored when the subscription params exist and value will be null.", | ||
| optional: true, | ||
| }, | ||
| active: { | ||
| type: "boolean", | ||
| label: "Active", | ||
| description: "Whether the payment is active or not.", | ||
| optional: true, | ||
| }, | ||
| returnUrl: { | ||
| type: "string", | ||
| label: "Return URL", | ||
| description: "The URL which the customer will be redirected to after a successful payment.", | ||
| optional: true, | ||
| }, | ||
| failureReturnUrl: { | ||
| type: "string", | ||
| label: "Failure Return URL", | ||
| description: "The URL which the customer will be redirected to after a failure payment.", | ||
| optional: true, | ||
| }, | ||
| processingFeePercentage: { | ||
| type: "integer", | ||
| label: "Processing Fee Percentage", | ||
| description: "The percentage of the transaction that is the fee.", | ||
| optional: true, | ||
| }, | ||
| amount: { | ||
| type: "string", | ||
| label: "Amount", | ||
| description: "The value number of the payment.", | ||
| optional: true, | ||
| }, | ||
| amountCurrency: { | ||
| type: "string", | ||
| label: "Amount Currency", | ||
| description: "The currency that the transaction will be charged.", | ||
| default: "AED", | ||
| options: [ | ||
| "AED", | ||
| "USD", | ||
| "EUR", | ||
| "GBP", | ||
| "SAR", | ||
| ], | ||
| }, | ||
| isWidget: { | ||
| type: "boolean", | ||
| label: "Is Widget", | ||
| description: "Generate widget payment link.", | ||
| optional: true, | ||
| }, | ||
| enableTabby: { | ||
| type: "boolean", | ||
| label: "Enable Tabby", | ||
| description: "Enables the ability for customers to buy now and pay later.", | ||
| optional: true, | ||
| }, | ||
| enableMessage: { | ||
| type: "boolean", | ||
| label: "Enable Message", | ||
| description: "Enables the ability for customers to add a message during the checkout process.", | ||
| optional: true, | ||
| }, | ||
| enableTips: { | ||
| type: "boolean", | ||
| label: "Enable Tips", | ||
| description: "Enables the tips option. This will be displayed on the first screen.", | ||
| optional: true, | ||
| }, | ||
| enableCustomerDetails: { | ||
| type: "boolean", | ||
| label: "Enable Customer Details", | ||
| description: "Enables adding customer details such as the name, email, and phone number. This screen will be displayed before the payment details screen.", | ||
| optional: true, | ||
| }, | ||
| enableQuantity: { | ||
| type: "boolean", | ||
| label: "Enable Quantity", | ||
| description: "Enable the payment link to be used multiple times.", | ||
| optional: true, | ||
| }, | ||
| enableQrCode: { | ||
| type: "boolean", | ||
| label: "Enable QR Code", | ||
| description: "Adds the ability to verify a payment through a QR code.", | ||
| optional: true, | ||
| }, | ||
| sendCustomerReceipt: { | ||
| type: "boolean", | ||
| label: "Send Customer Receipt", | ||
| description: "Enables the sending of customer receipts.", | ||
| optional: true, | ||
| }, | ||
| firstName: { | ||
| type: "string", | ||
| label: "First Name", | ||
| description: "The first name of customer which will pre-populate in card info step.", | ||
| optional: true, | ||
| }, | ||
| lastName: { | ||
| type: "string", | ||
| label: "Last Name", | ||
| description: "The last name of customer which will pre-populate in card info step.", | ||
| optional: true, | ||
| }, | ||
| email: { | ||
| type: "string", | ||
| label: "Email", | ||
| description: "The email of customer which will pre-populate in card info step.", | ||
| optional: true, | ||
| }, | ||
| externalId: { | ||
| type: "string", | ||
| label: "External Id", | ||
| description: "The external ID of your choice to associate with payments captured by this payment link.", | ||
| optional: true, | ||
| }, | ||
| customData: { | ||
| type: "object", | ||
| label: "Custom Data", | ||
| description: "An object with custom data of the payment link.", | ||
| optional: true, | ||
| }, | ||
| isRecurring: { | ||
| type: "boolean", | ||
| label: "Is Recurring", | ||
| description: "Whether this payment link is for a recurring payment.", | ||
| reloadProps: true, | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const props = {}; | ||
| if (this.isRecurring) { | ||
| props.frequency = { | ||
| type: "string", | ||
| label: "Frequency", | ||
| description: "Defines the interval that this subscription will be run on.", | ||
| options: [ | ||
| "weekly", | ||
| "monthly", | ||
| "annually", | ||
| ], | ||
| }; | ||
| props.frequencyInterval = { | ||
| type: "integer", | ||
| label: "Frequency Interval", | ||
| description: "Defines how often this subscription will run. This will be based on the frequency property defined above.", | ||
| }; | ||
| props.endDate = { | ||
| type: "string", | ||
| label: "End Date", | ||
| description: "The last date this subscription could run on. Format: YYYY/MM/DD", | ||
| }; | ||
| props.paymentQuantity = { | ||
| type: "string", | ||
| label: "Payment Quantity", | ||
| description: "Number of times this subscription will occur. If end_date defined, end_date takes precedence.", | ||
| }; | ||
| } | ||
| return props; | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| app, | ||
| returnUrl, | ||
| failureReturnUrl, | ||
| processingFeePercentage, | ||
| amountCurrency, | ||
| isWidget, | ||
| enableTabby, | ||
| enableMessage, | ||
| enableTips, | ||
| enableCustomerDetails, | ||
| enableQuantity, | ||
| enableQrCode, | ||
| sendCustomerReceipt, | ||
| firstName, | ||
| lastName, | ||
| externalId, | ||
| customData, | ||
| isRecurring, | ||
| frequency, | ||
| frequencyInterval, | ||
| endDate, | ||
| paymentQuantity, | ||
| ...data | ||
| } = this; | ||
|
|
||
| const obj = { | ||
| return_url: returnUrl, | ||
| failure_return_url: failureReturnUrl, | ||
| processing_fee_percentage: processingFeePercentage, | ||
| amount_currency: amountCurrency, | ||
| is_widget: isWidget, | ||
| enable_tabby: enableTabby, | ||
| enable_message: enableMessage, | ||
| enable_tips: enableTips, | ||
| enable_customer_details: enableCustomerDetails, | ||
| enable_quantity: enableQuantity, | ||
| enable_qr_code: enableQrCode, | ||
| send_customer_receipt: sendCustomerReceipt, | ||
| first_name: firstName, | ||
| last_name: lastName, | ||
| external_id: externalId, | ||
| custom_data: customData && parseObject(customData), | ||
| ...data, | ||
| }; | ||
| if (isRecurring) { | ||
| obj.subscription = { | ||
| frequency, | ||
| frequency_interval: frequencyInterval, | ||
| end_ate: endDate, | ||
| payment_quantity: paymentQuantity, | ||
| }; | ||
| } | ||
|
|
||
| const response = await app.createPaymentLink({ | ||
| $, | ||
| data: obj, | ||
| }); | ||
|
|
||
| $.export("$summary", `A new payment link with Id: ${response.id} was successfully created!`); | ||
| 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,6 @@ | ||
| export const parseObject = (obj) => { | ||
| if (typeof obj != "object") { | ||
| return JSON.parse(obj); | ||
luancazarine marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| return obj; | ||
| }; | ||
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,47 @@ | ||
| import { axios } from "@pipedream/platform"; | ||
|
|
||
| export default { | ||
| type: "app", | ||
| app: "mamo_business", | ||
| propDefinitions: {}, | ||
| methods: { | ||
| // this.$auth contains connected account data | ||
| authKeys() { | ||
| console.log(Object.keys(this.$auth)); | ||
| _apiUrl() { | ||
| return `https://${this.$auth.environment}.mamopay.com/manage_api/v1`; | ||
| }, | ||
| _getHeaders() { | ||
| return { | ||
| "Authorization": `Bearer ${this.$auth.api_key}`, | ||
| }; | ||
| }, | ||
| _makeRequest({ | ||
| $ = this, path, ...opts | ||
| }) { | ||
| const config = { | ||
| url: `${this._apiUrl()}/${path}`, | ||
| headers: this._getHeaders(), | ||
| ...opts, | ||
| }; | ||
|
|
||
| return axios($, config); | ||
| }, | ||
| createHook(args = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "webhooks", | ||
| ...args, | ||
| }); | ||
| }, | ||
| createPaymentLink(args = {}) { | ||
| return this._makeRequest({ | ||
| method: "POST", | ||
| path: "links", | ||
| ...args, | ||
| }); | ||
| }, | ||
| deleteHook(hookId) { | ||
| return this._makeRequest({ | ||
| method: "DELETE", | ||
| path: `webhooks/${hookId}`, | ||
| }); | ||
| }, | ||
| }, | ||
| }; | ||
| }; |
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
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,56 @@ | ||
| import app from "../../mamo_business.app.mjs"; | ||
|
|
||
| export default { | ||
| dedupe: "unique", | ||
| props: { | ||
| app, | ||
| http: { | ||
| type: "$.interface.http", | ||
| customResponse: true, | ||
| }, | ||
| db: "$.service.db", | ||
| }, | ||
| hooks: { | ||
| async activate() { | ||
| const data = await this.app.createHook({ | ||
| data: { | ||
| url: this.http.endpoint, | ||
| enabled_events: this.getEvent(), | ||
| }, | ||
| }); | ||
|
|
||
| this._setHookId(data.id); | ||
| }, | ||
| async deactivate() { | ||
| const id = this._getHookId("hookId"); | ||
| await this.app.deleteHook(id); | ||
| }, | ||
| }, | ||
| methods: { | ||
| emitEvent(body) { | ||
| const meta = this.generateMeta(body); | ||
| this.$emit(body, meta); | ||
| }, | ||
| _getHookId() { | ||
| return this.db.get("hookId"); | ||
| }, | ||
| _setHookId(hookId) { | ||
| this.db.set("hookId", hookId); | ||
| }, | ||
| generateMeta(body) { | ||
| return { | ||
| id: `${body.id}${body.created_date}`, | ||
| summary: this.getSummary(body), | ||
| ts: new Date(), | ||
| }; | ||
| }, | ||
| }, | ||
| async run({ body }) { | ||
| if (body.ping) { | ||
| return this.http.respond({ | ||
| status: 200, | ||
| }); | ||
| } | ||
| this.emitEvent(body); | ||
| }, | ||
| }; |
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.