Search code examples
pseudocode

Looking for assistance with Pseudocode


I need some help with pseudocode. The question is as follows:

Write pseudocode for a function, processPayment() that processes payment by customers and commits the system to delivering the promised product and service. This function may call on other functions, possibly from other objects. You do not have to describe the called functions or the classes that they belong to as long the calls are reasonably explanatory.

Advertising is displayed while the customer awaits credit approval. (i.e., you can assume that while the function is waiting for credit card approval to complete, the next step begins immediately.)

Advertising is removed as soon as credit acceptance or denial is received. You can assume that the user has already entered credit card information and is aware of the costs of each option.

I have this as pseudocode:

processPayment() 
   do displayAdContent(); 
   while paymentConfirmation(bool) = false; 

I keep thinking I need something after processPayment(). Any guidance would be appreciated!


Solution

  • You need a lot more than "something after processPayment()." I would do something like this:

    ProcessPayment()
    {
       if(paymentIsValid) 
       {
          do displayAdContent();
    
          if(isInInventory()) 
          {
             try 
             {
                do createAndChargeOrder();
                do deliverProduct(); 
                do updateInventory();
             }
             catch
             {
                do cancelOrder();
                do sendFailedOrderNotification();  
             }
          }
          else
          {
             do notifyNotAvailable();
             do offerSimilarProduct();
          }
    
          do sendConfirmation();
       }
       else
       {
          do paymentNotValid();
       }
    }