Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

feat(core): add support for payment links localization #5530

Merged
merged 18 commits into from
Aug 7, 2024

Conversation

srujanchikke
Copy link
Contributor

@srujanchikke srujanchikke commented Aug 5, 2024

Type of Change

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

Description

Add support for payment link localization in backend.

Additional Changes

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

Motivation and Context

This pr also passed locale from backend to SDK from Accept-Language headers. Static strings in javascript are declared in key value pairs in js, Using locale we transform the language.

The available languages in the locales constant are:

  1. English (en)
  2. Hebrew (he)
  3. French (fr)
  4. British English (en_GB)
  5. Arabic (ar)
  6. Japanese (ja)
  7. German (de)
  8. Belgian French (fr_BE)
  9. Spanish (es)
  10. Catalan (ca)
  11. Portuguese (pt)
  12. Italian (it)
  13. Polish (pl)
  14. Dutch (nl)
  15. Swedish (sv)
  16. Russian (ru)
  17. Chinese (zh)

How did you test it?

Create a payment link - you can choose any language from above, pass short form any language. below i choose zh(chinese).
Step 1 :

curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Accept-Language: zh' \
--header 'api-key: snd_efbc4c35649f45b2ac283bb2c1609730' \
--data-raw '{
    "amount":5000,
    "currency": "USD",
    "confirm": false,
    "payment_link" : true,
    "capture_on": "2029-09-10T10:11:12Z",
    "amount_to_capture": 5000,
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "three_ds",
    "return_url": "https://google.com",
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "03",
            "card_exp_year": "25",
            "card_holder_name": "chikke.srujan@juspay.in",
            "card_cvc": "737",
            "card_network": "Visa",
            "card_type": null,
            "card_issuing_country": null,
            "bank_code": null,
            "nick_name" : "srujan"
        },
        "billing": {
            "address": {
                "line1": "1467",
                "line2": "CA",
                "line3": "CA",
                "city": "San Fransico",
                "state": "California",
                "zip": "94122",
                "country": "NL",
                "first_name": "joseph",
                "last_name": "Doe"
            },
            "phone": {
                "number": "8056594427",
                "country_code": "+91"
            }
        }
    },
    "billing": {
            "address": {
                "line1": "1467",
                "line2": "CA",
                "line3": "CA",
                "city": "San Fransico",
                "state": "California",
                "zip": "94122",
                "country": "NL",
                "first_name": "joseph",
                "last_name": "Doe"
            },
            "phone": {
                "number": "8056594427",
                "country_code": "+91"
            }
        },
    "payment_method": "card",
    "payment_method_type" :"credit",
    "profile_id" : "pro_pzQKs5ECdVLWT2anGSz8",
    "customer_acceptance": {
        "acceptance_type": "online",
        "accepted_at": "2026-07-04T10:59:42.232Z",
        "online": {
            "ip_address": null,
            "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0"
        }
    },
    "browser_info": {
        "color_depth": 24,
        "java_enabled": true,
        "java_script_enabled": true,
        "language": "en-GB",
        "screen_height": 720,
        "screen_width": 1280,
        "time_zone": -330,
        "ip_address": "208.127.127.193",
        "accept_header": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "user_agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0"
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "CA",
            "line3": "CA",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "NL",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        }
    },
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    
    "order_details": [
        {
            "product_name": "Tea",
            "quantity": 1,
            "amount": 110,
            "product_img_link": "https://thumbs.dreamstime.com/b/indian-tea-spices-masala-chai-33827904.jpg"
        },
        {
            "product_name": "Tea",
            "quantity": 1,
            "amount": 110,
            "product_img_link": "https://thumbs.dreamstime.com/b/indian-tea-spices-masala-chai-33827904.jpg"
        },
        {
            "product_name": "Tea",
            "quantity": 1,
            "amount": 110,
            "product_img_link": "https://thumbs.dreamstime.com/b/indian-tea-spices-masala-chai-33827904.jpg"
        }
    ]
}'

after redirection everything should be chinese in payment link page.

Screenshot 2024-08-06 at 1 58 23 PM

Failure page :

Screenshot 2024-08-06 at 2 08 10 PM

Success page :
Screenshot 2024-08-06 at 4 51 40 PM

Test Case 2: Failed case , pass invalid Aceept-Language in header, it shoulb be able to default it to english.

Test Case 3: Enter pay now without redirecting after hitting payment link , error message should be in Accept-language

Screenshot 2024-08-06 at 2 10 42 PM
Test case 4: Test the same for secure payment links

Screenshot 2024-08-07 at 4 49 17 PM Screenshot 2024-08-07 at 4 49 30 PM

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

@srujanchikke srujanchikke added the A-core Area: Core flows label Aug 5, 2024
@srujanchikke srujanchikke self-assigned this Aug 5, 2024
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Aug 6, 2024
@srujanchikke srujanchikke marked this pull request as ready for review August 6, 2024 08:17
@srujanchikke srujanchikke requested review from a team as code owners August 6, 2024 08:17
@srujanchikke srujanchikke requested a review from sahkal August 6, 2024 08:17
@srujanchikke srujanchikke requested a review from a team as a code owner August 6, 2024 08:22
@srujanchikke srujanchikke added C-feature Category: Feature request or enhancement S-waiting-on-review Status: This PR has been implemented and needs to be reviewed labels Aug 6, 2024
.await?;
let locale = request_headers
.get(header::ACCEPT_LANGUAGE)
.and_then(|header_value| header_value.to_str().ok())
Copy link
Contributor

Choose a reason for hiding this comment

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

can we log the error, instead of ignoring it!

Comment on lines 63 to 65
.get(actix_web::http::header::ACCEPT_LANGUAGE)
.and_then(|header_value| header_value.to_str().ok())
.map(|str| str.to_owned());
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

@@ -92,6 +99,7 @@ pub async fn initiate_secure_payment_link(
let payload = api_models::payments::PaymentLinkInitiateRequest {
payment_id,
merchant_id: merchant_id.clone(),
locale: None,
Copy link
Contributor

Choose a reason for hiding this comment

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

is the locale only for open payment links, and not iframe embeded links?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PaymentLinkRequest is used for both payment links and secure payment links. In the case of payment links and status routes, we pass the locale to the flow. However, secure links already pass headers to the initiate_secure_payment_link_flow function. So I was consuming the locale from headers in secure_payment_link, and in all other cases, I am not passing headers to flows; instead, I am directly passing the locale.

Copy link
Contributor

Choose a reason for hiding this comment

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

can we unify it, it looks confusing at first glance!

Comment on lines 178 to 181
.get(actix_web::http::header::ACCEPT_LANGUAGE)
.and_then(|header_value| header_value.to_str().ok())
.map(|str| str.to_owned());
let payload = api_models::payments::PaymentLinkInitiateRequest {
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

sahkal
sahkal previously approved these changes Aug 7, 2024
@@ -92,6 +99,7 @@ pub async fn initiate_secure_payment_link(
let payload = api_models::payments::PaymentLinkInitiateRequest {
payment_id,
merchant_id: merchant_id.clone(),
locale: None,
Copy link
Contributor

Choose a reason for hiding this comment

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

can we unify it, it looks confusing at first glance!

@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Aug 7, 2024
@srujanchikke srujanchikke requested a review from a team as a code owner August 7, 2024 10:37
lsampras
lsampras previously approved these changes Aug 7, 2024
Copy link
Member

@lsampras lsampras left a comment

Choose a reason for hiding this comment

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

rest looks good

@@ -64,6 +65,7 @@ pub async fn form_payment_link_data(
key_store: domain::MerchantKeyStore,
merchant_id: common_utils::id_type::MerchantId,
payment_id: String,
locale: Option<String>,
Copy link
Member

Choose a reason for hiding this comment

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

this could be an enum for validation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't want to throw an error incase if client passes invalid enum of accept headers, that's the reason it was Option.

@srujanchikke srujanchikke removed the request for review from a team August 7, 2024 10:59
@srujanchikke srujanchikke removed the request for review from SanchithHegde August 7, 2024 11:10
@likhinbopanna likhinbopanna enabled auto-merge August 7, 2024 11:30
@likhinbopanna likhinbopanna added this pull request to the merge queue Aug 7, 2024
Merged via the queue into main with commit 3604b4f Aug 7, 2024
26 checks passed
@likhinbopanna likhinbopanna deleted the localization_for_payment_links branch August 7, 2024 12:34
pixincreate added a commit that referenced this pull request Aug 7, 2024
…e-connector-label-cypress

* 'main' of github.com:juspay/hyperswitch:
  feat(core): add support for payment links localization (#5530)
  refactor(router): refactor `merchant_connector_account` retrieve and delete v2 apis (#5528)
  feat(cypress): add core flow tests (#5546)
  feat(cypress): add mandates and refunds variation cases (#5513)
  feat(cypress): add configs for not overriding screenshots (#5524)
  refactor(business_profile): use concrete types for JSON fields (#5531)
  feat(customer_v2):  add customer create v2 endpoint  (#5444)
  refactor(connector): added amount conversion framework for Mifinity (#5460)
  refactor(connector): added amount conversion framework for Boku (#5459)
  chore(version): 2024.08.07.0
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Aug 7, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-core Area: Core flows C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants