-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
fix(dispute): change dispute currency type to currency enum #6454
Conversation
3346794
to
07c8721
Compare
8f26d2e
to
e97eede
Compare
e97eede
to
ed16e72
Compare
crates/router/src/db/dispute.rs
Outdated
@@ -483,7 +483,7 @@ mod tests { | |||
DisputeNew { | |||
dispute_id: dispute_ids.dispute_id, | |||
amount: "amount".into(), | |||
currency: "currency".into(), | |||
currency: common_enums::Currency::USD, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can use default in tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -0,0 +1,2 @@ | |||
-- Your SQL goes here | |||
ALTER TABLE dispute ALTER COLUMN currency TYPE "Currency" USING currency::"Currency"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This query would fail, if there's any invalid data. We would need to run a migration on the sandbox and production environments to backfill the currency field in the dispute table, ensuring everything is in uppercase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have added the migration query in the description
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ensure that this up.sql should be run only after deployment both in sandbox and production (along with the required migration to convert the existing data to upper case), you can add the code comments telling that this should be run after deployment
50cbc6e
to
72c065a
Compare
@@ -412,8 +412,7 @@ pub async fn generate_sample_data( | |||
amount: (amount * 100).to_string(), | |||
currency: payment_intent | |||
.currency | |||
.unwrap_or(common_enums::Currency::USD) | |||
.to_string(), | |||
.unwrap_or(common_enums::Currency::USD), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use default here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
@@ -0,0 +1,2 @@ | |||
-- Your SQL goes here | |||
ALTER TABLE dispute ALTER COLUMN currency TYPE "Currency" USING currency::"Currency"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please ensure that this up.sql should be run only after deployment both in sandbox and production (along with the required migration to convert the existing data to upper case), you can add the code comments telling that this should be run after deployment
4fc1601
to
2b315a1
Compare
9b87865
to
5d07f47
Compare
@@ -0,0 +1,2 @@ | |||
-- Your SQL goes here | |||
ALTER TABLE dispute ALTER COLUMN currency TYPE "Currency" USING currency::"Currency"; -- Migration query to be run after deployment before running this query |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't this lock the entire table, and possibly affect deployments which happen in a staggered manner?
43ad7b4
to
8c724f3
Compare
Can you please post a Kafka message which is being pushed as the sample log as well please |
d901c8d
17121e1
to
d901c8d
Compare
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Co-authored-by: hyperswitch-bot[bot] <148525504+hyperswitch-bot[bot]@users.noreply.github.com>
Type of Change
Description
Changed Dispute Currency from String to ENUM.
Connector create (Stripe):
curl --location 'http://localhost:8080/account/merchant_1731933435/connectors' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'api-key: test_admin' \ --data '{ "connector_type": "payment_processor", "connector_name": "stripe", "connector_account_details": { "auth_type": "HeaderKey", "api_key": "abc" }, "test_mode": true, "disabled": false, "payment_methods_enabled": [ { "payment_method": "card", "payment_method_types": [ { "payment_method_type": "credit", "payment_experience": null, "card_networks": [ "Visa", "Mastercard" ], "accepted_currencies": null, "accepted_countries": null, "minimum_amount": -1, "maximum_amount": 68607706, "recurring_enabled": true, "installment_payment_enabled": true }, { "payment_method_type": "debit", "payment_experience": null, "card_networks": [ "Visa", "Mastercard" ], "accepted_currencies": null, "accepted_countries": null, "minimum_amount": -1, "maximum_amount": 68607706, "recurring_enabled": true, "installment_payment_enabled": true } ] }, { "payment_method": "wallet", "payment_method_types": [ { "payment_method_type": "apple_pay", "payment_experience": "invoke_sdk_client", "minimum_amount": 1, "maximum_amount": 68607706, "recurring_enabled": true, "installment_payment_enabled": true }, { "payment_method_type": "google_pay", "payment_experience": "invoke_sdk_client", "minimum_amount": 1, "maximum_amount": 68607706, "recurring_enabled": true, "installment_payment_enabled": true } ] }, { "payment_method": "pay_later", "payment_method_types": [ { "payment_method_type": "klarna", "payment_experience": "redirect_to_url", "card_networks": null, "accepted_currencies": null, "accepted_countries": null, "minimum_amount": 1, "maximum_amount": 68607706, "recurring_enabled": true, "installment_payment_enabled": true } ] } ], "metadata": { "apple_pay_combined": { "manual": { "session_token_data": { "initiative": "web", "certificate": "", "display_name": "applepay", "certificate_keys": "", "payment_processing_details_at": "Connector", "initiative_context": "sdk-test-app.netlify.app", "merchant_identifier": "merchant.com.stripe.sang", "merchant_business_country": "US" }, "payment_request_data": { "label": "applepay", "supported_networks": [ "visa", "masterCard", "amex", "discover" ], "merchant_capabilities": [ "supports3DS" ] } } }, "google_pay": { "merchant_info": { "merchant_name": "Stripe" }, "allowed_payment_methods": [ { "type": "CARD", "parameters": { "allowed_auth_methods": [ "PAN_ONLY", "CRYPTOGRAM_3DS" ], "allowed_card_networks": [ "AMEX", "DISCOVER", "INTERAC", "JCB", "MASTERCARD", "VISA" ] }, "tokenization_specification": { "type": "PAYMENT_GATEWAY", "parameters": { "gateway": "stripe", "stripe:version": "2018-10-31", "stripe:publishableKey": "abc" } } } ] } } }'
Payments Create:
curl --location 'http://localhost:8080/payments' \ --header 'Content-Type: application/json' \ --header 'Accept: application/json' \ --header 'api-key: abc' \ --data-raw '{ "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://google.com", "payment_method": "card", "payment_method_type": "credit", "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": "joseph", "last_name": "Doe" }, "phone": { "number": "8056594427", "country_code": "+91" } }, "shipping": { "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" } }, "statement_descriptor_name": "joseph", "statement_descriptor_suffix": "JS", "metadata": { "udf1": "value1", "new_customer": "true", "login_date": "2019-09-10T10:11:12Z" } }'
payment_intent of the webhook body should be the
connector_transaction_id
of the Payments create response.Webhook testing:
curl --location 'http://localhost:8080/webhooks/merchant_1731037648/mca_X1y5O8y5i29CXmimByPp' \ --header 'stripe-signature: t=1730987258,v1=,v0=' \ --header 'Content-Type: application/json' \ --data '{ "id": "evt_1QIW3iD5R7gDAGffqLkKU7uK", "object": "event", "api_version": "2022-11-15", "created": 1730987257, "data": { "object": { "id": "dp_1QIW3hD5R7gDAGffIDgTp3hd", "object": "dispute", "amount": 100, "balance_transaction": null, "balance_transactions": [], "charge": "ch_3QIW3hD5R7gDAGff1ZNgFNL9", "created": 1730987257, "currency": "usd", "enhanced_eligibility_types": [], "evidence": { "access_activity_log": null, "billing_address": null, "cancellation_policy": null, "cancellation_policy_disclosure": null, "cancellation_rebuttal": null, "customer_communication": null, "customer_email_address": null, "customer_name": null, "customer_purchase_ip": null, "customer_signature": null, "duplicate_charge_documentation": null, "duplicate_charge_explanation": null, "duplicate_charge_id": null, "enhanced_evidence": {}, "product_description": null, "receipt": null, "refund_policy": null, "refund_policy_disclosure": null, "refund_refusal_explanation": null, "service_date": null, "service_documentation": null, "shipping_address": null, "shipping_carrier": null, "shipping_date": null, "shipping_documentation": null, "shipping_tracking_number": null, "uncategorized_file": null, "uncategorized_text": null }, "evidence_details": { "due_by": 1731801599, "enhanced_eligibility": {}, "has_evidence": false, "past_due": false, "submission_count": 0 }, "is_charge_refundable": true, "livemode": false, "metadata": {}, "payment_intent": "pi_3QIjEqD5R7gDAGff1hTCMHyE", "payment_method_details": { "card": { "brand": "visa", "case_type": "inquiry", "network_reason_code": "10" }, "type": "card" }, "reason": "fraudulent", "status": "warning_needs_response" } }, "livemode": false, "pending_webhooks": 12, "request": { "id": "req_LYPj1MWBqlb5QS", "idempotency_key": "7469f2e2-fe9f-4c8d-b863-cf7d4d7e325c" }, "type": "charge.dispute.created" }'
In the
dispute table
thedispute_currency
column should contain actual currency enum like:USD
Connectors that returns uppercase currency but implemented as String: Airwallex, Braintree, Checkout, TrustPay
and lowercase currency("usd"): Stripe
Migration query to be run before running up.sql:
UPDATE dispute SET currency = UPPER(currency);
Additional Changes
Motivation and Context
How did you test it?
Checklist
cargo +nightly fmt --all
cargo clippy