Skip to content

refactor(refunds): set Instant as the default RefundType #7824

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

Merged
merged 3 commits into from
Apr 28, 2025

Conversation

swangi-kumari
Copy link
Contributor

@swangi-kumari swangi-kumari commented Apr 16, 2025

Type of Change

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

Description

  • set Instant as the default RefundType

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?

  1. Create a Merchant
  2. Create a API Key
  3. Create Stripe MCA
  4. Create a Stripe Payment
{
    "amount": 6540,
    "currency": "USD",
    "confirm": true,
    "capture_method": "automatic",
    "capture_on": "2022-09-10T10:11:12Z",
    "amount_to_capture": 6540,
    "customer_id": "StripeCustomer",
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "phone_country_code": "+1",
    "description": "Its my first payment request",
    "authentication_type": "no_three_ds",
    "return_url": "https://duck.com",
    "setup_future_usage": "off_session",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "card_number": "4242424242424242",
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "card_cvc": "123"
        }
    },
    "billing": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "sundari"
        }
    },
    "shipping": {
        "address": {
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "city": "San Fransico",
            "state": "California",
            "zip": "94122",
            "country": "US",
            "first_name": "sundari"
        }
    },
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "routing": {
        "type": "single",
        "data": "stripe"
    }
}

Response

{
    "payment_id": "pay_dJRGgJCV4FAFIvmAi5No",
    "merchant_id": "postman_merchant_GHAction_7cf2ef98-05dd-4667-9704-6cc558a1eb76",
    "status": "succeeded",
    "amount": 6540,
    "net_amount": 6540,
    "shipping_cost": null,
    "amount_capturable": 0,
    "amount_received": 6540,
    "connector": "stripe",
    "client_secret": "pay_dJRGgJCV4FAFIvmAi5No_secret_0D9ybij4Vw5Khx77Q213",
    "created": "2025-04-16T06:15:49.117Z",
    "currency": "USD",
    "customer_id": "StripeCustomer",
    "customer": {
        "id": "StripeCustomer",
        "name": "John Doe",
        "email": "[email protected]",
        "phone": "999999999",
        "phone_country_code": "+1"
    },
    "description": "Its my first payment request",
    "refunds": null,
    "disputes": null,
    "mandate_id": null,
    "mandate_data": null,
    "setup_future_usage": "off_session",
    "off_session": null,
    "capture_on": null,
    "capture_method": "automatic",
    "payment_method": "card",
    "payment_method_data": {
        "card": {
            "last4": "4242",
            "card_type": "CREDIT",
            "card_network": "Visa",
            "card_issuer": "STRIPE PAYMENTS UK LIMITED",
            "card_issuing_country": "UNITEDKINGDOM",
            "card_isin": "424242",
            "card_extended_bin": null,
            "card_exp_month": "10",
            "card_exp_year": "25",
            "card_holder_name": "joseph Doe",
            "payment_checks": {
                "cvc_check": "pass",
                "address_line1_check": "pass",
                "address_postal_code_check": "pass"
            },
            "authentication_data": null
        },
        "billing": null
    },
    "payment_token": null,
    "shipping": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "sundari",
            "last_name": null
        },
        "phone": null,
        "email": null
    },
    "billing": {
        "address": {
            "city": "San Fransico",
            "country": "US",
            "line1": "1467",
            "line2": "Harrison Street",
            "line3": "Harrison Street",
            "zip": "94122",
            "state": "California",
            "first_name": "sundari",
            "last_name": null
        },
        "phone": null,
        "email": null
    },
    "order_details": null,
    "email": "[email protected]",
    "name": "John Doe",
    "phone": "999999999",
    "return_url": "https://duck.com/",
    "authentication_type": "no_three_ds",
    "statement_descriptor_name": "joseph",
    "statement_descriptor_suffix": "JS",
    "next_action": null,
    "cancellation_reason": null,
    "error_code": null,
    "error_message": null,
    "unified_code": null,
    "unified_message": null,
    "payment_experience": null,
    "payment_method_type": "credit",
    "connector_label": null,
    "business_country": null,
    "business_label": "default",
    "business_sub_label": null,
    "allowed_payment_method_types": null,
    "ephemeral_key": {
        "customer_id": "StripeCustomer",
        "created_at": 1744784149,
        "expires": 1744787749,
        "secret": "epk_681b7b15521c43fca2660f37d9e0e62d"
    },
    "manual_retry_allowed": false,
    "connector_transaction_id": "pi_3REPGDD5R7gDAGff1KI5u3aK",
    "frm_message": null,
    "metadata": {
        "udf1": "value1",
        "login_date": "2019-09-10T10:11:12Z",
        "new_customer": "true"
    },
    "connector_metadata": null,
    "feature_metadata": null,
    "reference_id": "pi_3REPGDD5R7gDAGff1KI5u3aK",
    "payment_link": null,
    "profile_id": "pro_cqVeaynmyv9rePnQmBJ9",
    "surcharge_details": null,
    "attempt_count": 1,
    "merchant_decision": null,
    "merchant_connector_id": "mca_b4Ikzjk24EKcNP5ZIMrT",
    "incremental_authorization_allowed": null,
    "authorization_count": null,
    "incremental_authorizations": null,
    "external_authentication_details": null,
    "external_3ds_authentication_attempted": false,
    "expires_on": "2025-04-16T06:30:49.117Z",
    "fingerprint": null,
    "browser_info": null,
    "payment_method_id": null,
    "payment_method_status": null,
    "updated": "2025-04-16T06:15:50.318Z",
    "split_payments": null,
    "frm_metadata": null,
    "extended_authorization_applied": null,
    "capture_before": null,
    "merchant_order_reference_id": null,
    "order_tax_amount": null,
    "connector_mandate_id": null,
    "card_discovery": "manual",
    "force_3ds_challenge": false,
    "force_3ds_challenge_trigger": false,
    "issuer_error_code": null,
    "issuer_error_message": null
}
  1. Create a refund and don't pass refund_type
curl --location 'http://localhost:8080/refunds' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'api-key: dev_6DE9TuqLLyGxlTvI6twET8TUPo341DE3sjqdUKwmZgbPaYavAGmymyUBgGXRO27k' \
--data '{
    "payment_id": "pay_dJRGgJCV4FAFIvmAi5No",
    "amount": 600,
    "reason": "Customer returned product",
    
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    }
}'

Response

{
    "refund_id": "ref_MxPPzIGgKWPx1z2V4Xmf",
    "payment_id": "pay_dJRGgJCV4FAFIvmAi5No",
    "amount": 600,
    "currency": "USD",
    "status": "succeeded",
    "reason": "Customer returned product",
    "metadata": {
        "udf1": "value1",
        "new_customer": "true",
        "login_date": "2019-09-10T10:11:12Z"
    },
    "error_message": null,
    "error_code": null,
    "unified_code": null,
    "unified_message": null,
    "created_at": "2025-04-16T06:15:59.663Z",
    "updated_at": "2025-04-16T06:16:00.642Z",
    "connector": "stripe",
    "profile_id": "pro_cqVeaynmyv9rePnQmBJ9",
    "merchant_connector_id": "mca_b4Ikzjk24EKcNP5ZIMrT",
    "split_refunds": null,
    "issuer_error_code": null,
    "issuer_error_message": null
}

Refund will go to succeeded, as now we have set default refund_type as Instant.
Before this change all the refund was being Scheduled, if we don't pass "refund_type": "instant"

In db we can see refund_type | instant_refund

Screenshot 2025-04-16 at 12 14 11 PM

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

@swangi-kumari swangi-kumari self-assigned this Apr 16, 2025
@swangi-kumari swangi-kumari requested review from a team as code owners April 16, 2025 06:43
Copy link

semanticdiff-com bot commented Apr 16, 2025

Review changes with  SemanticDiff

Changed Files
File Status
  crates/api_models/src/analytics/refunds.rs  0% smaller
  crates/api_models/src/refunds.rs  0% smaller
  crates/diesel_models/src/enums.rs  0% smaller

@swangi-kumari swangi-kumari changed the title refactor(core): [Refunds] make Instant as default refund_type refactor(refunds): make Instant as default refund_type Apr 16, 2025
@swangi-kumari swangi-kumari added this to the April 2025 Release milestone Apr 16, 2025
@swangi-kumari swangi-kumari changed the title refactor(refunds): make Instant as default refund_type refactor(refunds): set Instant as the default RefundType Apr 16, 2025
Copy link
Member

@SanchithHegde SanchithHegde left a comment

Choose a reason for hiding this comment

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

Other than that, looks good to me!

@@ -24,8 +24,8 @@ use crate::enums::{Currency, RefundStatus};
#[serde(rename_all = "snake_case")]
#[strum(serialize_all = "snake_case")]
pub enum RefundType {
Copy link
Member

Choose a reason for hiding this comment

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

@ShivanshMathurJuspay Why do we have this enum in the analytics crate as well? And does it need to derive Default?

Copy link
Contributor

Choose a reason for hiding this comment

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

// TODO RefundType api_models_oss need to mapped to storage_model

This was added when we had added refund analytics back in 2023

@swangi-kumari swangi-kumari added the A-core Area: Core flows label Apr 16, 2025
@likhinbopanna likhinbopanna added this pull request to the merge queue Apr 28, 2025
Merged via the queue into main with commit ac66cbe Apr 28, 2025
16 of 20 checks passed
@likhinbopanna likhinbopanna deleted the refund-type branch April 28, 2025 11:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-core Area: Core flows
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants