juspay / hyperswitch

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

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

Closed ShankarSinghC closed 4 days ago

ShankarSinghC commented 1 week ago

Type of Change

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

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": "something@gmail.com",
    "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