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_v2): implement payments sync #6464

Merged
merged 32 commits into from
Nov 11, 2024
Merged

feat(payment_v2): implement payments sync #6464

merged 32 commits into from
Nov 11, 2024

Conversation

Narayanbhat166
Copy link
Member

@Narayanbhat166 Narayanbhat166 commented Oct 29, 2024

Type of Change

  • New feature

Description

Implement payments sync for v2. Using this endpoint the status of the payment can be retrieved and also synced with the connector.

Motivation and Context

How did you test it?

  • Create a payment
curl --location 'http://localhost:8080/v2/payments/create-intent' \
--header 'api-key: dev_5BpYAlWiFrmujr10auC6jj48LPGkN7vMJYXv7hKTuLVRLSEt0BancBwWgfzAELii' \
--header 'Content-Type: application/json' \
--header 'x-profile-id: pro_NZsp8AqhIFzKshd7BxX4' \
--data '{
    "amount_details": {
        "order_amount": 100,
        "currency": "USD"
    }
}'
{
    "id": "12345_pay_01931afcc2667a839d75d2e760b99d1e",
    "status": "requires_payment_method",
    "amount_details": {
        "order_amount": 100,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "skip_external_tax_calculation": "Skip",
        "skip_surcharge_calculation": "Skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null
    },
    "client_secret": "12345_pay_01931afcc2667a839d75d2e760b99d1e_secret_01931afcc2667a839d75d2f412de1c77",
    "merchant_reference_id": null,
    "routing_algorithm_id": null,
    "capture_method": "automatic",
    "authentication_type": "no_three_ds",
    "billing": null,
    "shipping": null,
    "customer_id": null,
    "customer_present": "Present",
    "description": null,
    "return_url": null,
    "setup_future_usage": "on_session",
    "apply_mit_exemption": "Skip",
    "statement_descriptor": null,
    "order_details": null,
    "allowed_payment_method_types": null,
    "metadata": null,
    "connector_metadata": null,
    "feature_metadata": null,
    "payment_link_enabled": "Skip",
    "payment_link_config": null,
    "request_incremental_authorization": "default",
    "expires_on": "2024-11-11T11:44:52.743Z",
    "frm_metadata": null,
    "request_external_three_ds_authentication": "Skip"
}
  • Confirm the payment
curl --location 'http://localhost:8080/v2/payments/12345_pay_0192d87d5bfc72e2bd4985b52eb608b5/confirm-intent' \
--header 'x-profile-id: pro_NZsp8AqhIFzKshd7BxX4' \
--header 'x-client-secret: 12345_pay_0192d87d5bfc72e2bd4985b52eb608b5_secret_0192d87d5bfc72e2bd4985c73c6ae36d' \
--header 'Content-Type: application/json' \
--header 'api-key: pk_dev_d48019a209df4d5d8567c9e5d2bdc5af' \
--data '{
    "payment_method_data": {
            "card": {
                "card_number": "4242424242424242",
                "card_exp_month": "01",
                "card_exp_year": "27",
                "card_holder_name": "John Doe",
                "card_cvc": "100"
            }
    },
    "payment_method_type": "card",
    "payment_method_subtype": "credit"
}'
{
    "id": "12345_pay_01931afcc2667a839d75d2e760b99d1e",
    "status": "succeeded",
    "amount": {
        "order_amount": 100,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "skip_external_tax_calculation": "Skip",
        "skip_surcharge_calculation": "Skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null,
        "net_amount": 100,
        "amount_to_capture": null,
        "amount_capturable": 0,
        "amount_captured": null
    },
    "connector": "stripe",
    "client_secret": "12345_pay_01931afcc2667a839d75d2e760b99d1e_secret_01931afcc2667a839d75d2f412de1c77",
    "created": "2024-11-11T11:29:52.743Z",
    "payment_method_data": null,
    "payment_method_type": "card",
    "payment_method_subtype": "credit",
    "next_action": null,
    "connector_transaction_id": "pi_3QJvocIVaesDjvMP0szRoodA",
    "connector_reference_id": null,
    "merchant_connector_id": "mca_It087vhsTsNtgtnTnYd6",
    "browser_info": null,
    "error": null
}
  • Retrieve the payment
curl --location 'http://localhost:8080/v2/payments/12345_pay_0192d87d5bfc72e2bd4985b52eb608b5' \
--header 'x-profile-id: pro_NZsp8AqhIFzKshd7BxX4' \
--header 'x-client-secret: 12345_pay_0192d87d5bfc72e2bd4985b52eb608b5_secret_0192d87d5bfc72e2bd4985c73c6ae36d' \
--header 'Content-Type: application/json' \
--header 'api-key: pk_dev_d48019a209df4d5d8567c9e5d2bdc5af' 
{
    "id": "12345_pay_01931afcc2667a839d75d2e760b99d1e",
    "status": "succeeded",
    "amount": {
        "order_amount": 100,
        "currency": "USD",
        "shipping_cost": null,
        "order_tax_amount": null,
        "skip_external_tax_calculation": "Skip",
        "skip_surcharge_calculation": "Skip",
        "surcharge_amount": null,
        "tax_on_surcharge": null,
        "net_amount": 100,
        "amount_to_capture": null,
        "amount_capturable": 0,
        "amount_captured": null
    },
    "connector": "stripe",
    "client_secret": "12345_pay_01931afcc2667a839d75d2e760b99d1e_secret_01931afcc2667a839d75d2f412de1c77",
    "created": "2024-11-11T11:29:52.743Z",
    "payment_method_data": null,
    "payment_method_type": "card",
    "payment_method_subtype": "credit",
    "connector_transaction_id": "pi_3QJvocIVaesDjvMP0szRoodA",
    "connector_reference_id": null,
    "merchant_connector_id": "mca_It087vhsTsNtgtnTnYd6",
    "browser_info": null,
    "error": null
}

Checklist

  • I formatted the code cargo +nightly fmt --all
  • I addressed lints thrown by cargo clippy
  • I reviewed the submitted code

Copy link

semanticdiff-com bot commented Oct 29, 2024

Review changes with  SemanticDiff

Changed Files
File Status
  crates/diesel_models/src/query/payment_attempt.rs  85% smaller
  crates/router/src/routes/routing.rs  63% smaller
  crates/router/src/services/authentication.rs  62% smaller
  crates/router/src/core/payments/operations/payment_create_intent.rs  52% smaller
  crates/router/src/core/payments/operations/payment_get_intent.rs  52% smaller
  crates/diesel_models/src/query/payment_intent.rs  40% smaller
  crates/router/src/core/payments/operations/payment_response.rs  37% smaller
  crates/router/src/core/payments/operations/payment_confirm_intent.rs  24% smaller
  crates/router/src/core/payments.rs  18% smaller
  crates/common_enums/src/transformers.rs  14% smaller
  crates/router/src/core/payments/operations.rs  6% smaller
  crates/router/src/types/transformers.rs  3% smaller
  crates/storage_impl/src/mock_db/payment_attempt.rs  2% smaller
  crates/diesel_models/src/payment_intent.rs  1% smaller
  api-reference-v2/openapi_spec.json  0% smaller
  crates/api_models/src/events/payment.rs  0% smaller
  crates/api_models/src/payments.rs  0% smaller
  crates/common_enums/src/enums.rs  0% smaller
  crates/common_utils/src/types.rs  0% smaller
  crates/diesel_models/src/kv.rs  0% smaller
  crates/diesel_models/src/payment_attempt.rs  0% smaller
  crates/diesel_models/src/schema_v2.rs  0% smaller
  crates/hyperswitch_domain_models/src/merchant_connector_account.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments/payment_attempt.rs  0% smaller
  crates/hyperswitch_domain_models/src/payments/payment_intent.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_data.rs  0% smaller
  crates/hyperswitch_domain_models/src/router_response_types.rs  0% smaller
  crates/router/src/compatibility/stripe/payment_intents.rs  0% smaller
  crates/router/src/compatibility/stripe/setup_intents.rs  0% smaller
  crates/router/src/core/authentication/utils.rs Unsupported file format
  crates/router/src/core/fraud_check/flows/checkout_flow.rs  0% smaller
  crates/router/src/core/fraud_check/flows/record_return.rs  0% smaller
  crates/router/src/core/fraud_check/flows/sale_flow.rs  0% smaller
  crates/router/src/core/fraud_check/flows/transaction_flow.rs  0% smaller
  crates/router/src/core/payments/flows.rs  0% smaller
  crates/router/src/core/payments/flows/approve_flow.rs  0% smaller
  crates/router/src/core/payments/flows/authorize_flow.rs  0% smaller
  crates/router/src/core/payments/flows/cancel_flow.rs  0% smaller
  crates/router/src/core/payments/flows/capture_flow.rs  0% smaller
  crates/router/src/core/payments/flows/complete_authorize_flow.rs  0% smaller
  crates/router/src/core/payments/flows/incremental_authorization_flow.rs  0% smaller
  crates/router/src/core/payments/flows/post_session_tokens_flow.rs  0% smaller
  crates/router/src/core/payments/flows/psync_flow.rs  0% smaller
  crates/router/src/core/payments/flows/reject_flow.rs  0% smaller
  crates/router/src/core/payments/flows/session_flow.rs  0% smaller
  crates/router/src/core/payments/flows/session_update_flow.rs  0% smaller
  crates/router/src/core/payments/flows/setup_mandate_flow.rs  0% smaller
  crates/router/src/core/payments/operations/payment_get.rs  0% smaller
  crates/router/src/core/payments/retry.rs  0% smaller
  crates/router/src/core/payments/transformers.rs  0% smaller
  crates/router/src/core/payouts.rs  0% smaller
  crates/router/src/db/kafka_store.rs  0% smaller
  crates/router/src/routes/app.rs  0% smaller
  crates/router/src/routes/payments.rs  0% smaller
  crates/router/src/types/api.rs  0% smaller
  crates/storage_impl/src/mock_db/payment_intent.rs  0% smaller
  crates/storage_impl/src/payments/payment_attempt.rs  0% smaller
  crates/storage_impl/src/payments/payment_intent.rs  0% smaller
  v2_migrations/2024-08-28-081721_add_v2_columns/down.sql Unsupported file format
  v2_migrations/2024-08-28-081721_add_v2_columns/up.sql Unsupported file format
  v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/down.sql Unsupported file format
  v2_migrations/2024-08-28-081838_update_v2_primary_key_constraints/up.sql Unsupported file format
  v2_migrations/2024-10-08-081847_drop_v1_columns/down.sql Unsupported file format
  v2_migrations/2024-10-08-081847_drop_v1_columns/up.sql Unsupported file format

@hyperswitch-bot hyperswitch-bot bot added the M-database-changes Metadata: This PR involves database schema changes label Oct 29, 2024
@hyperswitch-bot hyperswitch-bot bot added the M-api-contract-changes Metadata: This PR involves API contract changes label Oct 29, 2024
@Narayanbhat166 Narayanbhat166 marked this pull request as ready for review October 31, 2024 11:34
@Narayanbhat166 Narayanbhat166 requested review from a team as code owners October 31, 2024 11:34
crates/api_models/src/payments.rs Outdated Show resolved Hide resolved
crates/api_models/src/payments.rs Show resolved Hide resolved
crates/api_models/src/payments.rs Show resolved Hide resolved
crates/common_enums/src/enums.rs Show resolved Hide resolved
crates/hyperswitch_domain_models/src/payments.rs Outdated Show resolved Hide resolved
crates/router/src/core/payments/operations/payment_get.rs Outdated Show resolved Hide resolved
crates/router/src/routes/app.rs Outdated Show resolved Hide resolved
crates/router/src/routes/payments.rs Outdated Show resolved Hide resolved
@@ -204,7 +204,10 @@ impl PaymentAttempt {
}

#[cfg(feature = "v2")]
pub async fn find_by_id(conn: &PgPooledConn, id: &str) -> StorageResult<Self> {
pub async fn find_by_id(
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 needs to query with GlobalIntentId also, for now no changes required.

crates/router/src/core/payments/transformers.rs Outdated Show resolved Hide resolved
crates/router/src/routes/app.rs Outdated Show resolved Hide resolved
crates/api_models/src/payments.rs Show resolved Hide resolved
crates/router/src/core/payments/transformers.rs Outdated Show resolved Hide resolved
crates/router/src/core/payments/transformers.rs Outdated Show resolved Hide resolved
@Narayanbhat166 Narayanbhat166 requested a review from a team as a code owner November 8, 2024 10:15
jarnura
jarnura previously approved these changes Nov 8, 2024
tsdk02
tsdk02 previously approved these changes Nov 8, 2024
ThisIsMani
ThisIsMani previously approved these changes Nov 8, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue Nov 11, 2024
github-merge-queue bot pushed a commit that referenced this pull request Nov 11, 2024
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 11, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue Nov 11, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 11, 2024
@likhinbopanna likhinbopanna added this pull request to the merge queue Nov 11, 2024
Merged via the queue into main with commit 42bdf47 Nov 11, 2024
29 checks passed
@likhinbopanna likhinbopanna deleted the payment_sync_v2 branch November 11, 2024 14:06
bsayak03 pushed a commit that referenced this pull request Nov 26, 2024
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
bsayak03 pushed a commit that referenced this pull request Nov 26, 2024
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-v2 M-api-contract-changes Metadata: This PR involves API contract changes M-database-changes Metadata: This PR involves database schema changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants