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(payment_methods_session_v2): update flow of payment method session #7263

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

ShivanshMathurJuspay
Copy link
Contributor

@ShivanshMathurJuspay ShivanshMathurJuspay commented Feb 13, 2025

Type of Change

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

Description

Payment Method Session update flow is implemented for the Payment Method Service where the PR reflects the changes of updating an already present payment-method-session without changing the TTL of the already present session 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 Session

POST CREATE
curl --location 'http://localhost:8080/v2/payment-methods-session' \
--header 'x-profile-id: pro_22n1ZyVAfpw9p19m03KA' \
--header 'Authorization: api-key=dev_yV5KB2TgmKcUOLvbSTyGVmYtukoyNqjxilK0YnfF1uDaj2Vv0wl2HYRdbSAKGeFb' \
--header 'Content-Type: application/json' \
--data-raw '{
    "customer_id": "12345_cus_0194fec3f6667f33828795d53de0cde8",
     "billing": {
        "address": {
            "first_name": "John",
            "last_name": "Dough"
        },
        "email": "[email protected]"
    },
    "expires_in" : 99999999
}
Response -> {
    "id": "12345_pms_019523b520507e7397b70c7a38cde54a",
    "customer_id": "12345_cus_0194fec3f6667f33828795d53de0cde8",
    "billing": {
        "address": {
            "city": null,
            "country": null,
            "line1": null,
            "line2": null,
            "line3": null,
            "zip": null,
            "state": null,
            "first_name": "John",
            "last_name": "Dough"
        },
        "phone": null,
        "email": "[email protected]"
    },
    "psp_tokenization": null,
    "network_tokenization": null,
    "expires_at": "2028-04-23T00:00:26.729Z",
    "client_secret": "cs_019523b520507e7397b70c81a472d306"
}

Retrieve Session ( before update )

GET RETRIEVE BEFORE UPDATE
curl --location 'http://localhost:8080/v2/payment-methods-session/12345_pms_019523b520507e7397b70c7a38cde54a' \
--header 'x-profile-id: pro_22n1ZyVAfpw9p19m03KA' \
--header 'Authorization: publishable-key=pk_dev_98e959071d914b90b92ecd8d5f0234e1,client-secret=cs_019523b520507e7397b70c81a472d306' \
--header 'api-key: dev_yV5KB2TgmKcUOLvbSTyGVmYtukoyNqjxilK0YnfF1uDaj2Vv0wl2HYRdbSAKGeFb'
Response -> {
    "id": "12345_pms_019523b520507e7397b70c7a38cde54a",
    "customer_id": "12345_cus_0194fec3f6667f33828795d53de0cde8",
    "billing": {
        "address": {
            "city": null,
            "country": null,
            "line1": null,
            "line2": null,
            "line3": null,
            "zip": null,
            "state": null,
            "first_name": "John",
            "last_name": "Dough"
        },
        "phone": null,
        "email": "[email protected]"
    },
    "psp_tokenization": null,
    "network_tokenization": null,
    "expires_at": "2028-04-23T00:00:26.729Z",
    "client_secret": "CLIENT_SECRET_REDACTED"
}

Update Session

PUT UPDATE
curl --location --request PUT 'http://localhost:8080/v2/payment-methods-session/12345_pms_019523b520507e7397b70c7a38cde54a' \
--header 'Authorization: api-key=dev_yV5KB2TgmKcUOLvbSTyGVmYtukoyNqjxilK0YnfF1uDaj2Vv0wl2HYRdbSAKGeFb' \
--header 'x-profile-id: pro_22n1ZyVAfpw9p19m03KA' \
--header 'Content-Type: application/json' \
--header 'api-key: dev_yV5KB2TgmKcUOLvbSTyGVmYtukoyNqjxilK0YnfF1uDaj2Vv0wl2HYRdbSAKGeFb' \
--data-raw '{
    "billing": {
        "address": {
            "first_name": "MATHUR_TESTSTAS",
            "last_name": "SHIVANSH"
        },
        "email": "[email protected]"
    }
}'`
`Response -> {
    "id": "12345_pms_019523b520507e7397b70c7a38cde54a",
    "customer_id": "12345_cus_0194fec3f6667f33828795d53de0cde8",
    "billing": {
        "address": {
            "city": null,
            "country": null,
            "line1": null,
            "line2": null,
            "line3": null,
            "zip": null,
            "state": null,
            "first_name": "MATHUR_TESTSTAS",
            "last_name": "SHIVANSH"
        },
        "phone": null,
        "email": "[email protected]"
    },
    "psp_tokenization": null,
    "network_tokenization": null,
    "expires_at": "2028-04-23T00:00:26.729Z",
    "client_secret": "CLIENT_SECRET_REDACTED"
}

Retrieve Session ( post update )

GET POST UPDATE
curl --location 'http://localhost:8080/v2/payment-methods-session/12345_pms_019523b520507e7397b70c7a38cde54a' \
--header 'x-profile-id: pro_22n1ZyVAfpw9p19m03KA' \
--header 'Authorization: publishable-key=pk_dev_98e959071d914b90b92ecd8d5f0234e1,client-secret=cs_019523b520507e7397b70c81a472d306' \
--header 'api-key: dev_yV5KB2TgmKcUOLvbSTyGVmYtukoyNqjxilK0YnfF1uDaj2Vv0wl2HYRdbSAKGeFb'
Response -> {
    "id": "12345_pms_019523b520507e7397b70c7a38cde54a",
    "customer_id": "12345_cus_0194fec3f6667f33828795d53de0cde8",
    "billing": {
        "address": {
            "city": null,
            "country": null,
            "line1": null,
            "line2": null,
            "line3": null,
            "zip": null,
            "state": null,
            "first_name": "MATHUR_TESTSTAS",
            "last_name": "SHIVANSH"
        },
        "phone": null,
        "email": "[email protected]"
    },
    "psp_tokenization": null,
    "network_tokenization": null,
    "expires_at": "2028-04-23T00:00:26.729Z",
    "client_secret": "CLIENT_SECRET_REDACTED"
}

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

Copy link

semanticdiff-com bot commented Feb 13, 2025

@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Feb 13, 2025
@ShivanshMathurJuspay ShivanshMathurJuspay linked an issue Feb 14, 2025 that may be closed by this pull request
2 tasks
#[cfg(feature = "v2")]
#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
pub struct PaymentMethodsSessionUpdate {
pub id: common_utils::id_type::GlobalPaymentMethodSessionId,
Copy link
Member

Choose a reason for hiding this comment

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

do we need id in the updatable struct?

@@ -1995,3 +2111,22 @@ impl pm_types::SavedPMLPaymentsInfo {
Ok(())
}
}

#[cfg(feature = "v2")]
pub async fn payment_method_session_update_to_current_state(
Copy link
Member

Choose a reason for hiding this comment

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

can you add an impl function like this

impl AuthenticationUpdateInternal {

Comment on lines 1983 to 1988
db.update_payment_method_session(
key_manager_state,
&key_store,
&payment_method_session_id,
update_state_change.clone(),
)
Copy link
Member

Choose a reason for hiding this comment

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

This function should take the update enum, then internally in the implementation we can convert the update enum to updateinternal and then insert into the db

state: &KeyManagerState,
key_store: &hyperswitch_domain_models::merchant_key_store::MerchantKeyStore,
id: &id_type::GlobalPaymentMethodSessionId,
payment_methods_session: hyperswitch_domain_models::payment_methods::PaymentMethodsSession,
Copy link
Member

Choose a reason for hiding this comment

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

instead of this taking the payment method session, it can take payment method session update enum, converting to the payment method session can be done internally. You can see how this logic has been implemented for updating the payment method

@Narayanbhat166
Copy link
Member

@ShivanshMathurJuspay can you attach the curl instead of screenshots? This helps in testing as well

@ShivanshMathurJuspay ShivanshMathurJuspay changed the title feat(payment_methods_session_v2): update flow of Payment Method Session feat(payment_methods_session_v2): update flow of payment method session Feb 21, 2025
Narayanbhat166
Narayanbhat166 previously approved these changes Feb 21, 2025
jarnura
jarnura previously approved these changes Feb 21, 2025
Narayanbhat166
Narayanbhat166 previously approved these changes Feb 21, 2025
@ShivanshMathurJuspay ShivanshMathurJuspay requested a review from a team February 21, 2025 11:04
jarnura
jarnura previously approved these changes Feb 21, 2025
@hyperswitch-bot hyperswitch-bot bot dismissed stale reviews from jarnura and Narayanbhat166 via 9166f48 February 21, 2025 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
M-api-contract-changes Metadata: This PR involves API contract changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[FEATURE] payment method sessions update endpoint
3 participants