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

fix(router): mark retry payment as failure if connector_tokenization fails #5114

Merged
merged 7 commits into from
Jul 1, 2024

Conversation

ShankarSinghC
Copy link
Contributor

@ShankarSinghC ShankarSinghC commented Jun 25, 2024

Type of Change

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

Description

When a payment confirm call is made the status of the payment would be requires_payment_method while performing connector pre-processing steps. If a there is an error during this step then the status remains in requires_payment_method. If the pre-processing steps succeeds, the status is changed to processing just before the authorize flow. Now if the status will be further updated based on the connector response.

Now if there is an failure response from the connector and if the the retry feature is enabled for that merchant we go to the retry flow. Now for the chosen connector we perform the pre-processing steps, here if something fails the payment status remains in processing as previous during the first attempt the status was updated to processing during the authorize flow.

In this case if something fails in the pre-processing steps during the retry we need to fail the payment.

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?

-> Create MCA of stripe with apple pay simplified flow enabled
-> The connector api in the connector tokenizatoin flow is hardcoded wrongly for test purpose. So in this case if apple pay simplified payment request is made, the error response changes to Invalid wallet token from unimplemented flow. And also in the db the payment_intent status will be as requires_payment_method.
image
image

-> Configure one more connector (BOA) with simplified flow. And configure the routing rule such that the payment first go through BOA and retry happens through Stripe.

-> Enable retry for the merchant account.

curl --location 'localhost:8080/configs/' \
--header 'api-key: test_admin' \
--header 'Content-Type: application/json' \
--data '{
    "key": "should_call_gsm_merchant_1719384197",
    "value": "true"
}'
curl --location 'localhost:8080/configs/' \
--header 'api-key: test_admin' \
--header 'Content-Type: application/json' \
--data '{
    "key": "max_auto_retries_enabled_merchant_1719384197",
    "value": "2"
}'
curl --location 'localhost:8080/gsm' \
--header 'api-key: test_admin' \
--header 'Content-Type: application/json' \
--data '{
    "connector": "bankofamerica",
    "flow": "Authorize",
    "sub_flow": "sub_flow",
    "code": "No error code",
    "message": "Authentication Failed",
    "status": "Failure",
    "decision": "retry",
    "step_up_possible": false
}'

-> Now I have hardcoded the BOA api key wrongly so that payment fails and will be retried with Stripe. Also the connector api in the connector tokenizatoin flow is hardcoded wrongly in Stripe to test if the payment reaches a terminal state (failed) if that connector tokenization call fails for stripe.

{
    "amount": 650,
    "currency": "USD",
    "confirm": true,
    "business_country": "US",
    "business_label": "default",
    "amount_to_capture": 650,
    "customer_id": "test_fb",
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "authentication_type": "three_ds",
    "return_url": "https://google.com",
    "email": "[email protected]",
    "name": "Joseph Doe",
    "phone": "999999999",
    "phone_country_code": "+65",
    "description": "Its my first payment request",
    "statement_descriptor_name": "Juspay",
    "statement_descriptor_suffix": "Router",
    "payment_method": "wallet",
    "payment_method_type": "apple_pay",
    "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"
        }
    },
    "payment_method_data": {
        "wallet": {
            "apple_pay": {
                "payment_data": "eyJkYXRhIjoiVnJnTm9mYXRRZEFIME1MTjZjd1VMazdIS09PdWIvUnMwbEtFOW1vWllvcFhSSXpGemM4VDJiMzlpWjdWSGVXK0YxZVFmY0V5OFJrWjMvcWRZQkVyaE4wK1BxL2pRZ2xpZFNUNlYzdXNwRHB6MlJGSWxYUWhiODJndmd5Y3hSb1R6MER4MDgwNzQ1MUJkN1RMUldyVWNlaVRvdEN4N041ZXFVcjM3UTJlZ2hTaExNOWtXVzAxSmIvT3FLM3RLTUhZaFZNRmE2alNaaHduMVU1NitpbXR5SDMvS1BpdlJlQ0ZxTUtFVmJiRFRyNmpzSDEyNWUwVmlOalBXYm1kVzZJZWU2RDR0cjk5VEhiSkhiWUJzaVdrMUROb29tS28zbHRVUjRkMTZwL09Cc2xTYUh6dnFTL2VrOGVCTDB4dTB3TkMyamx5OFpQUnVZNGRZL2gyS3U0VmprL1BpTWtJUnRNVGl3MTFZWExXUHFNamkvM1N1VDcxUEFnZllpQU4zZmxYK1Q5RmVZRE5yVmdSNWFyRGN3PT0iLCJzaWduYXR1cmUiOiJNSUFHQ1NxR1NJYjNEUUVIQXFDQU1JQUNBUUV4RFRBTEJnbGdoa2dCWlFNRUFnRXdnQVlKS29aSWh2Y05BUWNCQUFDZ2dEQ0NBK013Z2dPSW9BTUNBUUlDQ0JaalRJc09NRmNYTUFvR0NDcUdTTTQ5QkFNQ01Ib3hMakFzQmdOVkJwYjI0Z1EwRWdMU0JITXpFbU1DUUdBMVVFQ3d3ZFFYQndiR1VnUTJWeWRHbG1hV05oZEdsdmJpQkJkWFJvYjNKcGRIa3hFekFSQmdOVkJBb01Da0Z3Y0d4bElFbHVZeTR4Q3pBSkJnTlZCQVlUQWxWVE1Ga3dFd1lIS29aSXpqMENBUVlJS29aSXpqMERBUWNEUWdBRThCY1JoQm5YWklYVkdsNGxnUWQyNklDaTc5NTdyazNnamZ4TGsrRXpWdFZtV3pXdUl0Q1hkZzBpVG51NkNQMTJGODZJeTNhN1puQyt5T2dwaFA5VVJhT0I5ekNCOURCR0JnZ3JCZ0VGQlFjQkFRUTZNRGd3TmdZSUt3WUJCUVVITUFRpb25JZCI6ImMxMTFjYzA1YzBkZjFiMjZmYTI3MjcwZDcyMjhmM2EzNDQ1ZTJhMDNiYTMyYjQ5NjI3ODEzNTVkYjc2M2VjNjMifSwidmVyc2lvbiI6IkVDX3YxIn0=",
                "payment_method": {
                    "display_name": "Visa 0326",
                    "network": "Mastercard",
                    "type": "debit"
                },
                "transaction_identifier": "55CC32D7BF7890B9064433F15B9F23F849CF84AFD01E4E65DD8ADE306300E9D8"
            }
        }
    }
}
image image image

-> When made the same above request without the changes in this pr.
image

image

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

@ShankarSinghC ShankarSinghC added A-core Area: Core flows C-bug Category: Bug labels Jun 25, 2024
@ShankarSinghC ShankarSinghC self-assigned this Jun 25, 2024
@ShankarSinghC ShankarSinghC requested a review from a team as a code owner June 25, 2024 07:13
@ShankarSinghC ShankarSinghC linked an issue Jun 25, 2024 that may be closed by this pull request
@ShankarSinghC ShankarSinghC requested a review from a team as a code owner June 26, 2024 06:58
Comment on lines 839 to 846
if is_retry_payment {
router_data.response = Err(err);
println!("failed connector tokenization");
(None, false)
} else {
logger::debug!(payment_method_tokenization_error=?err);
(None, should_continue_payment)
}
Copy link
Member

Choose a reason for hiding this comment

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

you can decouple this logic as it is done for access token, this function only returns the result of payment method tokenization. Rest of the decision can be taken by another function. You can try to do this.

@ShankarSinghC ShankarSinghC requested a review from a team as a code owner July 1, 2024 09:34
Ok(types::PaymentMethodTokenResult {
payment_method_token_result: Ok(None),
is_payment_method_tokenization_performed: true,
})
Copy link
Member

Choose a reason for hiding this comment

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

should this be true? as we are not performing any tokenization in case the connector is not payme

Ok(None)
Ok(types::PaymentMethodTokenResult {
payment_method_token_result: Ok(None),
is_payment_method_tokenization_performed: false,
Copy link
Member

Choose a reason for hiding this comment

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

the default implementation should be false right?

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jul 1, 2024
Merged via the queue into main with commit ecb8caf Jul 1, 2024
11 checks passed
@Gnanasundari24 Gnanasundari24 deleted the retry/fix-connector-tokenization branch July 1, 2024 14:53
pixincreate added a commit that referenced this pull request Jul 2, 2024
…ror-handling-in-cypress

* 'main' of github.com:juspay/hyperswitch:
  fix(auth_methods): Add checks for duplicate `auth_method` in create API (#5161)
  chore(version): 2024.07.02.0
  fix(router): rename the browser name header to `x-browser-name` (#5162)
  fix(router): mark retry payment as failure if `connector_tokenization` fails (#5114)
  fix(connector): [Paypal] dispute webhook deserialization failure (#5111)
  feat(analytics): Add v2 payment analytics (payment-intents analytics) (#5150)
  feat(globalsearch): Implement tag-based filters in global search (#5151)
  refactor(connector): Add amount conversion framework to iatapay along with amount conversion code to connector template (#4866)
  feat(payment_link): add multiple custom css support in business level  (#5137)
  feat(connector): [Bambora Apac] Template for integration (#5062)
  feat(tls): add support for https in actix web (#5089)
  chore(ci): fix ci tests failing by removing them (#5167)
  chore(version): 2024.07.01.0
  chore(postman): update Postman collection files
  ci(postman): log request id for user tests (#5159)
  chore(euclid_wasm): make field domain optional wasm (#5154)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows C-bug Category: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mark retry payment as failure if connector_tokenization fails
4 participants