Skip to content

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 6 commits into from
Apr 29, 2025
Merged

New Components - ifthenpay #16393

merged 6 commits into from
Apr 29, 2025

Conversation

luancazarine
Copy link
Collaborator

@luancazarine luancazarine commented Apr 22, 2025

Resolves #16383.

Summary by CodeRabbit

  • New Features
    • Introduced Ifthenpay integration, enabling creation of payment references for Multibanco and MB WAY, issuing refunds, and detecting newly completed payments.
    • Added event source to emit notifications for new completed Ifthenpay payments.
  • Improvements
    • Enhanced payment method selection with predefined options for Ifthenpay actions.
  • Chores
    • Updated package dependencies for Ifthenpay integration.
  • Style
    • Added newline characters to several app files for consistency.

@luancazarine luancazarine added the ai-assisted Content generated by AI, with human refinement and modification label Apr 22, 2025
Copy link

vercel bot commented Apr 22, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs-v2 ⬜️ Ignored (Inspect) Visit Preview Apr 28, 2025 8:03pm
pipedream-docs ⬜️ Ignored (Inspect) Apr 28, 2025 8:03pm
pipedream-docs-redirect-do-not-edit ⬜️ Ignored (Inspect) Apr 28, 2025 8:03pm

Copy link
Contributor

coderabbitai bot commented Apr 22, 2025

"""

Walkthrough

This update introduces a new integration for Ifthenpay, including actions to generate payment references and issue refunds, as well as a polling source to emit events when payments are completed. It adds supporting constants, updates the app definition with new authentication and API methods, and includes a sample event for testing. Several other app files receive minor formatting changes with the addition of trailing newline characters. The package manifest is updated to include a dependency on "@pipedream/platform" and a new version number.

Changes

Files/Paths Change Summary
components/ifthenpay/actions/create-payment-reference/create-payment-reference.mjs New action: Generate payment references for Multibanco or MB WAY, with dynamic props and API call logic.
components/ifthenpay/actions/issue-refund/issue-refund.mjs New action: Issue full or partial refunds for completed payments via Ifthenpay API.
components/ifthenpay/common/constants.mjs New export: PAYMENT_METHOD_OPTIONS array for payment method selection.
components/ifthenpay/ifthenpay.app.mjs Major update: Adds prop definitions, API methods (generatePaymentReference, refundPayment, listPayments), and removes placeholder.
components/ifthenpay/package.json Version bump to 0.1.0; adds @pipedream/platform dependency.
components/ifthenpay/sources/new-payment/new-payment.mjs New polling source: Emits events for completed payments, manages last processed date, and emits on deploy.
components/ifthenpay/sources/new-payment/test-event.mjs New file: Exports sample payment event data for testing.
components/bika_ai/bika_ai.app.mjs
components/inferable/inferable.app.mjs
components/instasent/instasent.app.mjs
components/peerdom/peerdom.app.mjs
components/urltopdf/urltopdf.app.mjs
Minor formatting: Adds trailing newline at end of file.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Action_CreatePaymentReference
    participant IfthenpayApp
    participant IfthenpayAPI

    User->>Action_CreatePaymentReference: Provide payment details
    Action_CreatePaymentReference->>IfthenpayApp: generatePaymentReference(data)
    IfthenpayApp->>IfthenpayAPI: POST /init or /mbway (based on method)
    IfthenpayAPI-->>IfthenpayApp: Payment reference response
    IfthenpayApp-->>Action_CreatePaymentReference: Return result
    Action_CreatePaymentReference-->>User: Export summary
Loading
sequenceDiagram
    participant User
    participant Action_IssueRefund
    participant IfthenpayApp
    participant IfthenpayAPI

    User->>Action_IssueRefund: Provide refund details
    Action_IssueRefund->>IfthenpayApp: refundPayment(data)
    IfthenpayApp->>IfthenpayAPI: POST /refund
    IfthenpayAPI-->>IfthenpayApp: Refund response
    IfthenpayApp-->>Action_IssueRefund: Return result
    Action_IssueRefund-->>User: Export summary
Loading
sequenceDiagram
    participant Source_NewPayment
    participant IfthenpayApp
    participant IfthenpayAPI
    participant User

    Source_NewPayment->>IfthenpayApp: listPayments(since lastDate)
    IfthenpayApp->>IfthenpayAPI: POST /read
    IfthenpayAPI-->>IfthenpayApp: List of new payments
    IfthenpayApp-->>Source_NewPayment: Return payment data
    Source_NewPayment-->>User: Emit event(s) for new payments
Loading

Assessment against linked issues

Objective Addressed Explanation
Implement polling source to emit event on successful payment (new-payment) [#16383]
Implement action to generate Multibanco or MB WAY payment reference (create-payment-reference) [#16383]
Implement action to issue full/partial refund for completed payment (issue-refund) [#16383]
Support required/optional props as described for actions and source [#16383]

Suggested reviewers

  • lcaresia

Poem

A hop, a leap, a payment made,
Refunds and references now cascade.
Ifthenpay’s new tricks delight,
Hopping through events, day and night.
With every bounce, new flows appear,
The code is fresh—let’s give a cheer!
🐇💸
"""

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

components/ifthenpay/actions/create-payment-reference/create-payment-reference.mjs

Oops! Something went wrong! :(

ESLint: 8.57.1

Error [ERR_MODULE_NOT_FOUND]: Cannot find package 'jsonc-eslint-parser' imported from /eslint.config.mjs
at packageResolve (node:internal/modules/esm/resolve:839:9)
at moduleResolve (node:internal/modules/esm/resolve:908:18)
at defaultResolve (node:internal/modules/esm/resolve:1038:11)
at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:557:12)
at ModuleLoader.resolve (node:internal/modules/esm/loader:525:25)
at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:246:38)
at ModuleJob._link (node:internal/modules/esm/module_job:126:49)


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a5eff78 and 558c676.

📒 Files selected for processing (1)
  • components/ifthenpay/actions/create-payment-reference/create-payment-reference.mjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/ifthenpay/actions/create-payment-reference/create-payment-reference.mjs
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components
  • GitHub Check: Verify TypeScript components
✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sources
 - New Payment

Actions
 - Create Payment Reference
 - Issue Refund
lcaresia
lcaresia previously approved these changes Apr 23, 2025
@luancazarine luancazarine marked this pull request as ready for review April 24, 2025 16:28
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 4

🧹 Nitpick comments (6)
components/ifthenpay/sources/new-payment/test-event.mjs (1)

1-13: Test event structure looks good but missing trailing newline.

The test event object provides a comprehensive sample with appropriate data types and values for testing payment events. The date format in paymentDate follows the European format (DD-MM-YYYY).

Add a trailing newline at the end of the file to follow best practices:

  "terminal": "5-0000000000-CAIXA GERAL DE "
}
+
components/ifthenpay/actions/issue-refund/issue-refund.mjs (2)

3-22: Component definition looks good, but consider improving the amount prop.

The action component follows Pipedream's component pattern with appropriate metadata and property definitions.

Consider enhancing the amount property with validation to ensure it's a valid currency value:

    amount: {
      type: "string",
      label: "Amount",
      description: "The amount to be refunded.",
+     pattern: "^\\d+(\\.\\d{1,2})?$",
+     examples: ["10.50", "100"],
    },

36-37: Add trailing newline at the end of the file.

Following best practices, add a trailing newline at the end of the file.

};
+
components/ifthenpay/ifthenpay.app.mjs (1)

11-31: Consider adding error handling for the async options method.

While the implementation works well, it's missing error handling for potential API failures.

 async options({ prevContext }) {
+  try {
     const { payments } = await this.listPayments({
       data: {
         dateStart: prevContext.token,
       },
     });

+    if (!payments || !Array.isArray(payments)) {
+      return {
+        options: [],
+        context: { token: null },
+      };
+    }
+
     return {
       options: payments.map(({
         requestId: value, orderId: label,
       }) => ({
         label,
         value,
       })),
       context: {
         token: payments.length
           ? payments[0].paymentDate
           : null,
       },
     };
+  } catch (error) {
+    console.error('Error fetching payment requests:', error);
+    return {
+      options: [],
+      context: prevContext,
+    };
+  }
 },
components/ifthenpay/actions/create-payment-reference/create-payment-reference.mjs (2)

77-81: Fix incorrect description for the email property.

The email property has an incorrect description that doesn't match its purpose.

 email: {
   type: "string",
   label: "Email",
-  description: "The Client's name.",
+  description: "The client's email address, with a maximum length of 200 characters",
   optional: true,
 },

127-148: Remove duplicate client email in API request.

The data object includes both email and clientEmail with the same value, which is redundant.

 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,
 },
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5ab8a83 and a5eff78.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (12)
  • components/bika_ai/bika_ai.app.mjs (1 hunks)
  • components/ifthenpay/actions/create-payment-reference/create-payment-reference.mjs (1 hunks)
  • components/ifthenpay/actions/issue-refund/issue-refund.mjs (1 hunks)
  • components/ifthenpay/common/constants.mjs (1 hunks)
  • components/ifthenpay/ifthenpay.app.mjs (1 hunks)
  • components/ifthenpay/package.json (2 hunks)
  • components/ifthenpay/sources/new-payment/new-payment.mjs (1 hunks)
  • components/ifthenpay/sources/new-payment/test-event.mjs (1 hunks)
  • components/inferable/inferable.app.mjs (1 hunks)
  • components/instasent/instasent.app.mjs (1 hunks)
  • components/peerdom/peerdom.app.mjs (1 hunks)
  • components/urltopdf/urltopdf.app.mjs (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Verify TypeScript components
  • GitHub Check: pnpm publish
  • GitHub Check: Publish TypeScript components
🔇 Additional comments (22)
components/inferable/inferable.app.mjs (1)

11-11: Consistent EOF newline
A single newline was added at the end of the file for formatting consistency. No functional modifications were made.

components/instasent/instasent.app.mjs (1)

11-11: Consistent EOF newline
A single newline was added at the end of the file for formatting consistency. No functional modifications were made.

components/bika_ai/bika_ai.app.mjs (1)

11-11: Consistent EOF newline
A single newline was added at the end of the file for formatting consistency. No functional modifications were made.

components/peerdom/peerdom.app.mjs (1)

11-11: Consistent EOF newline
A single newline was added at the end of the file for formatting consistency. No functional modifications were made.

components/urltopdf/urltopdf.app.mjs (1)

11-11: Consistent EOF newline
A single newline was added at the end of the file for formatting consistency. No functional modifications were made.

components/ifthenpay/common/constants.mjs (1)

1-4: LGTM: Clean constant definition for payment methods.

The constant PAYMENT_METHOD_OPTIONS is well-defined and will serve as a centralized reference for supported payment methods across the Ifthenpay integration.

components/ifthenpay/package.json (2)

3-3: Version bump follows semantic versioning.

The version upgrade from 0.0.1 to 0.1.0 appropriately reflects the addition of new features without breaking changes.


14-16: LGTM: Required dependency added properly.

Adding the dependency on @pipedream/platform is appropriate for the expanded Ifthenpay integration functionality.

components/ifthenpay/actions/issue-refund/issue-refund.mjs (1)

1-2: LGTM: Proper import and spacing.

The import statement for the Ifthenpay app is correctly defined with appropriate spacing.

components/ifthenpay/ifthenpay.app.mjs (4)

1-2: Appropriate import from Pipedream platform.

Good choice importing axios from the Pipedream platform package instead of using it directly. This helps maintain consistency with platform standards.


6-45: Well-structured prop definitions with proper descriptions and appropriate security measures.

The prop definitions are well-organized with clear labels and descriptions. Good practice marking the API keys as secret: true for security purposes.

For the requestId prop, the async options implementation provides a good user experience by fetching and formatting payment data dynamically.


47-67: Well-structured HTTP request helper methods.

Good job implementing helper methods for API interactions:

  • _baseUrl() for the consistent API URL
  • _data() for handling authentication keys
  • _makeRequest() as a reusable request wrapper with consistent headers

These utility methods follow best practices for organizing API integration code.


85-98: Clean implementation of payment service methods.

The refundPayment and listPayments methods are implemented cleanly, following the same pattern and reusing the _makeRequest utility method.

components/ifthenpay/actions/create-payment-reference/create-payment-reference.mjs (4)

1-9: Good module composition with appropriate metadata.

The action module is well-organized with proper imports and clear metadata. The description provides helpful context and includes a link to documentation.


10-18: Well-structured props with proper reloadProps implementation.

Good job implementing reloadProps: true for the payment method selection, allowing dynamic UI updates based on the selected option.


104-126: Well-implemented dynamic props handling.

The additionalProps method effectively manages visibility and default values based on the selected payment method. Good practice updating labels and descriptions dynamically.

One minor suggestion:

 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 {};
+  return props; // Return props to maintain consistency with standard additionalProps pattern
 },

149-152: Good job providing a clear success message.

The export summary provides clear feedback on the action's result, which improves user experience.

components/ifthenpay/sources/new-payment/new-payment.mjs (5)

1-12: Well-structured source component with proper imports and metadata.

Good job using the standard pattern for Pipedream source components, including the proper default polling interval and deduplication strategy.


12-21: Standard and clean props implementation for source components.

The props follow Pipedream's best practices for source components with proper timer and database integration.


22-28: Clean implementation of database helpers.

The database helper methods are concise and follow best practices for persisting state in Pipedream sources.


54-62: Good implementation of source lifecycle hooks.

The deploy hook correctly limits the initial emission to 25 items to prevent overwhelming the workflow. The run method keeps the implementation simple and focused.


45-51:

❓ Verification inconclusive

Verify the order of emitted events.

The code reverses the payment array before emission, which might impact the chronological order of events.

Currently, you're using response.reverse() which reverses the array in place. Verify that this is the intended behavior:

  1. If the API returns payments in descending order (newest first), then reversing makes sense to emit oldest payments first
  2. If the API returns payments in ascending order (oldest first), then reversing would emit newest payments first

🏁 Script executed:

#!/bin/bash
# Check if there are comments or documentation about the order of payments
rg -i "order|sort|chronological" --type js components/ifthenpay

Length of output: 65


Verify the ordering of emitted events

I couldn’t find any in-code documentation on whether the IfThenPay API returns payments in ascending (oldest-first) or descending (newest-first) order. Please confirm the API’s default sort order in its official docs or by inspecting a sample response:

  • If the API returns newest-first, keep the .reverse() so you emit oldest-first.
  • If the API returns oldest-first, remove the .reverse() so you emit newest-first.

@luancazarine
Copy link
Collaborator Author

/approve

@luancazarine luancazarine merged commit 57f04ff into master Apr 29, 2025
11 checks passed
@luancazarine luancazarine deleted the issue-16383 branch April 29, 2025 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai-assisted Content generated by AI, with human refinement and modification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Components] ifthenpay
2 participants