Description
Solutions
For All Intents And Purposes Part 2 - Change Is Good! πŸ‘
🀘 INTERNπŸ‘©β€πŸŽ“ NEW GRAD

🐝 Hi there! The description you are currently reading is just 2nd part of the problem set. It is highly recommended to read ALL THE PARTS before coding as parts may build on top of each other 🐳

  • For All Intents And Purposes Part 1 - Initilizing the System πŸ—οΈ
  • For All Intents And Purposes Part 2 - Change Is Good! πŸ‘
  • For All Intents And Purposes Part 3 - Accepting Failure 😌
  • For All Intents And Purposes Part 4 - Timing Matters ⏰
  • The initial version of our system looks good πŸ˜„πŸ‘! But it turns out merchants also need to be able to update the amount of initialized Payment Intents. This happen if a customer begins to check out but then decides to change the items in their shopping cart πŸ›’ and thus the amount of the payment. Let's add that the our system 🍻!

    Commands

    Your system should support an additional command for updaing a Payment Intent.

    UPDATE <payment_intent_id> <new amount>

  • Update the monetary amount of an existing Payment Intent in the REQUIRES_ACTION state. This does not transition the state of the Payment Intent.
  • If no Payment Intent with the given identifier exists, or if the Payment Intent is not in the REQUIRES_ACTION state, or if the new amount is negative, this mommand should do nothing.
  • ο½‘οΎŸβ€’β”ˆκ’°αƒ 🧑 Credit to Rachel πŸ§‘ΰ»’κ’±β”ˆβ€’ q゚

    Example 1:

    Input:  commands = ["INIT m1 0", "CREATE p1 m1 50", "UPDATE p1 100",  "ATTEMPT p1", "SUCCEED p1"]
    Output: ["m1 100"]
    Explanation:
    While the Payment Intent p1 was initially created with an amount of 50, this was then updated to 100 before being attempted then succeeded. Therefore, merchant m1 has a balance of 100 after all commands have been processed.
    Constraints:
      🫢
    Thumbnail 0
    Testcase

    Result
    Case 1

    input:

    output: