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] Add shipping Address in Klarna Session and Payment Request #4836

Merged
merged 3 commits into from
Jun 3, 2024

Conversation

swangi-kumari
Copy link
Contributor

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

Type of Change

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

Description

Add shipping Address in Klarna Session and Payment Request

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": "[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
{
  "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"
    }
}

Create a payment via sdk with capture_method = automatic and use the shipping address which is provided below

{
      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: "[email protected]",
      description: "Hello this is description",
      connector_metadata: {
        noon: {
          order_category: "applepay",
        },
      },
      metadata: {
        udf1: "value1",
        new_customer: "true",
        login_date: "2019-09-10T10:11:12Z",
      },
      shipping: {
        address: {
          state: "NY",
          city: "New York",
          country: "US",
          line1: "509",
          line2: "Amsterdam Ave",
          line3: "alsksoe",
          zip: "10024",
          first_name: "Test",
          last_name: "Person-us",
        },
        phone: {
          number: "5551234",
          country_code: "+1",
        },
        email: "[email protected]"
      },
      billing: {
        address: {
          country: "US",
        }
      },
      }

Check in klarna dashboard if shipping details are being populated correctly for the paymnet.

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 31, 2024
@swangi-kumari swangi-kumari self-assigned this May 31, 2024
@swangi-kumari swangi-kumari requested a review from a team as a code owner May 31, 2024 10:45
@swangi-kumari swangi-kumari changed the title reafactor(connector): [Klarna] Add shipping Address in Klarna Session and Payment Request refactor(connector): [Klarna] Add shipping Address in Klarna Session and Payment Request May 31, 2024
Comment on lines +214 to +217
shipping_address
.clone()
.address
.and_then(|shipping_address_details| shipping_address_details.first_name)
Copy link
Member

Choose a reason for hiding this comment

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

we can avoid clone on the shipping address and have clone only on the required field

Suggested change
shipping_address
.clone()
.address
.and_then(|shipping_address_details| shipping_address_details.first_name)
shipping_address
.address.as_ref()
.and_then(|shipping_address_details| shipping_address_details.first_name.clone())

This can be done in other places as well

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jun 3, 2024
Merged via the queue into main with commit 8650077 Jun 3, 2024
10 checks passed
@Gnanasundari24 Gnanasundari24 deleted the klarna-billing branch June 3, 2024 08:10
pixincreate added a commit that referenced this pull request Jun 4, 2024
…atus_pt

* 'main' of github.com:juspay/hyperswitch:
  chore(version): 2024.06.04.0
  fix: include client_version and client_source in retried payments (#4826)
  refactor(users): Changes for Home and Signout APIs for TOTP Redis flows (#4851)
  feat(users): Create config for TOTP Issuer (#4776)
  feat(multitenancy): add support for multitenancy and handle the same in router, producer, consumer, drainer and analytics (#4630)
  feat(connector): [AUTHORIZEDOTNET] Support payment_method_id in recurring mandate payment (#4841)
  refactor(connector): airwallex convert init payment to preprocessing (#4842)
  feat(router): send `three_ds_requestor_url` in authentication_response for external 3ds flow (#4828)
  feat(consolidated-kafka-events): add consolidated kafka payment events (#4798)
  refactor(connector): [Klarna] Add shipping Address in Klarna Session and Payment Request (#4836)
  fix(connector): make few fields optional in struct NetceteraErrorDetails (#4827)
  chore(cypress): remove logs that expose `globalState` (#4844)
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants