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(pm_auth): Added balance check for PM auth bank account #5054

Merged
merged 12 commits into from
Jul 3, 2024

Conversation

Sarthak1799
Copy link
Contributor

@Sarthak1799 Sarthak1799 commented Jun 20, 2024

Type of Change

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

Description

have added a balance check that would enable a check on the available amount in the selected bank account while doing a payment.
If the found balance is less than the intent amount, the payment would not go through.

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?

Follow this for TCs - #3047
In the payment create, use amount greater then 150 USD for the check to work

  • Payment create -
curl --location --request POST 'http:https://localhost:8080/payments' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_0u355Qt5nbq8BhTZtWmbkwzQJ4JY77u0jOpjyIi3LRqIFziLTFKI8E6QwgFmaFc5' \
--data-raw '{
    "amount": 65400,
    "currency": "USD",
    "confirm": false,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 65400,
    "customer_id": "StripeCustomer",
    "business_country": "US",
    "business_label": "default",
    "email": "[email protected]",
    "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",
    "shipping": {
        "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": "8056594430",
            "country_code": "+91"
        }
    },
    "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"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'
  • Payment confirm
curl --location --request POST 'http:https://localhost:8080/payments/pay_FKpvykZd46XL9grQwPlC/confirm' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: pk_dev_9cdfbdb024614790a4bf730b19a8c375' \
--data-raw '{
    "payment_token": "token_Yxogj2YxdeHjC316ZtM9",
    "client_secret": "pay_FKpvykZd46XL9grQwPlC_secret_KQLB47ADsiyrIhIpOvxv",
    "payment_method": "bank_debit",
    "payment_method_type": "ach"
}'

Response

{
    "error": {
        "type": "invalid_request",
        "message": "Payment amount is greater than the available amount in selected bank account",
        "code": "IR_06"
    }
}

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

@Sarthak1799 Sarthak1799 added the C-feature Category: Feature request or enhancement label Jun 20, 2024
@Sarthak1799 Sarthak1799 self-assigned this Jun 20, 2024
@Sarthak1799 Sarthak1799 requested review from a team as code owners June 20, 2024 10:40
@Sarthak1799 Sarthak1799 linked an issue Jun 20, 2024 that may be closed by this pull request
2 tasks
crates/router/src/core/pm_auth.rs Outdated Show resolved Hide resolved
crates/router/src/core/pm_auth.rs Outdated Show resolved Hide resolved
crates/router/src/core/pm_auth.rs Outdated Show resolved Hide resolved
Chethan-rao
Chethan-rao previously approved these changes Jun 25, 2024
crates/router/src/core/pm_auth.rs Outdated Show resolved Hide resolved
crates/router/src/core/pm_auth.rs Outdated Show resolved Hide resolved
Comment on lines +73 to +76
.change_context(ApiErrorResponse::InvalidRequestData {
message: "Incorrect payment_id provided in request".to_string(),
})
.attach_printable("Corresponding pm_auth_key does not exist in redis")?
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be InternalServerError as the first error propagation is due to redis error. If the bool is false then it should be 4xx.

Can be taken in the next PR.

@likhinbopanna likhinbopanna added this pull request to the merge queue Jul 3, 2024
Merged via the queue into main with commit f513c8e Jul 3, 2024
11 checks passed
@likhinbopanna likhinbopanna deleted the pm-auth-balance-check branch July 3, 2024 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature Category: Feature request or enhancement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] Add a balance check for bank account during AIS flow
4 participants