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): add payment method type duplication check for google_pay #5023

Merged
merged 3 commits into from
Jun 19, 2024

Conversation

ShankarSinghC
Copy link
Contributor

@ShankarSinghC ShankarSinghC commented Jun 18, 2024

Type of Change

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

Description

Currently there is no duplication check for google pay and we will create a new payment method entry for every google pay payment CIT with "setup_future_usage": "on_session". This is not the case in cards as locker handles the card duplication. Since we do not have a parameter handle duplication check for a google pay, we have to go with a approach of a customer can have only one saved google pay payment method.

In this approach we list all the saved payment method for a customer during every google pay CIT and check if any of them have the payment_method_type is google_pay if it is then we just return already saved payment_method_id.

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 a merchant connector account with google pay enabled
-> Do a CIT with setup_future_usage

curl --location 'https://localhost:8080/payments' \
--header 'Accept: application/json' \
--header 'api-key: dev_rR35w9RzL1WW5hiDN7aF9jZbH6qHzAzW0nb9kB52KAnJDYc5EH3CakFbIje9MpYk' \
--header 'Content-Type: application/json' \
--data-raw '{
    "amount": 800,
    "currency": "USD",
    "confirm": true,
    "amount_to_capture": 800,
    "customer_id": "gpay_testing",
    "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": "google_pay",
    "payment_method_data": {
        "wallet": {
            "google_pay": {
                "type": "CARD",
                "description": "Visa •••• 1111",
                "info": {
                    "card_network": "VISA",
                    "card_details": "1111"
                },
                "tokenization_data": {
                    "type": "PAYMENT_GATEWAY",
                    "token": "{\n  \"id\": \"tok_1PT1DcD5n    \"address_line2\": null,\n    \"address_state\": null,\n    \"address_zip\": null,\n    \"address,\n    \"exp_year\": 2026,\n    \"funding\": \"credit\",\n    \"last4\": \"1111\",\n    \"metadata\": {},\n    \"name\": null,\n    \"networks\": {\n      \"preferred\": null\n    },\n    \"tokenization_method\": \"android_pay\",\n    \"wallet\": null\n  },\n  \"client_ip\": \"209.85.198.162\",\n  \"created\": 1718713980,\n  \"livemode\": false,\n  \"type\": \"card\",\n  \"used\": false\n}"
                }
            }
        }
    },
    "setup_future_usage": "off_session",
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    "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"
        }
    },
    "connector_metadata": {
        "noon": {
            "order_category": "pay"
        }
    }
}'
image

-> Perform the CIT again with same request payload and different google pay token

{
    "amount": 800,
    "currency": "USD",
    "confirm": true,
    "amount_to_capture": 800,
    "customer_id": "gpay_testing",
    "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": "google_pay",
    "payment_method_data": {
        "wallet": {
            "google_pay": {
                "type": "CARD",
                "description": "Visa •••• 1111",
                "info": {
                    "card_network": "VISA",
                    "card_details": "1111"
                },
                "tokenization_data": {
                    "type": "PAYMENT_GATEWAY",
                    "token": "{\n  \"id\": \"tok_1PT1czD5R7gDAGffO2Mtj23f\",\n  \"object\": \"token\",\n  \"card\": {\n    \"id\": \"card_1PT1czD5R7gDAGffPGZqUPoL\",\n    \"object\": \"card\",\n    \"address_city\": null,\n    \"address_country\": null,\n    \"address_line1\": null,\n    \"address_line1_check\": null,\n    \"address_line2\": null,\n    \"address_state\": null,\n    \"address_zip\": null,\n    \"address_zip_check\": null,\n    \"brand\": \"Visa\",\n    \"country\": \"US\",\n    \"cvc_check\": null,\n    \"dynamic_last4\": \"1111\",\n    \"exp_month\": 12,\n    \"exp_year\": 2026,\n    \"funding\": \"credit\",\n    \"last4\": \"1111\",\n    \"metadata\": {},\n    \"name\": null,\n    \"networks\": {\n      \"preferred\": null\n    },\n    \"tokenization_method\": \"android_pay\",\n    \"wallet\": null\n  },\n  \"client_ip\": \"209.85.198.162\",\n  \"created\": 1718715553,\n  \"livemode\": false,\n  \"type\": \"card\",\n  \"used\": false\n}"
                }
            }
        }
    },
    "setup_future_usage": "off_session",
    "customer_acceptance": {
        "acceptance_type": "offline",
        "accepted_at": "1963-05-03T04:07:52.723Z",
        "online": {
            "ip_address": "in sit",
            "user_agent": "amet irure esse"
        }
    },
    "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"
        }
    },
    "connector_metadata": {
        "noon": {
            "order_category": "pay"
        }
    }
}
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 A-payment-methods Area: Payment Methods labels Jun 18, 2024
@ShankarSinghC ShankarSinghC self-assigned this Jun 18, 2024
@ShankarSinghC ShankarSinghC requested a review from a team as a code owner June 18, 2024 11:04
@ShankarSinghC ShankarSinghC linked an issue Jun 18, 2024 that may be closed by this pull request
@@ -532,6 +534,10 @@ where
.find(|payment_method| {
payment_method.payment_method_type
== Some(api_models::enums::PaymentMethodType::ApplePay)
|| payment_method.payment_method_type
Copy link
Contributor

Choose a reason for hiding this comment

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

it can return apple pay PM id for a gpay PM

jagan-jaya
jagan-jaya previously approved these changes Jun 19, 2024
Copy link
Member

Choose a reason for hiding this comment

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

You probably want to rename the customer_apple_pay_saved_pm_id_option variable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will rename it.

@preetamrevankar preetamrevankar added this pull request to the merge queue Jun 19, 2024
Merged via the queue into main with commit 7d46afd Jun 19, 2024
11 checks passed
@preetamrevankar preetamrevankar deleted the google_pay/handle_duplication branch June 19, 2024 12:47
pixincreate added a commit that referenced this pull request Jun 20, 2024
…ress-skip

* 'main' of github.com:juspay/hyperswitch: (27 commits)
  feat(cypress): add 2 more payout connectors and bank transfer support for payout (#4993)
  chore(version): 2024.06.20.0
  Refactor(core): reverts the payment method list filtering using constraint graph (#5044)
  feat(router): add payment method type duplication check for `google_pay` (#5023)
  refactor(storage): remove `id` from payment intent, attempt and remove datamodel ext from payment intent (#4923)
  fix(events): Correct parsing of API events with user event_type for Clickhouse (#5022)
  fix(connector):  add local bank redirect type in compatibility layer, default the country to AT for Local Bank Redirect and add creds_identifier in access token  (#5038)
  refactor(connector): add amount conversion framework for noon (#4843)
  fix(logging): fix stack overflow on recording restricted keys (#4423)
  feat(core): Add logger for sessions call failure (#5036)
  chore(version): 2024.06.19.0
  fix(opensearch): handle index not present errors in search api (#4965)
  feat(multitenancy): add tenant_id as a field for data pipeline and support individual database for clickhouse  (#4867)
  refactor: add basic counter metrics for IMC (#5006)
  fix(payment_methods): populate card fields while saving card again during metadata change condition (#5019)
  feat(router): Override the `setup_future_usage` to `on_session` based on the merchant config (#5016)
  chore(docker-compose): pass correct configuration values for running SDK demo app  (#5012)
  refactor: Move trait ConnectorIntegration to crate hyperswitch_interfaces (#4946)
  chore(version): 2024.06.17.0
  chore(process_tracker): use `const` instead of `String` for `business_status` (#4849)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows A-payment-methods Area: Payment Methods
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add payment method type duplication check for google_pay
4 participants