Skip to content

fix(payment-methods): add ph code validation in customer create flow - #13752

Open
prasunna09 wants to merge 1 commit into
mainfrom
fix-phone-country-code-500-error
Open

fix(payment-methods): add ph code validation in customer create flow#13752
prasunna09 wants to merge 1 commit into
mainfrom
fix-phone-country-code-500-error

Conversation

@prasunna09

@prasunna09 prasunna09 commented Aug 18, 2026

Copy link
Copy Markdown
Contributor

Type of Change

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

Description

Additional Changes

  • This PR modifies the API contract
  • This PR modifies the database schema
  • This PR modifies application configuration/environment variables

Motivation and Context

How did you test it?

Setup:

  1. Create merchant account
  2. Create API key for that merchant

Test 1 — valid phone_country_code ("+1"):

curl -s -X POST http://localhost:8080/customers \
  -H "Content-Type: application/json" \
  -H "api-key: dev_PYPUYZwF1HNg2gZeMYUy4qINUEKVZvJjNRK9OxqmIK67k84vnvTNGQS71Tty6kAw" \
  -d '{
    "name": "Jon Test",
    "email": "jontest@example.com",
    "phone": "9123456789",
    "phone_country_code": "+1"
  }'

HTTP/1.1 200 OK

{"customer_id":"cus_6dxPT61GjFgDhhs0caJ0","name":"Jon
Test","email":"jontest@example.com","phone":"9123456789","phocription":null,"address":null,"created_at":"2026-08-18T18:57:39.168Z","metadata":null,"default_payment_method_id":null,"tax_registration_id":null,"document_details":null}

Test 2 — invalid phone_country_code ("United States", the exact value from the bug report):

curl -s -X POST http://localhost:8080/customers \
  -H "Content-Type: application/json" \
  -H "api-key: dev_PYPUYZwF1HNg2gZeMYUy4qINUEKVZvJjNRK9OxqmIK
  -d '{
    "name": "Jon Test 2",
    "email": "jontest2@example.com",
    "phone": "9123456789",
    "phone_country_code": "United States"
  }'

HTTP/1.1 400 Bad Request (previously 500)

{"error":{"type":"invalid_request","message":"Invalid value p must be a valid country calling code (e.g. \"+1\"), got\"United States\"","code":"IR_07"}}

Confirmed via the server log too — the invalid request is handled as a normal BadRequest, not a panic or unhandled DB error.

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code
  • I added unit tests for my changes where possible

@prasunna09 prasunna09 self-assigned this Aug 18, 2026
@prasunna09
prasunna09 requested review from a team as code owners August 18, 2026 09:05
@semanticdiff-com

semanticdiff-com Bot commented Aug 18, 2026

Copy link
Copy Markdown

Review changes with  SemanticDiff

Changed Files
File Status
  crates/common_utils/src/validation.rs  0% smaller
  crates/router/src/core/customers.rs  0% smaller

@prasunna09 prasunna09 added S-test-ready Status: This PR is ready for cypress-tests C-bug Category: Bug A-customers Area: Customer Flow/API's labels Aug 18, 2026
@github-actions github-actions Bot removed the S-test-ready Status: This PR is ready for cypress-tests label Aug 18, 2026

/// Maximum length allowed for a phone country (calling) code, matching the `VARCHAR(8)`
/// column used to store it.
pub const MAX_PHONE_COUNTRY_CODE_LENGTH: usize = 8;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should this go to consts.rs ?

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

Labels

A-customers Area: Customer Flow/API's C-bug Category: Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants