juspay / hyperswitch

An open source payments switch written in Rust to make payments fast, reliable and affordable
https://hyperswitch.io/
Apache License 2.0
12.64k stars 1.36k forks source link

[WEB - SDK] - Add Payment Method with Dynamic Field Rendering - Klarna #6050

Open sakksham7 opened 2 months ago

sakksham7 commented 2 months ago

The Hyperswitch SDK is a versatile tool built to streamline payment integration for developers. It simplifies the process of adding multiple payment methods, allowing you to quickly implement support for various gateways without the need to manually integrate each one. With Hyperswitch, you can efficiently manage payments across platforms, reducing complexity and boosting development speed.

Getting started

  1. Get familiar with ReScript.
  2. Check the README.md for project structure and setup instructions.
  3. To setup locally, follow these steps
#  Clone repository
cd hyperswitch-web
yarn install
yarn run server     # This starts the mock server
yarn run re:start   # In another terminal

# Start Demo App in another terminal
cd hyperswitch-react-demo-app
yarn install
yarn run start        # This starts the demo app

Description:

We are looking to implement a new payment method in our WebSDK that supports dynamic field rendering. The goal is to allow the backend to define the fields required for the payment method and have the frontend WebSDK render these fields dynamically based on the response.

This feature should be flexible enough to handle different payment methods, each potentially requiring different types of input fields (e.g., text fields, dropdowns, checkboxes, etc.).


Requirements:

  1. Payment Method Integration Details:

    In this section, we provide details on the payment call response and the confirm call payload for the newly integrated payment method. Ensure you have configured the payment method at Hyperswitch Dashboard correctly. The backend already includes support for this payment method, so no additional configuration is needed.

    Payment Method List Response for Klarna -

    {
     "payment_method": "pay_later",
     "payment_method_types": [
       {
         "payment_method_type": "klarna",
         "payment_experience": [
           {
             "payment_experience_type": "redirect_to_url",
             "eligible_connectors": ["adyen"]
           }
         ],
         "card_networks": null,
         "bank_names": null,
         "bank_debits": null,
         "bank_transfers": null,
         "required_fields": {
           "payment_method_data.pay_later.klarna.billing_country": {
             "required_field": "payment_method_data.pay_later.klarna.billing_country",
             "display_name": "billing_country",
             "field_type": {
               "user_address_country": {
                 "options": ["ALL"]
               }
             },
             "value": null
           },
           "billing.email": {
             "required_field": "payment_method_data.billing.email",
             "display_name": "email",
             "field_type": "user_email_address",
             "value": "hyperswitch_sdk_demo_id@gmail.com"
           }
         },
         "surcharge_details": null,
         "pm_auth_connector": null
       }
     ]
    }

    Confirm call Payload should look like:

    curl --location 'http://localhost:8080/payments' \
    --header 'Content-Type: application/json' \
    --header 'Accept: application/json' \
    --header 'api-key: dev_n9y9SATrxsd8LxVDN7hkyEJcnl1CLdIii8eynRLWfj84Q6BGGS5hXhhljMT6AK1A' \
    --data-raw '{
    "amount": 6540,
    "currency": "EUR",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 6540,
    "customer_id": "StripeCustomer",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "payment_method": "pay_later",
    "payment_method_type": "klarna",
    "payment_experience": "redirect_to_url",
    "payment_method_data": {
        "pay_later": {
            "klarna_redirect": {}
        },
        "billing": {
            "address": {
                "country": "DE"
    
            },
            "email": "example@example.com"
        }
    }
    }'
  2. Dynamic Field Rendering:

  1. User Inputs:

Contribution Guidelines:


Helpful Resources:

Submission Process:

Refer here for Terms and conditions for the contest.

If you have any questions or need help getting started, feel free to ask in the comments!

Jayanth-M0625 commented 1 month ago

Hello maintainers. I want to contribute to this issue. Should I prepare my code first and then ask for this issue to be assigned or to get help regarding this issue it has to be assigned to me first?

gorakhnathy7 commented 1 month ago

Hey @Jayanth-M0625 This can be assigned to you before hand, thanks!

Jayanth-M0625 commented 1 month ago

Can you please assign me this issue?

gorakhnathy7 commented 1 month ago

Hey @Jayanth-M0625 ,

Quick check-in on the status of this issue. If you have any questions or need assistance, feel free to reach out in the community.

Jayanth-M0625 commented 1 month ago

I am out of station till 14th. I will continue after that. Update until now: I have read payments 101, got familiar with react and I could set up the app. I need to learn rescript and how to interact with the App's APIs. I will continue after I return.

gorakhnathy7 commented 1 month ago

Hey @Jayanth-M0625 Great to see you learning, To ensure everyone is able to work on some issues, I'll un-assign this issue for now. You can pick new issue from here, once you are back.