Skip to content
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

feat: add regex for UnionPay and allow card number checking if cardbrand not detected #882

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

aritro2002
Copy link
Contributor

@aritro2002 aritro2002 commented Jan 30, 2025

Type of Change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring
  • Dependency updates
  • Documentation
  • CI/CD

Description

This update enhances our card validation logic by adding regex support for UnionPay and allow card number checking if cardbrand not detected.

The UnionPay regex pattern and pin was derived from the following sources:

  1. https://github.com/validatorjs/validator.js/blob/a1e84761802e050ed5d0e3d138e8f87cc1564860/src/lib/isCreditCard.js#L10
  2. https://en.wikipedia.org/wiki/Payment_card_number
  3. https://www.mystoredemo.io/#/checkout
  4. https://m.unionpayintl.com/wap/en/serviceCenter/cardUsingInstructions/1439.shtml

How did you test it?

I have checked it by running the local React demo app.
Screenshot 2025-01-30 at 11 40 44 AM

If the card brand is not detected but the card number is valid (passes the Luhn test and falls within the valid card number length range), we allow the user to make a payment. We send card_network as null.
Screenshot 2025-01-30 at 2 18 25 PM

I have also changed the default pattern, as many card brands have different CVC and card number lengths.
Screenshot 2025-01-30 at 2 19 51 PM

I have removed checkIsTestCardWildcard, as it is passing luhn test.

Checklist

  • I ran npm run re:build
  • I reviewed submitted code
  • I added unit tests for my changes where possible

@aritro2002 aritro2002 added the Ready for Review PR with label Ready for Review should only be reviewed. label Jan 30, 2025
@aritro2002 aritro2002 self-assigned this Jan 30, 2025
Copy link

Review changes with  SemanticDiff

@aritro2002 aritro2002 added the DO NOT MERGE Use this label if you want your PR to restrict from merging label Jan 30, 2025
@PritishBudhiraja PritishBudhiraja removed the DO NOT MERGE Use this label if you want your PR to restrict from merging label Jan 30, 2025
@aritro2002 aritro2002 changed the title feat: add regex support for UnionPay and unknown card brand feat: add regex for UnionPay and allow card number checking if cardbrand not detected Jan 30, 2025
Comment on lines 154 to 159
if cardBrand != "" {
[("card_network", cardBrand->JSON.Encode.string)]
} else {
[]
[("card_network", JSON.Encode.null)]
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

let cardNetwork = [
  ("card_network", cardBrand != "" ? cardBrand->JSON.Encode.string : JSON.Encode.null),
]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

src/Payment.res Outdated
Comment on lines 229 to 233
if cardBrand != "" {
[("card_network", cardBrand->JSON.Encode.string)]
} else {
[]
[("card_network", JSON.Encode.null)]
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

let cardNetwork = [
  ("card_network", cardBrand != "" ? cardBrand->JSON.Encode.string : JSON.Encode.null),
]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Ready for Review PR with label Ready for Review should only be reviewed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add regex for UnionPay and allow card number checking if cardbrand not detected
3 participants