The response object for SendInvoice.
Ejemplo n.º 1
0
 public void sendInvoiceResponseConstruction()
 {
     SendInvoiceResponse cir = new SendInvoiceResponse(validSendInvoiceResponse, "");
     Assert.AreEqual("INV2-PCWG-P78G-7EYV-94QY", cir.invoiceID);
     Assert.AreEqual(AckCode.SUCCESS, cir.responseEnvelope.ack);
     Assert.AreEqual("1917403", cir.responseEnvelope.build);
     Assert.AreEqual("9b3bb0a44d852", cir.responseEnvelope.correlationId);
     Assert.AreEqual("2011-05-30T03:31:18.988-07:00", cir.responseEnvelope.timestamp);
 }
    // # SendInvoice API Operation
    // Use the SendInvoice API operation to send an invoice to a payer, and notify the payer of the pending invoice. 
    public SendInvoiceResponse SendInvoiceAPIOperation()
    {
        // Create the SendInvoiceResponse object
        SendInvoiceResponse responseSendInvoice = new SendInvoiceResponse();
        
        try
        {
            // # SendInvoiceRequest
            // Use the SendInvoiceRequest message to send an invoice to a payer, and
            // notify the payer of the pending invoice.

            // The code for the language in which errors are returned, which must be
            // en_US.
            RequestEnvelope envelopeRequest = new RequestEnvelope();
            envelopeRequest.errorLanguage = "en_US";

            // SendInvoiceRequest which takes mandatory params:
            //
            // * `Request Envelope` - Information common to each API operation, such
            // as the language in which an error message is returned.
            // * `Invoice ID` - ID of the invoice to send.
            SendInvoiceRequest requestSendInvoice = new SendInvoiceRequest(envelopeRequest, "INV2-ZC9R-X6MS-RK8H-4VKJ");

            // Create the service wrapper object to make the API call
            InvoiceService service = new InvoiceService();
           
            // # API call 
            // Invoke the SendInvoice method in service
            responseSendInvoice = service.SendInvoice(requestSendInvoice);

            if (responseSendInvoice != null)
            {
                // Response envelope acknowledgement
                string acknowledgement = "SendInvoice API Operation - ";
                acknowledgement += responseSendInvoice.responseEnvelope.ack.ToString();
                logger.Info(acknowledgement + "\n");
                Console.WriteLine(acknowledgement + "\n");

                // # Success values
                if (responseSendInvoice.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // ID of the created invoice.
                    logger.Info("Invoice ID : " + responseSendInvoice.invoiceID + "\n");
                    Console.WriteLine("Invoice ID : " + responseSendInvoice.invoiceID + "\n");
                }
                // # Error Values                
                else
                {
                    List<ErrorData> errorMessages = responseSendInvoice.error;
                    foreach (ErrorData error in errorMessages)
                    {
                        logger.Debug("API Error Message : " + error.message);
                        Console.WriteLine("API Error Message : " + error.message + "\n");
                    }
                }
            }
        }
        // # Exception log    
        catch (System.Exception ex)
        {
            // Log the exception message       
            logger.Debug("Error Message : " + ex.Message);
            Console.WriteLine("Error Message : " + ex.Message);
        }
        return responseSendInvoice;
    }