Search parameters criteria.
Esempio n. 1
0
        /// <summary>
        /// API call example for SearchInvoices
        /// </summary>
        /// <param name="context"></param>
        private void SearchInvoices(HttpContext context)
        {
            // Collect input params
            String merchantEmail = context.Request.Params["merchantEmail"];
            int page = Int32.Parse(context.Request.Params["page"]);
            int pageSize = Int32.Parse(context.Request.Params["pageSize"]);
            SearchParametersType searchParams = new SearchParametersType();
            SearchInvoicesRequest request = new SearchInvoicesRequest(
                new RequestEnvelope(ERROR_LANGUAGE), merchantEmail, searchParams, page, pageSize);
            if (context.Request.Params["email"] != "")
            {
                searchParams.email = context.Request.Params["email"];
            }
            if (context.Request.Params["recipientName"] != "")
            {
                searchParams.recipientName = context.Request.Params["recipientName"];
            }
            if (context.Request.Params["businessName"] != "")
            {
                searchParams.businessName = context.Request.Params["businessName"];
            }
            if (context.Request.Params["invoiceNumber"] != "")
            {
                searchParams.invoiceNumber = context.Request.Params["invoiceNumber"];
            }
            if (context.Request.Params["status0"] != "")
            {
                // You can add upto 10 status to do a 'OR' search on multiple status types
                searchParams.status.Add(
                    (StatusType)Enum.Parse(typeof(StatusType), context.Request.Params["status0"]));
            }
            if (context.Request.Params["status1"] != "")
            {
                // You can add upto 10 status to do a 'OR' search on multiple status types
                searchParams.status.Add(
                    (StatusType)Enum.Parse(typeof(StatusType), context.Request.Params["status1"]));
            }
            if (context.Request.Params["status2"] != "")
            {
                // You can add upto 10 status to do a 'OR' search on multiple status types
                searchParams.status.Add(
                    (StatusType)Enum.Parse(typeof(StatusType), context.Request.Params["status2"]));
            }
            if (context.Request.Params["lowerAmount"] != "")
            {
                searchParams.lowerAmount = decimal.Parse(context.Request.Params["lowerAmount"]);
            }
            if (context.Request.Params["upperAmount"] != "")
            {
                searchParams.upperAmount = decimal.Parse(context.Request.Params["upperAmount"]);
            }
            if (context.Request.Params["memo"] != "")
            {
                searchParams.memo = context.Request.Params["memo"];
            }
            if (context.Request.Params["currencyCode"] != "")
            {
                searchParams.currencyCode = context.Request.Params["currencyCode"];
            }
            if (context.Request.Params["origin"] != "")
            {
                searchParams.origin = (OriginType)
                     Enum.Parse( typeof(OriginType),  context.Request.Params["origin"]);
            }
            if (context.Request.Params["invoiceDateStart"] != "" || context.Request.Params["invoiceDateEnd"] != "")
            {
                DateRangeType dateRange = new DateRangeType();
                dateRange.startDate = context.Request.Params["invoiceDateStart"];
                dateRange.endDate = context.Request.Params["invoiceDateEnd"];
                searchParams.invoiceDate = dateRange;
            }
            if (context.Request.Params["dueDateStart"] != "" || context.Request.Params["dueDateEnd"] != "")
            {
                DateRangeType dateRange = new DateRangeType();
                dateRange.startDate = context.Request.Params["dueDateStart"];
                dateRange.endDate = context.Request.Params["dueDateEnd"];
                searchParams.dueDate = dateRange;
            }
            if (context.Request.Params["paymentDateStart"] != "" || context.Request.Params["paymentDateEnd"] != "")
            {
                DateRangeType dateRange = new DateRangeType();
                dateRange.startDate = context.Request.Params["paymentDateStart"];
                dateRange.endDate = context.Request.Params["paymentDateEnd"];
                searchParams.paymentDate = dateRange;
            }
            if (context.Request.Params["creationDateStart"] != "" || context.Request.Params["creationDateEnd"] != "")
            {
                DateRangeType dateRange = new DateRangeType();
                dateRange.startDate = context.Request.Params["creationDateStart"];
                dateRange.endDate = context.Request.Params["creationDateEnd"];
                searchParams.creationDate = dateRange;
            }

            // Create service object and make the API call
            InvoiceService service;
            SearchInvoicesResponse response;

            try
            {
                service = getService(context);
                response = service.SearchInvoices(request);
            }
            catch (Exception e)
            {
                context.Response.Write(e.Message);
                return;
            }

            // Display response values.
            Dictionary<string, string> keyResponseParams = new Dictionary<string, string>();
            keyResponseParams.Add("API status", response.responseEnvelope.ack.ToString());
            keyResponseParams.Add("correlationId", response.responseEnvelope.correlationId);
            keyResponseParams.Add("invoice count", response.count.ToString());
            keyResponseParams.Add("hasNextPage", response.hasNextPage.ToString());
            keyResponseParams.Add("hasPreviousPage", response.hasPreviousPage.ToString());

            if (response.invoiceList != null && response.invoiceList.invoice != null)
            {
                int idx = 0;
                foreach (InvoiceSummaryType invoice in response.invoiceList.invoice)
                {
                    keyResponseParams.Add(idx + " invoice Id", invoice.invoiceID);
                    keyResponseParams.Add(idx + " invoice status", invoice.status.ToString());
                    idx++;
                }
            }
            displayResponse(context, "SearchInvoices", keyResponseParams, service.getLastRequest(),
                service.getLastResponse(), response.error, null);
        }
    // # SearchInvoices API Operation
    // Use the SearchInvoice API operation to search an invoice. 
    public SearchInvoicesResponse SearchInvoicesAPIOperation()
    {
        // Create the SearchInvoicesResponse object
        SearchInvoicesResponse responseSearchInvoices = new SearchInvoicesResponse();

        try
        {
            // # SearchInvoicesRequest
            // Use the SearchInvoiceRequest message to search an invoice.

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

            SearchParametersType parameters = new SearchParametersType();

            // Invoice amount search. It specifies the smallest amount to be
            // returned. If you pass a value for this field, you must also pass a
            // currencyCode value.
            parameters.upperAmount = Convert.ToDecimal("4.00");

            // Currency used for lower and upper amounts. It is required when you
            // specify lowerAmount or upperAmount.
            parameters.currencyCode = "USD";

            // SearchInvoicesRequest which takes mandatory params:
            // 
            // * `Request Envelope` - Information common to each API operation, such
            // as the language in which an error message is returned.
            // * `Merchant Email` - Email address of invoice creator.
            // * `SearchParameters` - Parameters constraining the search.
            // * `Page` - Page number of result set, starting with 1.
            // * `Page Size` - Number of results per page, between 1 and 100.
            SearchInvoicesRequest requestSearchInvoices = new SearchInvoicesRequest(envelopeRequest, "*****@*****.**", parameters, Convert.ToInt32("1"), Convert.ToInt32("10"));

            // Create the service wrapper object to make the API call
            InvoiceService service = new InvoiceService();

            // # API call   
            // Invoke the SearchInvoices method in service
            responseSearchInvoices = service.SearchInvoices(requestSearchInvoices);

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

                // # Success values
                if (responseSearchInvoices.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // Number of invoices that matched the request.                    
                    logger.Info("Count : " + responseSearchInvoices.count + "\n");
                    Console.WriteLine("Count : " + responseSearchInvoices.count + "\n");

                }
                // # Error Values                
                else
                {
                    List<ErrorData> errorMessages = responseSearchInvoices.error;
                    foreach (ErrorData error in errorMessages)
                    {
                        logger.Debug("API Error Message : " + error.message + "\n");
                        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 responseSearchInvoices;
    }
Esempio n. 3
0
 /**
  	  * Constructor with arguments
  	  */
 public SearchInvoicesRequest(RequestEnvelope requestEnvelope, string merchantEmail, SearchParametersType parameters, int? page, int? pageSize)
 {
     this.requestEnvelope = requestEnvelope;
     this.merchantEmail = merchantEmail;
     this.parameters = parameters;
     this.page = page;
     this.pageSize = pageSize;
 }
        /// <summary>
        /// API call example for SearchInvoices
        /// </summary>
        /// <param name="context"></param>
        private void SearchInvoices(HttpContext context)
        {
            // Collect input params

            // (Required) Email address of invoice creator.
            string merchantEmail = context.Request.Params["merchantEmail"];

            // (Required) Page number of result set, starting with 1.
            int page = Convert.ToInt32(context.Request.Params["page"]);

            // (Required) Number of results per page, between 1 and 100.
            int pageSize = Convert.ToInt32(context.Request.Params["pageSize"]);

            InvoiceModelAlias.SearchParametersType searchParams = new InvoiceModelAlias.SearchParametersType();
            InvoiceModelAlias.RequestEnvelope env = new InvoiceModelAlias.RequestEnvelope();

            // (Required) RFC 3066 language in which error messages are returned;
            // by default it is en_US, which is the only language currently supported.
            env.errorLanguage = ERROR_LANGUAGE;
            InvoiceModelAlias.SearchInvoicesRequest request = new InvoiceModelAlias.SearchInvoicesRequest(
                env, merchantEmail, searchParams, page, pageSize);

            // (Optional) Email search string.
            if (context.Request.Params["email"] != string.Empty)
            {
                searchParams.email = context.Request.Params["email"];
            }

            // (Optional) Recipient search string.
            if (context.Request.Params["recipientName"] != string.Empty)
            {
                searchParams.recipientName = context.Request.Params["recipientName"];
            }

            // (Optional) Company search string.
            if (context.Request.Params["businessName"] != string.Empty)
            {
                searchParams.businessName = context.Request.Params["businessName"];
            }

            // (Optional) Invoice number search string.
            if (context.Request.Params["invoiceNumber"] != string.Empty)
            {
                searchParams.invoiceNumber = context.Request.Params["invoiceNumber"];
            }

            // (Optional) Invoice status search.
            if (context.Request.Params["status0"] != string.Empty)
            {
                // You can add upto 10 status to do a 'OR' search on multiple status types
                searchParams.status.Add(
                    (InvoiceModelAlias.StatusType)Enum.Parse(typeof(InvoiceModelAlias.StatusType), context.Request.Params["status0"]));
            }

            // (Optional) Invoice status search.
            if (context.Request.Params["status1"] != string.Empty)
            {
                // You can add upto 10 status to do a 'OR' search on multiple status types
                searchParams.status.Add(
                    (InvoiceModelAlias.StatusType)Enum.Parse(typeof(InvoiceModelAlias.StatusType), context.Request.Params["status1"]));
            }

            // (Optional) Invoice status search.
            if (context.Request.Params["status2"] != string.Empty)
            {
                // You can add upto 10 status to do a 'OR' search on multiple status types
                searchParams.status.Add(
                    (InvoiceModelAlias.StatusType)Enum.Parse(typeof(InvoiceModelAlias.StatusType), context.Request.Params["status2"]));
            }

            // (Optional) Invoice amount search. It specifies the smallest amount to be returned.
            // If you pass a value for this field, you must also pass a currencyCode value.
            if (context.Request.Params["lowerAmount"] != string.Empty)
            {
                searchParams.lowerAmount = Convert.ToDecimal(context.Request.Params["lowerAmount"]);
            }

            // (Optional) Invoice amount search. It specifies the largest amount to be returned.
            // If you pass a value for this field, you must also pass a currencyCode value.
            if (context.Request.Params["upperAmount"] != string.Empty)
            {
                searchParams.upperAmount = Convert.ToDecimal(context.Request.Params["upperAmount"]);
            }

            // (Optional) Invoice memo search string.
            if (context.Request.Params["memo"] != string.Empty)
            {
                searchParams.memo = context.Request.Params["memo"];
            }

            // (Optional) Currency used for lower and upper amounts.
            // It is required when you specify lowerAmount or upperAmount.
            if (context.Request.Params["currencyCode"] != string.Empty)
            {
                searchParams.currencyCode = context.Request.Params["currencyCode"];
            }

            // (Optional) Indicates whether the invoice was created by the website or by an API call.
            // It is one of the following values:
            //  Web – The invoice was created on paypal.com.
            //  API – The invoice was created by an Invoicing Service API call.
            if (context.Request.Params["origin"] != string.Empty)
            {
                searchParams.origin = (InvoiceModelAlias.OriginType)
                     Enum.Parse(typeof(InvoiceModelAlias.OriginType), context.Request.Params["origin"]);
            }

            //
            if (context.Request.Params["invoiceDateStart"] != string.Empty || context.Request.Params["invoiceDateEnd"] != string.Empty)
            {
                InvoiceModelAlias.DateRangeType dateRange = new InvoiceModelAlias.DateRangeType();

                // (Optional) Start of the date range.
                dateRange.startDate = context.Request.Params["invoiceDateStart"];

                // Optional) End of the date range.
                dateRange.endDate = context.Request.Params["invoiceDateEnd"];
                searchParams.invoiceDate = dateRange;
            }

            if (context.Request.Params["dueDateStart"] != string.Empty || context.Request.Params["dueDateEnd"] != string.Empty)
            {
                InvoiceModelAlias.DateRangeType dateRange = new InvoiceModelAlias.DateRangeType();

                // (Optional) Start of the date range.
                dateRange.startDate = context.Request.Params["dueDateStart"];

                // Optional) End of the date range.
                dateRange.endDate = context.Request.Params["dueDateEnd"];
                searchParams.dueDate = dateRange;
            }
            if (context.Request.Params["paymentDateStart"] != string.Empty || context.Request.Params["paymentDateEnd"] != string.Empty)
            {
                InvoiceModelAlias.DateRangeType dateRange = new InvoiceModelAlias.DateRangeType();

                // (Optional) Start of the date range.
                dateRange.startDate = context.Request.Params["paymentDateStart"];

                // Optional) End of the date range.
                dateRange.endDate = context.Request.Params["paymentDateEnd"];
                searchParams.paymentDate = dateRange;
            }
            if (context.Request.Params["creationDateStart"] != string.Empty || context.Request.Params["creationDateEnd"] != string.Empty)
            {
                InvoiceModelAlias.DateRangeType dateRange = new InvoiceModelAlias.DateRangeType();

                // (Optional) Start of the date range.
                dateRange.startDate = context.Request.Params["creationDateStart"];

                // Optional) End of the date range.
                dateRange.endDate = context.Request.Params["creationDateEnd"];
                searchParams.creationDate = dateRange;
            }

            // Create service object and make the API call
            InvoiceAlias.InvoiceService service;
            InvoiceModelAlias.SearchInvoicesResponse response;
            SignatureCredential cred = SetThirdPartyAuthorization(context);
            try
            {
                service = GetService(context);
                if (cred != null)
                {
                    response = service.SearchInvoices(request, cred);
                }
                else
                {
                    response = service.SearchInvoices(request);
                }
            }
            catch (Exception e)
            {
                context.Response.Write(e.Message);
                return;
            }

            // Display response values.
            Dictionary<string, string> keyResponseParams = new Dictionary<string, string>();

            //Acknowledgement code. It is one of the following values:
            //Success – The operation completed successfully.
            //Failure – The operation failed.
            //SuccessWithWarning – The operation completed successfully; however, there is a warning message.
            //FailureWithWarning – The operation failed with a warning message.
            keyResponseParams.Add("API status", response.responseEnvelope.ack.ToString());

            // Correlation identifier. It is a 13-character,
            // alphanumeric string (for example, db87c705a910e) that is used
            // only by PayPal Merchant Technical Support.
            // Note: You must log and store this data for every response you receive.
            // PayPal Technical Support uses the information to assist with reported issues.
            keyResponseParams.Add("correlationId", response.responseEnvelope.correlationId);

            // Number of invoices that matched the request.
            keyResponseParams.Add("invoice count", response.count.ToString());

            // True if another page of invoice summary results exists.
            keyResponseParams.Add("hasNextPage", response.hasNextPage.ToString());

            // True if a previous page of the invoice summary results exists.
            keyResponseParams.Add("hasPreviousPage", response.hasPreviousPage.ToString());

            if (response.invoiceList != null && response.invoiceList.invoice != null)
            {
                int idx = 0;
                foreach (InvoiceModelAlias.InvoiceSummaryType invoice in response.invoiceList.invoice)
                {
                    keyResponseParams.Add(idx + " invoice Id", invoice.invoiceID);
                    keyResponseParams.Add(idx + " invoice status", invoice.status.ToString());
                    idx++;
                }
            }
            displayResponse(context, "SearchInvoices", keyResponseParams, service.getLastRequest(),
                service.getLastResponse(), response.error, null);
        }
Esempio n. 5
0
        /// <summary>
        /// API call example for SearchInvoices
        /// </summary>
        /// <param name="context"></param>
        private void SearchInvoices(HttpContext context)
        {
            // Collect input params
            String merchantEmail = context.Request.Params["merchantEmail"];
            int page = Int32.Parse(context.Request.Params["page"]);
            int pageSize = Int32.Parse(context.Request.Params["pageSize"]);
            SearchParametersType searchParams = new SearchParametersType();
            SearchInvoicesRequest request = new SearchInvoicesRequest(
                new RequestEnvelope(ERROR_LANGUAGE), merchantEmail, searchParams, page, pageSize);
            if (context.Request.Params["email"] != "")
            {
                searchParams.email = context.Request.Params["email"];
            }
            if (context.Request.Params["recipientName"] != "")
            {
                searchParams.recipientName = context.Request.Params["recipientName"];
            }
            if (context.Request.Params["businessName"] != "")
            {
                searchParams.businessName = context.Request.Params["businessName"];
            }
            if (context.Request.Params["invoiceNumber"] != "")
            {
                searchParams.invoiceNumber = context.Request.Params["invoiceNumber"];
            }
            if (context.Request.Params["status0"] != "")
            {
                // You can add upto 10 status to do a 'OR' search on multiple status types
                searchParams.status.Add(
                    (StatusType)Enum.Parse(typeof(StatusType), context.Request.Params["status0"]));
            }
            if (context.Request.Params["status1"] != "")
            {
                // You can add upto 10 status to do a 'OR' search on multiple status types
                searchParams.status.Add(
                    (StatusType)Enum.Parse(typeof(StatusType), context.Request.Params["status1"]));
            }
            if (context.Request.Params["status2"] != "")
            {
                // You can add upto 10 status to do a 'OR' search on multiple status types
                searchParams.status.Add(
                    (StatusType)Enum.Parse(typeof(StatusType), context.Request.Params["status2"]));
            }
            if (context.Request.Params["lowerAmount"] != "")
            {
                searchParams.lowerAmount = decimal.Parse(context.Request.Params["lowerAmount"]);
            }
            if (context.Request.Params["upperAmount"] != "")
            {
                searchParams.upperAmount = decimal.Parse(context.Request.Params["upperAmount"]);
            }
            if (context.Request.Params["memo"] != "")
            {
                searchParams.memo = context.Request.Params["memo"];
            }
            if (context.Request.Params["currencyCode"] != "")
            {
                searchParams.currencyCode = context.Request.Params["currencyCode"];
            }
            if (context.Request.Params["origin"] != "")
            {
                searchParams.origin = (OriginType)
                     Enum.Parse( typeof(OriginType),  context.Request.Params["origin"]);
            }
            if (context.Request.Params["invoiceDateStart"] != "" || context.Request.Params["invoiceDateEnd"] != "")
            {
                DateRangeType dateRange = new DateRangeType();
                dateRange.startDate = context.Request.Params["invoiceDateStart"];
                dateRange.endDate = context.Request.Params["invoiceDateEnd"];
                searchParams.invoiceDate = dateRange;
            }
            if (context.Request.Params["dueDateStart"] != "" || context.Request.Params["dueDateEnd"] != "")
            {
                DateRangeType dateRange = new DateRangeType();
                dateRange.startDate = context.Request.Params["dueDateStart"];
                dateRange.endDate = context.Request.Params["dueDateEnd"];
                searchParams.dueDate = dateRange;
            }
            if (context.Request.Params["paymentDateStart"] != "" || context.Request.Params["paymentDateEnd"] != "")
            {
                DateRangeType dateRange = new DateRangeType();
                dateRange.startDate = context.Request.Params["paymentDateStart"];
                dateRange.endDate = context.Request.Params["paymentDateEnd"];
                searchParams.paymentDate = dateRange;
            }
            if (context.Request.Params["creationDateStart"] != "" || context.Request.Params["creationDateEnd"] != "")
            {
                DateRangeType dateRange = new DateRangeType();
                dateRange.startDate = context.Request.Params["creationDateStart"];
                dateRange.endDate = context.Request.Params["creationDateEnd"];
                searchParams.creationDate = dateRange;
            }

            // Create service object and make the API call
            InvoiceService service = getService(context);
            SearchInvoicesResponse response = service.SearchInvoices(request);

            // Process response
            context.Response.Write("<html><body><textarea rows=30 cols=80>");
            ObjectDumper.Write(response, 5, context.Response.Output);
            context.Response.Write("</textarea></body></html>");
        }