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

refactor(payment_methods): Enable deletion of default Payment Methods #4942

Merged
merged 1 commit into from
Jun 12, 2024

Conversation

Aprabhat19
Copy link
Contributor

@Aprabhat19 Aprabhat19 commented Jun 11, 2024

Type of Change

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

Description

Previously we did not support the deletion of the Default Payment Method, if it's the only PM for the particular customer. In this PR we enable deletion of default Payment Methods

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 MA and a MCA
  • Do a payment , with setup_future_usag:off_session; the card would be saved
  • Do a List PM for Customers, you'll have only one card , which has been set as default
Response
{
    "customer_payment_methods": [
        {
            "payment_token": "token_FC8TupTKMEmhtM69dmYS",
            "payment_method_id": "pm_Syvbg2Nb8mGdZC9oi4Sv",
            "customer_id": "CustomerX",
            "payment_method": "card",
            "payment_method_type": "credit",
            "payment_method_issuer": null,
            "payment_method_issuer_code": null,
            "recurring_enabled": true,
            "installment_payment_enabled": false,
            "payment_experience": [
                "redirect_to_url"
            ],
            "card": {
                "scheme": null,
                "issuer_country": null,
                "last4_digits": "4242",
                "expiry_month": "11",
                "expiry_year": "2040",
                "card_token": null,
                "card_holder_name": "AKA",
                "card_fingerprint": null,
                "nick_name": "HELO",
                "card_network": null,
                "card_isin": "424242",
                "card_issuer": null,
                "card_type": null,
                "saved_to_locker": true
            },
            "metadata": null,
            "created": "2024-06-11T10:14:09.587Z",
            "bank": null,
            "surcharge_details": null,
            "requires_cvv": true,
            "last_used_at": "2024-06-11T10:14:09.587Z",
            "default_payment_method_set": true,
            "billing": {
                "address": {
                    "city": "San Fransico",
                    "country": "US",
                    "line1": "1467",
                    "line2": "Harrison Street",
                    "line3": "Harrison Street",
                    "zip": "94122",
                    "state": "California",
                    "first_name": "joseph",
                    "last_name": "Doe"
                },
                "phone": {
                    "number": "8056594427",
                    "country_code": "+91"
                },
                "email": null
            }
        }
    ],
    "is_guest_customer": null
}
  • Delete the Payment Method, it'll be a success
Request
curl --location --request DELETE 'http://localhost:8080/payment_methods/:payment_method_id' \
--header 'Accept: application/json' \
--header 'api-key: dev_u3eBlxHY8BxUeQxxgvZGxKRXf7HEPaAw0sXmhjXjFFTmQ0pfyslENYRDajyrQnOf'
Response
{
    "payment_method_id": "pm_50cS5VsVOhgbKQ63WReh",
    "deleted": true
}
  • List the Pm for Customer would be empty
Response

{
    "customer_payment_methods": [],
    "is_guest_customer": null
}

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

@Aprabhat19 Aprabhat19 requested a review from a team as a code owner June 11, 2024 08:57
@Aprabhat19 Aprabhat19 self-assigned this Jun 11, 2024
@Aprabhat19 Aprabhat19 linked an issue Jun 11, 2024 that may be closed by this pull request
2 tasks
Copy link
Member

@vspecky vspecky left a comment

Choose a reason for hiding this comment

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

If we allow deleting default payment methods, then we also need to update the default_payment_method_id field of the customer object in DB, else it will be pointing to a deleted record.

@Aprabhat19
Copy link
Contributor Author

Aprabhat19 commented Jun 12, 2024

If we allow deleting default payment methods, then we also need to update the default_payment_method_id field of the customer object in DB, else it will be pointing to a deleted record.

@vspecky here we are just allowing the deletion of the default payment method id if its 1 , the updation of the default_payment_method_id field of the customer object in DB , is already happening

@Gnanasundari24 Gnanasundari24 added this pull request to the merge queue Jun 12, 2024
Merged via the queue into main with commit cf3d039 Jun 12, 2024
17 of 19 checks passed
@Gnanasundari24 Gnanasundari24 deleted the enable-delete-default branch June 12, 2024 10:30
pixincreate added a commit that referenced this pull request Jun 13, 2024
…outs

* 'main' of github.com:juspay/hyperswitch:
  feat(router): include the pre-routing connectors in Apple Pay retries (#4952)
  fix(cypress): Add `jwt_token` and `cookie` for routing test (#4953)
  feat(connectors): [Iatapay] add payment methods (#4968)
  chore(version): 2024.06.13.0
  feat(payouts): make payout_type optional in payouts table (#4954)
  feat(connector): [BOA/CYB] Make billTo fields optional (#4951)
  fix(core): fix the multitenancy prefix  in routing cache (#4963)
  refactor(connector): [Mifinity]Move destination_account_number from pmd to Mifinity Metadata (#4962)
  refactor(payment_methods): Enable deletion of default Payment Methods (#4942)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[REFACTOR] Allow deletion of Default Payment Methods
5 participants