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(connector): added amount conversion framework for klarna and change type of amount to MinorUnit for OrderDetailsWithAmount #4979

Merged
merged 20 commits into from
Oct 25, 2024

Conversation

KiranKBR
Copy link
Contributor

@KiranKBR KiranKBR commented Jun 12, 2024

Type of Change

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

Description

  • added amount conversion framework for klarna
  • For struct OrderDetailsWithAmount, changed the type of amount from i64 to MinorUnit
  • Made unit_price as Option, for TaxJar connector.

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 Merchant Account
  2. Create API Key
  3. Create MCA for Klarna|
curl --location 'http://localhost:8080/account/merchant_1729494178/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "payment_processor",
    "connector_name": "klarna",
    "connector_account_details": {
        "auth_type": "BodyKey",
        "api_key": "___", 
        "key1":  "_____"   
        
    },
    "test_mode": true,
    "disabled": false,
    "payment_methods_enabled": [
        {
            "payment_method": "pay_later",
            "payment_method_types": [
                {
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true,
                    "payment_experience": "invoke_sdk_client",
                    "payment_method_type": "klarna"
                }
            ]
        }
    ],
    "metadata": {
        "klarna_region": "NorthAmerica"
    },
    "business_country": "US",
    "business_label": "food"
}
'
  1. Create Tax Jar
curl --location 'http://localhost:8080/account/merchant_1729494178/connectors' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: test_admin' \
--data '{
    "connector_type": "tax_processor",
    "connector_name": "taxjar",
    "connector_account_details": {
        "auth_type": "HeaderKey",
        "api_key": "____" 
    },

    "test_mode": false,
    "disabled": false,

    "metadata": {
        "city": "NY",
        "unit": "245"
    },
    "business_country": "US",
    "business_label": "food"
}'
  1. Create a Payment
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: _____' \
--data-raw '{
    "amount": 3000,
    "currency": "USD",
    "confirm": false,
    "capture_method": "manual",
    "capture_on": "2022-09-10T10:11:12Z",
    "customer_id": "StripeCustomer",
    "email": "guest@example.com",
    "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",
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "joseph",
            "last_name": "Doe"
        },
        "phone": {
            "number": "8056594427",
            "country_code": "+91"
        },
        "email": "swangi@gmail.com"
    },
    "order_details": [ 
        {
            "product_name": "Apple iphone 15",
            "quantity": 1,
            "amount": 1000,
            "product_tax_code": "23"
        },
        {
            "product_name": "Apple iphone 15",
            "quantity": 1,
            "amount": 2000,
            "minor_amount" : 2000,
            "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. Session Token
curl --location 'http://localhost:8080/payments/session_tokens' \
--header 'Content-Type: application/json' \
--header 'api-key: pk_dev_28ab740febb44c1eb1c3176698abd56f' \
--data '{
    "payment_id": "pay_PnNHfYis89QYkvY7sFcX",
    "wallets": [],
    "client_secret": "__"
}'
  1. List Payment Methods for merchant
curl --location 'http://localhost:8080/account/payment_methods?client_secret=pay_PnNHfYis89QYkvY7sFcX_secret_drsmJqh2E2sZM7UuIVGd' \
--header 'Accept: application/json' \
--header 'api-key: ___'
  1. Calculate Tax
curl --location 'http://localhost:8080/payments/pay_PnNHfYis89QYkvY7sFcX/calculate_tax' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_28ab740febb44c1eb1c3176698abd56f' \
--data-raw '{
    "client_secret": "pay_PnNHfYis89QYkvY7sFcX_secret_drsmJqh2E2sZM7UuIVGd",
    "shipping": {
        "address": {
            "line1": "1335",
            "line2": "E 103rd St",
            
            "city": "Los Angeles",
            "state": "California",
            "zip": "90002",
            "country": "US",
            "first_name": "Test",
            "last_name": "Person-us"
        },
        "phone": {
            "number": "5551234",
            "country_code": "+1"
        },
        "email": "generated_email_us+1715685671426@example.com"
    },
    "payment_method_type": "klarna",
    
    "session_id": "feb4fc0d-4196-6856-8d02-eb999d6b971a"
}
'

Response

{
    "payment_id": "pay_PnNHfYis89QYkvY7sFcX",
    "net_amount": 3190,
    "order_tax_amount": 190,
    "shipping_cost": null,
    "display_amount": {
        "net_amount": "31.90",
        "order_tax_amount": "1.90",
        "shipping_cost": null
    }
}

Note:

  • To test end to end flow please test Klarna payments flow via sdk.
  • We can not test TaxCalculation for Klarna via sdk as SessionUpdate flow for klarna is not yet implemented.

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

@KiranKBR KiranKBR requested review from a team as code owners June 12, 2024 18:51
@KiranKBR KiranKBR self-assigned this Jun 13, 2024
@KiranKBR KiranKBR added the C-refactor Category: Refactor label Jun 13, 2024
@KiranKBR KiranKBR changed the title do-amount-conversion-for-klarna refactor(connector): added amount conversion framework for klarna Jun 13, 2024
Base automatically changed from 5188-amount-conversion-do-amount-conversion-for-iatapay to main July 1, 2024 11:36
@KiranKBR KiranKBR requested review from a team as code owners July 1, 2024 11:36
@KiranKBR KiranKBR force-pushed the do-amount-conversion-for-klarna branch from 60e988f to 19d54b0 Compare July 17, 2024 13:10
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jul 17, 2024
@KiranKBR KiranKBR removed request for a team July 25, 2024 06:01
@KiranKBR KiranKBR force-pushed the do-amount-conversion-for-klarna branch from 19a9185 to bc0a254 Compare July 25, 2024 11:26
@hyperswitch-bot hyperswitch-bot bot added M-api-contract-changes Metadata: This PR involves API contract changes and removed M-api-contract-changes Metadata: This PR involves API contract changes labels Jul 25, 2024
@KiranKBR KiranKBR force-pushed the do-amount-conversion-for-klarna branch from c882e54 to 5c2ac69 Compare July 25, 2024 11:56
@hyperswitch-bot hyperswitch-bot bot removed the M-api-contract-changes Metadata: This PR involves API contract changes label Jul 25, 2024
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Jul 25, 2024
@KiranKBR KiranKBR marked this pull request as draft August 7, 2024 21:40
@sahkal sahkal requested a review from jarnura October 22, 2024 06:05
}
}

impl Sum for MinorUnit {
Copy link
Contributor

Choose a reason for hiding this comment

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

add is already there why is Sum needed?

Copy link
Contributor

Choose a reason for hiding this comment

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

.sum() function is required to accumulate the elements of an iterator for OrderDetails.

sahkal
sahkal previously approved these changes Oct 23, 2024
@swangi-kumari swangi-kumari changed the title refactor(connector): added amount conversion framework for klarna refactor(connector): added amount conversion framework for klarna and change type of amount to MinorUnit for OrderDetailsWithAmount Oct 24, 2024
@swangi-kumari swangi-kumari requested review from a team as code owners October 24, 2024 13:38
@swangi-kumari swangi-kumari force-pushed the do-amount-conversion-for-klarna branch from c93a383 to 1adb70a Compare October 24, 2024 13:41
@swangi-kumari swangi-kumari removed request for a team October 24, 2024 14:20
@likhinbopanna likhinbopanna added this pull request to the merge queue Oct 25, 2024
Merged via the queue into main with commit 2807622 Oct 25, 2024
17 checks passed
@likhinbopanna likhinbopanna deleted the do-amount-conversion-for-klarna branch October 25, 2024 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.

6 participants