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

feat(router): Added amount conversion function in core for connector module #4710

Merged
merged 75 commits into from
May 30, 2024

Conversation

sahkal
Copy link
Contributor

@sahkal sahkal commented May 20, 2024

Type of Change

  • Enhancement

Description

Currently while sending amount to connector, connector does the conversion for all the flows

with this change we will make the amount conversion function as a part of core, where connector will send core in what format it needs the data in and core will do the conversion and connector needs to execute convert function to get that converted data.

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?

To Test this we can do a transaction with NMI and check NMI dashboard for the amount being sent.
note: NMI use currency as Major Unit

Flows to test :

  • Normal Payments
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_YNzUb5MTw5YJw8xiuqUMXUKyi4sZ3QEFClFLp39JbnWBR4Qi8Y6x6dRxyFs0S4bP' \
--data-raw '{
    "amount": 65401,
    "currency": "USD",
    "confirm": true,
    "customer_id": "StripeCustomer",
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "three_ds",
    "return_url": "https://duck.com",
    "payment_method": "card",
    "payment_method_type":"credit",
    "payment_method_data": {
        "card": {
            "card_number": "4000000000002503",
            "card_exp_month": "04",
            "card_exp_year": "2026",
            "card_holder_name": "joseph Doe",
            "card_cvc": "323"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "sundari"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "sundari"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}
'
  • Refunds
curl --location 'http://localhost:8080/refunds' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_YNzUb5MTw5YJw8xiuqUMXUKyi4sZ3QEFClFLp39JbnWBR4Qi8Y6x6dRxyFs0S4bP' \
--data '{
    "payment_id": "pay_Zvlokvy6pOKCeOvryAqV",
    "amount": 65401,
    "reason": "Customer returned product",
    "refund_type": "instant",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
  • Capture
curl --location 'http://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_YNzUb5MTw5YJw8xiuqUMXUKyi4sZ3QEFClFLp39JbnWBR4Qi8Y6x6dRxyFs0S4bP' \
--data-raw '{
    "amount": 65401,
    "currency": "USD",
    "confirm": true,
    "capture_method": "manual",
    "amount_to_capture": 65401,
    "customer_id": "StripeCustomer",
    "email": "guest@example.com",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "three_ds",
    "return_url": "https://duck.com",
    "payment_method": "card",
    "payment_method_type":"credit",
    "payment_method_data": {
        "card": {
            "card_number": "4000000000002503",
            "card_exp_month": "04",
            "card_exp_year": "2026",
            "card_holder_name": "joseph Doe",
            "card_cvc": "323"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "sundari"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "sundari"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }  
}
'

Capture Call

curl --location 'http://localhost:8080/payments/pay_DRwnnBM2UiZj7ZgsBapM/capture' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_YNzUb5MTw5YJw8xiuqUMXUKyi4sZ3QEFClFLp39JbnWBR4Qi8Y6x6dRxyFs0S4bP' \
--data '{
  "amount_to_capture": 65401
}'
Screenshot 2024-05-30 at 7 32 15 PM

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

sahkal and others added 30 commits May 13, 2024 16:50
@sahkal sahkal dismissed stale reviews from Narayanbhat166 and apoorvdixit88 via d009312 May 29, 2024 15:09
Sakilmostak
Sakilmostak previously approved these changes May 30, 2024
Aprabhat19
Aprabhat19 previously approved these changes May 30, 2024
jarnura
jarnura previously approved these changes May 30, 2024
apoorvdixit88
apoorvdixit88 previously approved these changes May 30, 2024
Narayanbhat166
Narayanbhat166 previously approved these changes May 30, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue May 30, 2024
Merged via the queue into main with commit 08eefdb May 30, 2024
22 checks passed
@likhinbopanna likhinbopanna deleted the move-newType-amount-to-connector-module branch May 30, 2024 14:14
@SanchithHegde SanchithHegde removed the S-waiting-on-review Status: This PR has been implemented and needs to be reviewed label Jun 2, 2024
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 A-core Area: Core flows A-currency-conversion Area: Currency Conversion A-payments Area: payments C-feature Category: Feature request or enhancement high-risk
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet