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

refactor(core): update response for PaymentsDynamicTaxCalculationResponse #5910

Merged
merged 1 commit into from
Sep 16, 2024

Conversation

swangi-kumari
Copy link
Contributor

@swangi-kumari swangi-kumari commented Sep 16, 2024

Type of Change

A new field display_amount has been added to the PaymentsDynamicTaxCalculationResponse. This field holds amounts in the StringMajorUnit format, converted from their respective MinorUnit values. It includes the net_amount, order_tax_amount, and shipping_cost fields, all intended for display in the SDK.

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

Description

Hotfix of #5909

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 Merchant Account
curl --location 'http://localhost:8080/accounts' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data-raw '{
  "merchant_id": "merchant_1725535996",
  "locker_id": "m0010",
  "merchant_name": "NewAge Retailer",
  "merchant_details": {
    "primary_contact_person": "John Test",
    "primary_email": "[email protected]",
    "primary_phone": "sunt laborum",
    "secondary_contact_person": "John Test2",
    "secondary_email": "[email protected]",
    "secondary_phone": "cillum do dolor id",
    "website": "https://www.example.com",
    "about_business": "Online Retail with a wide selection of organic products for North America",
    "address": {
      "line1": "1467",
      "line2": "Harrison Street",
      "line3": "Harrison Street",
      "city": "San Fransico",
      "state": "California",
      "zip": "94122",
      "country": "US"
    }
  },
  "return_url": "https://google.com/success",
  "webhook_details": {
    "webhook_version": "1.0.1",
    "webhook_username": "ekart_retail",
    "webhook_password": "password_ekart@123",
    "payment_created_enabled": true,
    "payment_succeeded_enabled": true,
    "payment_failed_enabled": true
  },
  "sub_merchants_enabled": false,
  "metadata": {
    "city": "NY",
    "unit": "245"
  },
  "primary_business_details": [
    {
      "country": "US",
      "business": "food"
    }
  ]
}'
  1. create Api key
curl --location 'http://localhost:8080/api_keys/merchant_1725532194' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
  "name": "API Key 1",
  "description": null,
  "expiration": "2038-01-19T03:14:08.000Z"
}'

Create a Payment Connector Create of Cybersource for Googlepay

curl --location 'http://localhost:8080/account/merchant_1726144591/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "payment_processor",
    "connector_name": "cybersource",
    
    
      "connector_account_details": {
        "auth_type": "SignatureKey",
        "api_secret": "{{{}}}",
        "api_key": "{{}}",
        "key1": "getin_sandbox"
    },
    "connector_label": "hehe",
    "test_mode": false,
    "disabled": false,
    "payment_methods_enabled": [
        {
            "payment_method": "card",
            "payment_method_types": [
                {
                    "payment_method_type": "credit",
                    "card_networks": [
                        "AmericanExpress",
                        "Discover",
                        "Interac",
                        "JCB",
                        "Mastercard",
                        "Visa",
                        "DinersClub",
                        "UnionPay",
                        "RuPay"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                },
                {
                    "payment_method_type": "debit",
                    "card_networks": [
                        "AmericanExpress",
                        "Discover",
                        "Interac",
                        "JCB",
                        "Mastercard",
                        "Visa",
                        "DinersClub",
                        "UnionPay",
                        "RuPay"
                    ],
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        },
        {
            "payment_method": "wallet",
            "payment_method_types": [
                {
                    "payment_method_type": "google_pay",
                    "payment_experience": "invoke_sdk_client",
                    "card_networks": null,
                    "accepted_currencies": null,
                    "accepted_countries": null,
                    "minimum_amount": -1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }]
        }
    ],
    "metadata": {
      "google_pay": {
            "merchant_info": {
                "merchant_id": "mpptiscity1",
                "merchant_name": "mpptiscity1"
            },
            "allowed_payment_methods": [
                {
                    "type": "CARD",
                    "parameters": {
                        "allowed_auth_methods": [
                            "PAN_ONLY",
                            "CRYPTOGRAM_3DS"
                        ],
                        "allowed_card_networks": [
                            "AMEX",
                            "DISCOVER",
                            "INTERAC",
                            "JCB",
                            "MASTERCARD",
                            "VISA"
                        ]
                    },
                    "tokenization_specification": {
                        "type": "PAYMENT_GATEWAY",
                        "parameters": {
                            "gateway": "cybersource",
                            "gateway_merchant_id": "mpptiscity1"
                        }
                    }
                }
            ]
        }
    }
}'

4.Payment Connector Create for TaxJar

{
    "connector_type": "tax_processor",
    "connector_name": "taxjar",
    "connector_account_details": {
        "auth_type": "HeaderKey",
        "api_key": "_________" 
    },

    "test_mode": false,
    "disabled": false,
     "payment_methods_enabled": [
        {
            "payment_method": "upi",
            "payment_method_types": [
                {
                    "payment_method_type": "upi_collect",
                    "payment_experience": "redirect_to_url",
                    "accepted_currencies": {
                        "type" : "enable_only",
                        "list": ["INR"]
                    },
                    "accepted_countries": {
                        "type" : "enable_only",
                        "list": ["IN"]
                    },
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true
                }
            ]
        }

    ],
    "metadata": {
        "city": "NY",
        "unit": "245"
    },
    "connector_webhook_details": {
        "merchant_secret": "dce1d767-7c28-429c-b0fe-9e0b9e91f962"
    },
    "business_country": "US",
    "business_label": "food"
}
  1. Payment Create
{
    "amount": 2000,
    "currency": "USD",
    "confirm": false,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "customer_id": "StripeCustomer",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://google.com",
    "shipping_cost": 500,
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "DE",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "[email protected]"
    },
    "order_details": [
        {
            "product_name": "Apple iphone 15",
            "quantity": 1,
            "amount": 2000,
            "account_name": "transaction_processing",
            "product_id": "1",
            "product_tax_code": "23"
        }
    ],
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}
  1. Update business_profile
curl --location 'http://localhost:8080/account/merchant_1725543554/business_profile/{pro____}' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "tax_connector_id": "{mca_____}",
    "is_tax_connector_enabled": true
}'
  1. Create session Token
curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'api-key: pk_dev_85f56ada7b2f4ffab21fe0dc214a0d75' \
--data '{
    "payment_id": "pay_PNd6JEhLnwe6q7K5LKJ0",
    "wallets": [],
    "client_secret": "pay_PNd6JEhLnwe6q7K5LKJ0_secret_BPT9z1RBmCFQJVvAGJJ2"
}'
  1. List Payment Methods
curl --location 'http://localhost:8080/account/payment_methods?client_secret={}' \
--header 'Accept: application/json' \
--header 'api-key: {pk_dev_}'
curl --location 'http://localhost:8080/payments/pay_PNd6JEhLnwe6q7K5LKJ0/calculate_tax' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: {pk_dev}' \
--data-raw '{
    "client_secret": "{}",
    "shipping": {
        "address": {
            "line1": "1335 E 103rd St",
            "line2": " Street",
            "line3": " Street",
            "city": "Los Angeles",
            "state": "California",
            "zip": "90002",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "[email protected]"
    },
    "payment_method_type" : "klarna"
}'

Response

{
    "payment_id": "pay_D1KwskbRrHs2wZcXzi6w",
    "net_amount": 4190,
    "order_tax_amount": 190,
    "shipping_cost": 1000,
    "display_amount": {
        "net_amount": "41.90",
        "order_tax_amount": "1.90",
        "shipping_cost": "10.00"
    }
}

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

@swangi-kumari swangi-kumari requested review from a team as code owners September 16, 2024 15:09
Copy link

semanticdiff-com bot commented Sep 16, 2024

Review changes with SemanticDiff.

Analyzed 6 of 6 files.

Overall, the semantic diff is 9% smaller than the GitHub diff.

Filename Status
✔️ crates/router/src/core/payments/transformers.rs 12.5% smaller
✔️ crates/openapi/src/openapi.rs Analyzed
✔️ crates/openapi/src/openapi_v2.rs Analyzed
✔️ crates/api_models/src/payments.rs Analyzed
✔️ api-reference-v2/openapi_spec.json 7.14% smaller
✔️ api-reference/openapi_spec.json 7.14% smaller

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Sep 16, 2024
@swangi-kumari swangi-kumari self-assigned this Sep 16, 2024
@swangi-kumari swangi-kumari added A-core Area: Core flows C-refactor Category: Refactor labels Sep 16, 2024
@likhinbopanna likhinbopanna merged commit f462c73 into hotfix-2024.09.13.0 Sep 16, 2024
29 of 30 checks passed
@likhinbopanna likhinbopanna deleted the session-update-res branch September 16, 2024 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows C-refactor Category: Refactor M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants