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): [Klarna] Refactor Authorize call and configs for prod #4750

Merged
merged 10 commits into from
May 29, 2024

Conversation

swangi-kumari
Copy link
Contributor

@swangi-kumari swangi-kumari commented May 23, 2024

Type of Change

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

Description

  1. Refactor Authorize Call
  2. Add support for configurable region_based_endpoint while creating mca
  3. Refactor configs for prod

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
{
  "merchant_id": "merchant_{{$timestamp}}",
  "locker_id": "m0010",
  "merchant_name": "NewAge Retailer",
  "merchant_details": {
    "primary_contact_person": "John Test",
    "primary_email": "JohnTest@test.com",
    "primary_phone": "sunt laborum",
    "secondary_contact_person": "John Test2",
    "secondary_email": "JohnTest2@test.com",
    "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
{
  "name": "API Key 1",
  "description": null,
  "expiration": "2038-01-19T03:14:08.000Z"
}

  1. Create MCA
{
    "connector_type": "fiz_operations",
    "connector_name": "klarna",
    "connector_account_details": {
        "auth_type": "BodyKey",
        "api_key": "Password",
        "key1": "username"
    },
    "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"
                }
            ]
        },
        {
            "payment_method": "pay_later",
            "payment_method_types": [
                {
                    "minimum_amount": 1,
                    "maximum_amount": 68607706,
                    "recurring_enabled": true,
                    "installment_payment_enabled": true,
                    "payment_experience": "redirect_to_url",
                    "payment_method_type": "klarna"
                }
            ]
        }
    ],
    "metadata": {
        "city": "NY",
        "unit": "245",
        "klarna_region": "NorthAmerica"
    }
}

In metadata try 3 values and do a Klarna Payment via SDK for Klarna Connector for each klarna_region
i.

"metadata": {
       "city": "NY",
       "unit": "245",
       "klarna_region": "Europe"
   }

ii.

"metadata": {
       "city": "NY",
       "unit": "245",
       "klarna_region": "NorthAmerica"
   }

iii.

"metadata": {
       "city": "NY",
       "unit": "245",
       "region_based_endpoint": "Oceania"
   }

Create a payment via sdk with capture_method = manual

{
      currency: "USD",
      amount: 5000,
      order_details: [
        {
          product_name: "Apple iphone 15",
          quantity: 1,
          amount: 5000,
        },
      ],
      confirm: false,
      capture_method: "manual",
      authentication_type: "three_ds",
      customer_id: "hyperswitch_sdk_demo_id",
      email: "hyperswitch_sdk_demo_id@gmail.com",
      description: "Hello this is description",
      connector_metadata: {
        noon: {
          order_category: "applepay",
        },
      },
      metadata: {
        udf1: "value1",
        new_customer: "true",
        login_date: "2019-09-10T10:11:12Z",
      },
      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",
        },
      },
      }

Create a payment via sdk with capture_method = automatic

{
      currency: "USD",
      amount: 5000,
      order_details: [
        {
          product_name: "Apple iphone 15",
          quantity: 1,
          amount: 5000,
        },
      ],
      confirm: false,
      capture_method: "automatic",
      authentication_type: "three_ds",
      customer_id: "hyperswitch_sdk_demo_id",
      email: "hyperswitch_sdk_demo_id@gmail.com",
      description: "Hello this is description",
      connector_metadata: {
        noon: {
          order_category: "applepay",
        },
      },
      metadata: {
        udf1: "value1",
        new_customer: "true",
        login_date: "2019-09-10T10:11:12Z",
      },
      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",
        },
      },
      }

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 added A-connector-integration Area: Connector integration C-refactor Category: Refactor labels May 23, 2024
@swangi-kumari swangi-kumari self-assigned this May 23, 2024
@swangi-kumari swangi-kumari marked this pull request as ready for review May 24, 2024 10:13
@swangi-kumari swangi-kumari requested review from a team as code owners May 24, 2024 10:13
Comment on lines 107 to 112
#[serde(rename = "")]
Europe,
#[serde(rename = "-na")]
NorthAmerica,
#[serde(rename = "-oc")]
Oceania,
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this renames

Comment on lines 78 to 83
#[serde(rename = "")]
Europe,
#[serde(rename = "-na")]
NorthAmerica,
#[serde(rename = "-oc")]
Oceania,
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove this renames

Comment on lines 127 to 132
let region_based_endpoint = klarna_metadata_object.region_based_endpoint.ok_or(
errors::ConnectorError::InvalidConnectorConfig {
config: "metadata.region_based_endpoint",
},
)?;
Ok(base_url.replace("{{region_based_endpoint}}", &region_based_endpoint))
Copy link
Contributor

Choose a reason for hiding this comment

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

Match over metadata object and then construct all the different urls

#[derive(Debug, Serialize)]
pub struct OrderLines {
name: String,
quantity: u16,
quantity: i64,
Copy link
Contributor

Choose a reason for hiding this comment

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

Dont modify it

@swangi-kumari swangi-kumari requested a review from a team as a code owner May 27, 2024 14:21
let endpoint =
build_region_specific_endpoint(self.base_url(connectors), &req.connector_meta_data)?;

println!("###session{:?}", endpoint);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove println

let endpoint =
build_region_specific_endpoint(self.base_url(connectors), &req.connector_meta_data)?;

println!("###authorize{:?}", endpoint);
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove println

@@ -70,10 +104,13 @@ impl TryFrom<&types::PaymentsSessionRouterData> for KlarnaSessionRequest {
match request.order_details.clone() {
Some(order_details) => Ok(Self {
intent: KlarnaSessionIntent::Buy,
purchase_country: "US".to_string(),
purchase_country: request.country.ok_or(
Copy link
Contributor

Choose a reason for hiding this comment

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

Which country is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is PaymentsSessionData country.

SamraatBansal
SamraatBansal previously approved these changes May 28, 2024
@swangi-kumari swangi-kumari changed the title refactor(connector): [Klarna] Update api reference and connector_base_url refactor(connector): [Klarna] Refactor Authorize call and configs for prod May 29, 2024
@likhinbopanna likhinbopanna added the M-api-contract-changes Metadata: This PR involves API contract changes label May 29, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue May 29, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 29, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue May 29, 2024
Merged via the queue into main with commit a6570b6 May 29, 2024
22 checks passed
@likhinbopanna likhinbopanna deleted the klarna-refactor branch May 29, 2024 10:18
ghost pushed a commit that referenced this pull request May 29, 2024
…actor

* 'main' of github.com:juspay/hyperswitch: (39 commits)
  Fix(Cypress): Fixing 3DS payment failure in headless mode (#4807)
  feat(users): Add redis in Begin and Verify TOTP and create a new API that updates TOTP (#4765)
  refactor(connector): [Klarna] Refactor Authorize call and configs for prod (#4750)
  fix: implement StrongEq for Vec<u8> (#4795)
  refactor(core): move router data response and request models to hyperswitch domain models crate (#4789)
  chore(version): 2024.05.29.0
  refactor: retrieve extended card info config during business profile get call (#4784)
  refactor(payment_methods): add support for passing ttl to locker entries (#4690)
  feat(connector): [CRYPTOPAY] Pass network details in payment request (#4779)
  fix: include client columns in payment attempts response struct (#4761)
  fix(docker-compose): fix docker compose syntax (#4782)
  feat(connector): [Iatapay] add upi qr support (#4728)
  docs(analytics): Add documentation for setting up data services and enabling data features in control center (#4741)
  chore(version): 2024.05.28.0
  feat(connector): [AUTHORIZEDOTNET] Implement non-zero mandates (#4758)
  feat(core): [Paypal] Add session_token flow for Paypal sdk (#4697)
  chore(version): 2024.05.27.0
  chore: add missing migrations for recently added currencies (#4760)
  Refactor(core): Inclusion of constraint graph for merchant Payment Method list (#4626)
  chore(version): 2024.05.24.1
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-connector-integration Area: Connector integration 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.

None yet

4 participants