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(payments): [Payment links] add showCardFormByDefault config for payment links #6663

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

Conversation

cookieg13
Copy link
Contributor

@cookieg13 cookieg13 commented Nov 26, 2024

Type of Change

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

Description

Add showCardFormByDefault config for payment links.
https://docs.hyperswitch.io/explore-hyperswitch/merchant-controls/integration-guide/web/customization#show-card-form-by-default

Functionality:
(By default showCardFormByDefault is true.)
When in PML card is not present + showCardFormByDefault=false, then card form is hidden from the UI. In all other cases card form is shown in UI.

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?

1. Create a connector with only wallets in `payment_methods_enabled` (Expand to see details)
"payment_methods_enabled": [
       {
           "payment_method": "wallet",
           "payment_method_types": [
               {
                   "payment_method_type": "paypal",
                   "payment_experience": "redirect_to_url",
                   "minimum_amount": 1,
                   "maximum_amount": 68607706,
                   "recurring_enabled": true,
                   "installment_payment_enabled": false
               },
               {
                   "payment_method_type": "google_pay",
                   "payment_experience": "redirect_to_url",
                   "card_networks": null,
                   "accepted_currencies": null,
                   "accepted_countries": null,
                   "minimum_amount": 0,
                   "maximum_amount": 68607706,
                   "recurring_enabled": true,
                   "installment_payment_enabled": false
               },
               {
                   "payment_method_type": "apple_pay",
                   "payment_experience": "invoke_sdk_client",
                   "minimum_amount": 1,
                   "maximum_amount": 68607706,
                   "recurring_enabled": true,
                   "installment_payment_enabled": true
               }
           ]
       }
   ]
2. Update `allowed_domains` in business profile (Expand to see details)
curl --location 'http://localhost:8080/account/merchant_1721984694/business_profile/pro_oXHnmgfZSnfe92PvodqP' \
--header 'Content-Type: application/json' \
--header 'api-key: test_admin' \
--data '{
    "payment_link_config": {
        "allowed_domains": [
            "*"
        ],
        "enabled_saved_payment_method": true,
        "hide_card_nickname_field" : true
    }
}'

3. Create a payment link with `show_card_form_by_default = false` (Expand to see details)
curl --location --request POST 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_pSNneiwGWnPCMmVN3DgFWEKnQsirXbr4HDO5xkNSidBhPg3MnEa3wHyXyhngDsbS' \
--data-raw '{
    "amount": 100,
    "currency": "USD",
    "payment_link": true,
    "connector": [
        "novalnet"
    ],
    "session_expiry": 1000000,
    "return_url": "http://127.0.0.1:5500/src/pl_iframe.html",
    "payment_link_config": {
        "theme": "#14356f",
        "logo": "https://logosandtypes.com/wp-content/uploads/2020/08/zurich.svg",
        "seller_name": "Zurich Inc.",
        "show_card_form_by_default": false
    }
}'

Response of /payments
{ "payment_id": "pay_FmjZdNGEcf4Vkttj9wgF", "merchant_id": "merchant_1732539663", "status": "requires_payment_method", "amount": 100, "net_amount": 100, "shipping_cost": null, "amount_capturable": 100, "amount_received": null, "connector": null, "client_secret": "pay_FmjZdNGEcf4Vkttj9wgF_secret_rMdkJoz3AqMb9E7lD3JC", "created": "2024-11-26T09:52:37.464Z", "currency": "USD", "customer_id": null, "customer": null, "description": null, "refunds": null, "disputes": null, "mandate_id": null, "mandate_data": null, "setup_future_usage": null, "off_session": null, "capture_on": null, "capture_method": null, "payment_method": null, "payment_method_data": null, "payment_token": null, "shipping": null, "billing": null, "order_details": null, "email": null, "name": null, "phone": null, "return_url": "http://127.0.0.1:5500/src/pl_iframe.html", "authentication_type": null, "statement_descriptor_name": null, "statement_descriptor_suffix": null, "next_action": null, "cancellation_reason": null, "error_code": null, "error_message": null, "unified_code": null, "unified_message": null, "payment_experience": null, "payment_method_type": null, "connector_label": null, "business_country": null, "business_label": "default", "business_sub_label": null, "allowed_payment_method_types": null, "ephemeral_key": null, "manual_retry_allowed": null, "connector_transaction_id": null, "frm_message": null, "metadata": null, "connector_metadata": null, "feature_metadata": null, "reference_id": null, "payment_link": { "link": "http://localhost:8080/payment_link/merchant_1732539663/pay_FmjZdNGEcf4Vkttj9wgF?locale=en", "secure_link": "http://localhost:8080/payment_link/s/merchant_1732539663/pay_FmjZdNGEcf4Vkttj9wgF?locale=en", "payment_link_id": "plink_EYi1uYFwZ0TBAQcJKVDH" }, "profile_id": "pro_WY0cgeQScEEXmVNzGWqV", "surcharge_details": null, "attempt_count": 1, "merchant_decision": null, "merchant_connector_id": null, "incremental_authorization_allowed": null, "authorization_count": null, "incremental_authorizations": null, "external_authentication_details": null, "external_3ds_authentication_attempted": false, "expires_on": "2024-12-07T23:39:17.336Z", "fingerprint": null, "browser_info": null, "payment_method_id": null, "payment_method_status": null, "updated": "2024-11-26T09:52:37.572Z", "charges": null, "frm_metadata": null, "merchant_order_reference_id": null, "order_tax_amount": null, "connector_mandate_id": null }

4. Screenshots (Expand to see details) Open the secure payment link (`secure_link` in API response) in an iframe for validating the functionality. For checking payment_link simply click on the payment_link (`payment_link` in API response)

Screenshot for payment link
Screenshot 2024-11-26 at 15 36 03

Screenshot for secured payment link
Screenshot 2024-11-26 at 15 34 49

Expected Behavior: Since PML consists of only wallets and not cards, and show_card_form_by_default is false the card form is not shown by default

5. Create a payment link with `show_card_form_by_default = true` (Expand to see details)
curl --location --request POST 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_pSNneiwGWnPCMmVN3DgFWEKnQsirXbr4HDO5xkNSidBhPg3MnEa3wHyXyhngDsbS' \
--data-raw '{
    "amount": 100,
    "currency": "USD",
    "payment_link": true,
    "connector": [
        "novalnet"
    ],
    "session_expiry": 1000000,
    "return_url": "http://127.0.0.1:5500/src/pl_iframe.html",
    "payment_link_config": {
        "theme": "#14356f",
        "logo": "https://logosandtypes.com/wp-content/uploads/2020/08/zurich.svg",
        "seller_name": "Zurich Inc.",
        "show_card_form_by_default": true
    }
}'

Response of /payments
{ "payment_id": "pay_t5OgMwdSEHCg0JEgaKyM", "merchant_id": "merchant_1732616040", "status": "requires_payment_method", "amount": 100, "net_amount": 100, "shipping_cost": null, "amount_capturable": 100, "amount_received": null, "connector": null, "client_secret": "pay_t5OgMwdSEHCg0JEgaKyM_secret_36NNyT20Ol3HOs9qLghA", "created": "2024-11-26T10:14:46.689Z", "currency": "USD", "customer_id": null, "customer": null, "description": null, "refunds": null, "disputes": null, "mandate_id": null, "mandate_data": null, "setup_future_usage": null, "off_session": null, "capture_on": null, "capture_method": null, "payment_method": null, "payment_method_data": null, "payment_token": null, "shipping": null, "billing": null, "order_details": null, "email": null, "name": null, "phone": null, "return_url": "http://127.0.0.1:5500/src/pl_iframe.html", "authentication_type": null, "statement_descriptor_name": null, "statement_descriptor_suffix": null, "next_action": null, "cancellation_reason": null, "error_code": null, "error_message": null, "unified_code": null, "unified_message": null, "payment_experience": null, "payment_method_type": null, "connector_label": null, "business_country": null, "business_label": "default", "business_sub_label": null, "allowed_payment_method_types": null, "ephemeral_key": null, "manual_retry_allowed": null, "connector_transaction_id": null, "frm_message": null, "metadata": null, "connector_metadata": null, "feature_metadata": null, "reference_id": null, "payment_link": { "link": "http://localhost:8080/payment_link/merchant_1732616040/pay_t5OgMwdSEHCg0JEgaKyM?locale=en", "secure_link": "http://localhost:8080/payment_link/s/merchant_1732616040/pay_t5OgMwdSEHCg0JEgaKyM?locale=en", "payment_link_id": "plink_py51CKCnCY4qvK98SDMu" }, "profile_id": "pro_ElaKfgKnFwT7Eo348xeM", "surcharge_details": null, "attempt_count": 1, "merchant_decision": null, "merchant_connector_id": null, "incremental_authorization_allowed": null, "authorization_count": null, "incremental_authorizations": null, "external_authentication_details": null, "external_3ds_authentication_attempted": false, "expires_on": "2024-12-08T00:01:26.671Z", "fingerprint": null, "browser_info": null, "payment_method_id": null, "payment_method_status": null, "updated": "2024-11-26T10:14:46.743Z", "charges": null, "frm_metadata": null, "merchant_order_reference_id": null, "order_tax_amount": null, "connector_mandate_id": null }

6. Screenshots (Expand to see details) Open the secure payment link (`secure_link` in API response) in an iframe for validating the functionality. For checking payment_link simply click on the payment_link (`payment_link` in API response)

Screenshot for payment link
Screenshot 2024-11-26 at 15 45 06

Screenshot for secured payment link
Screenshot 2024-11-26 at 15 48 32

Expected Behavior: Since PML consists of only wallets and not cards, and show_card_form_by_default is true the card form is shown by default

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

@cookieg13 cookieg13 requested review from a team as code owners November 26, 2024 10:19
@cookieg13 cookieg13 self-assigned this Nov 26, 2024
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Nov 26, 2024
kashif-m
kashif-m previously approved these changes Nov 26, 2024
@@ -153,6 +153,9 @@ pub const DEFAULT_ALLOWED_DOMAINS: Option<HashSet<String>> = None;
/// Default hide card nickname field
pub const DEFAULT_HIDE_CARD_NICKNAME_FIELD: bool = false;

/// Show card form by default for payment links
pub const DEFAULT_SHOW_CARD_FORM: bool = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

This is true, where as in api_models default is 'false'!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes my bad, made the default value 'true' everywhere now

@@ -2673,6 +2673,9 @@ pub struct PaymentLinkConfigRequest {
/// Hide card nickname field option for payment link
#[schema(default = false, example = true)]
pub hide_card_nickname_field: Option<bool>,
/// Show card form by default for payment link
#[schema(default = false, example = true)]
Copy link
Contributor

Choose a reason for hiding this comment

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

+1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants