Skip to content

feat: add type, first 6, last 4 fields to the wallet cc form#1

Open
chrismshea wants to merge 3 commits into
rel-1.5.17from
1517-walletForm
Open

feat: add type, first 6, last 4 fields to the wallet cc form#1
chrismshea wants to merge 3 commits into
rel-1.5.17from
1517-walletForm

Conversation

@chrismshea
Copy link
Copy Markdown
Owner

@chrismshea chrismshea commented Feb 14, 2025

Building on the 1.5.17 release to support SP Vault in the customer wallet card form.

Summary by CodeRabbit

  • New Features
    • The payment process now captures additional credit card details (including card type and digit segments) to provide a more comprehensive transaction profile and improve payment processing reliability.
    • Enhanced component functionality to handle and submit new credit card information during the payment process.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 14, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The update refines the payment processing flow by improving code readability and extending data handling for credit card details. In the backend, both the card save controller and wallet payment builder now extract and pass additional credit card information. In the frontend, the JavaScript component managing vault cards is enhanced to observe and submit these new properties. No public entity declarations were modified.

Changes

File(s) Change Summary
Controller/Cards/Save.php Reformatted condition in execute for clarity and added new credit card parameters (creditcard_type, creditcard_first_digits, creditcard_last_digits) in prepareVerifyCommandSubject.
Gateway/Request/WalletPaymentBuilder.php Updated build method to include new credit card entries (CREDITCARD_TYPE, CREDITCARD_LAST_DIGITS, CREDITCARD_FIRST_DIGITS) using null coalescing.
view/frontend/web/js/.../card.js Introduced new properties (creditCardLastDigits, creditCardFirstDigits, paymentMethodToken, selectedCardType), updated observable initialization, and amended payment data submission to include new credit card fields.

Sequence Diagram(s)

sequenceDiagram
    participant JS as JS Payment Component
    participant CTRL as Save Controller
    participant WPB as WalletPaymentBuilder
    participant PG as Payment Gateway
    
    JS->>CTRL: submitPayment() with credit card details
    CTRL->>CTRL: execute() & validate form key
    CTRL->>CTRL: prepareVerifyCommandSubject() extracts credit card data
    CTRL->>WPB: Pass enhanced payment profile data
    WPB->>WPB: build() returns array with new credit card fields
    WPB->>PG: Send detailed payment information
Loading

Poem

I’m a rabbit in the code, oh what fun,
Hopping through new fields under the virtual sun.
Credit card details now dance in the flow,
Clean, clear, and structured – watch them grow!
With each key added, my heart hops in delight.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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. (Beta)
  • @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.

@chrismshea
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 14, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@chrismshea
Copy link
Copy Markdown
Owner Author

@coderabbitai full review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Feb 14, 2025

✅ Actions performed

Full review triggered.

Copy link
Copy Markdown

@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: 2

🧹 Nitpick comments (1)
view/frontend/web/js/view/vault/card.js (1)

74-78: Ensure consistency in data handling.

The submitPayment method only includes last_digits and first_digits but not creditcard_type, unlike getPaymentData. Consider adding creditcard_type for consistency.

 submitPayment: function () {
     var cartData = $(this.formSelector).serializeJSON();
     cartData.creditcard_last_digits = this.creditCardLastDigits();
     cartData.creditcard_first_digits = this.creditCardFirstDigits();
+    cartData.creditcard_type = this.selectedCardType();
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 73b76fa and c6cd323.

📒 Files selected for processing (3)
  • Controller/Cards/Save.php (2 hunks)
  • Gateway/Request/WalletPaymentBuilder.php (1 hunks)
  • view/frontend/web/js/view/vault/card.js (2 hunks)
🔇 Additional comments (3)
view/frontend/web/js/view/vault/card.js (1)

22-26: LGTM! Good use of observables for new card properties.

The new properties are properly initialized and made observable.

Controller/Cards/Save.php (2)

93-100: LGTM! Improved readability of form validation conditions.

The multi-line formatting of validation conditions improves code readability.


151-153:

Details

❓ Verification inconclusive

Verify validation coverage for new credit card fields.

The code relies on vaultFormValidator->validate() for field validation. Please ensure that the validator properly handles these new sensitive fields.


🏁 Script executed:

#!/bin/bash
# Check if vaultFormValidator includes validation for new fields
ast-grep --pattern 'class Validator {
  $$$
  validate($profileData) {
    $$$
    PaymentProfileInterface::CREDITCARD_TYPE
    $$$
  }
}'

# Also check for any existing validation patterns
rg -A 5 "CREDITCARD_(TYPE|FIRST_DIGITS|LAST_DIGITS)" --type php

Length of output: 3572


Action Required: Validate New Credit Card Fields in the Validator

The new fields (creditcard_type, creditcard_first_digits, and creditcard_last_digits) are now being passed through the vault form validation, but our search didn’t reveal any explicit validation rules within the validator for these fields. Please double-check that the vaultFormValidator->validate() method adequately covers these sensitive fields. If not, consider adding explicit validation logic to handle them securely.

Comment on lines +21 to +23
PaymentProfileInterface::CREDITCARD_TYPE => $buildSubject['creditcard_type'] ?? null,
PaymentProfileInterface::CREDITCARD_LAST_DIGITS => $buildSubject['creditcard_last_digits'] ?? null,
PaymentProfileInterface::CREDITCARD_FIRST_DIGITS => $buildSubject['creditcard_first_digits'] ?? null,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for sensitive credit card fields.

While using the null coalescing operator is good for safety, consider adding validation for these sensitive credit card fields similar to how other fields are validated. This ensures data integrity and security.

Consider adding validation methods similar to existing ones:

 public function build(array $buildSubject)
 {
     return [
         PaymentProfileInterface::CREDITCARD_MONTH => $this->getCreditCardMonth($buildSubject),
         PaymentProfileInterface::CREDITCARD_YEAR => $this->getCreditCardYear($buildSubject),
-        PaymentProfileInterface::CREDITCARD_TYPE => $buildSubject['creditcard_type'] ?? null,
-        PaymentProfileInterface::CREDITCARD_LAST_DIGITS => $buildSubject['creditcard_last_digits'] ?? null,
-        PaymentProfileInterface::CREDITCARD_FIRST_DIGITS => $buildSubject['creditcard_first_digits'] ?? null,
+        PaymentProfileInterface::CREDITCARD_TYPE => $this->getCreditCardType($buildSubject),
+        PaymentProfileInterface::CREDITCARD_LAST_DIGITS => $this->getCreditCardLastDigits($buildSubject),
+        PaymentProfileInterface::CREDITCARD_FIRST_DIGITS => $this->getCreditCardFirstDigits($buildSubject),
         PaymentProfileInterface::BILLING_ADDRESS => $this->getBillingAddress($buildSubject),

Add these validation methods:

private function getCreditCardType(array $buildSubject)
{
    if (empty($buildSubject['creditcard_type'])) {
        throw new \InvalidArgumentException('Credit card type is not passed.');
    }
    return $buildSubject['creditcard_type'];
}

private function getCreditCardLastDigits(array $buildSubject)
{
    if (empty($buildSubject['creditcard_last_digits'])) {
        throw new \InvalidArgumentException('Credit card last digits are not passed.');
    }
    return $buildSubject['creditcard_last_digits'];
}

private function getCreditCardFirstDigits(array $buildSubject)
{
    if (empty($buildSubject['creditcard_first_digits'])) {
        throw new \InvalidArgumentException('Credit card first digits are not passed.');
    }
    return $buildSubject['creditcard_first_digits'];
}

Comment on lines +67 to +70
'month': this.creditCardExpMonth(),
'creditcard_first_digits': this.creditCardFirstDigits(),
'creditcard_last_digits': this.creditCardLastDigits(),
'creditcard_type': this.selectedCardType(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add validation for credit card data.

Consider adding validation to ensure the credit card data follows expected patterns:

  • First 6 digits should be exactly 6 digits
  • Last 4 digits should be exactly 4 digits
  • Card type should be from a valid set of card types

Add validation before returning the data:

 getPaymentData: function () {
+    if (this.creditCardFirstDigits() && !/^\d{6}$/.test(this.creditCardFirstDigits())) {
+        throw new Error('Invalid credit card first digits');
+    }
+    if (this.creditCardLastDigits() && !/^\d{4}$/.test(this.creditCardLastDigits())) {
+        throw new Error('Invalid credit card last digits');
+    }
     return {
         'first_name': $("#first_name").val(),
         // ... other fields ...
         'creditcard_first_digits': this.creditCardFirstDigits(),
         'creditcard_last_digits': this.creditCardLastDigits(),
         'creditcard_type': this.selectedCardType(),
     };
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
'month': this.creditCardExpMonth(),
'creditcard_first_digits': this.creditCardFirstDigits(),
'creditcard_last_digits': this.creditCardLastDigits(),
'creditcard_type': this.selectedCardType(),
getPaymentData: function () {
if (this.creditCardFirstDigits() && !/^\d{6}$/.test(this.creditCardFirstDigits())) {
throw new Error('Invalid credit card first digits');
}
if (this.creditCardLastDigits() && !/^\d{4}$/.test(this.creditCardLastDigits())) {
throw new Error('Invalid credit card last digits');
}
return {
'month': this.creditCardExpMonth(),
'creditcard_first_digits': this.creditCardFirstDigits(),
'creditcard_last_digits': this.creditCardLastDigits(),
'creditcard_type': this.selectedCardType(),
};
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant