This specifies the list of parameters with every request to the service.
        /// <summary>
        /// API call example for MarkInvoiceAsUnpaid
        /// </summary>
        /// <param name="context"></param>
        private void MarkInvoiceAsUnpaid(HttpContext context)
        {
            // Collect input params
            // (Required) ID of the invoice to mark as unpaid.
            string invoiceId = context.Request.Params["invoiceId"];
            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.MarkInvoiceAsUnpaidRequest request =
                new InvoiceModelAlias.MarkInvoiceAsUnpaidRequest(env, invoiceId);

            // Create service object and make the API call
            InvoiceAlias.InvoiceService service;
            InvoiceModelAlias.MarkInvoiceAsUnpaidResponse response;
            SignatureCredential cred = SetThirdPartyAuthorization(context);
            try
            {
                service = GetService(context);
                if (cred != null)
                {
                    response = service.MarkInvoiceAsUnpaid(request, cred);
                }
                else
                {
                    response = service.MarkInvoiceAsUnpaid(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);

            // ID of the invoice marked as unpaid.
            keyResponseParams.Add("invoiceId", response.invoiceID);

            // Number of the invoice marked as unpaid.
            keyResponseParams.Add("invoiceNumber", response.invoiceNumber);

            // URL location where merchants view the invoice details.
            keyResponseParams.Add("invoiceUrl", response.invoiceURL);
            displayResponse(context, "MarkInvoiceAsUnpaid", keyResponseParams, service.getLastRequest(),
                service.getLastResponse(), response.error, null);
        }
        /// <summary>
        /// API call example for UpdateInvoice
        /// </summary>
        /// <param name="context"></param>
        private void UpdateInvoice(HttpContext context)
        {
            // Collect input params

            // (Required) ID of the invoice to update.
            string invoiceId = context.Request.Params["invoiceId"];

            // (Required) Merchant email address.
            string merchantEmail = context.Request.Params["merchantEmail"];

            // (Required) Payer email address.
            string payerEmail = context.Request.Params["payerEmail"];

            // (Required) Terms by which the invoice payment is due. It is one of the following values:
            // DueOnReceipt – Payment is due when the payer receives the invoice.
            // DueOnDateSpecified – Payment is due on the date specified in the invoice.
            // Net10 – Payment is due 10 days from the invoice date.
            // Net15 – Payment is due 15 days from the invoice date.
            // Net30 – Payment is due 30 days from the invoice date.
            // Net45 – Payment is due 45 days from the invoice date.
            InvoiceModelAlias.PaymentTermsType paymentTerms = (InvoiceModelAlias.PaymentTermsType)Enum.Parse(
                    typeof(InvoiceModelAlias.PaymentTermsType), context.Request.Params["paymentTerms"]);

            // (Required) SKU or name of the item. Character length and limitations: 30 characters maximum
            string item_name1 = context.Request.Params["item_name1"];

            // (Required) Item count. Valid values are 0 to 10.000.
            string item_quantity1 = context.Request.Params["item_quantity1"];

            // (Required) Price of the item, in the currency specified by the invoice.
            string item_unitPrice1 = context.Request.Params["item_unitPrice1"];

            // (Required) SKU or name of the item. Character length and limitations: 30 characters maximum
            string item_name2 = context.Request.Params["item_name2"];

            // (Required) Item count. Valid values are 0 to 10.000.
            string item_quantity2 = context.Request.Params["item_quantity2"];

            // (Required) Price of the item, in the currency specified by the invoice.
            string item_unitPrice2 = context.Request.Params["item_unitPrice2"];

            // (Required) Currency used for all invoice item amounts and totals.
            string currencyCode = context.Request.Params["currencyCode"];

            InvoiceModelAlias.InvoiceItemListType itemList = new InvoiceModelAlias.InvoiceItemListType();
            itemList.item = new List<InvoiceModelAlias.InvoiceItemType>();
            itemList.item.Add(new InvoiceModelAlias.InvoiceItemType(
                        item_name1,
                        Convert.ToDecimal(item_quantity1),
                        Convert.ToDecimal(item_unitPrice1)));
            itemList.item.Add(new InvoiceModelAlias.InvoiceItemType(
                        item_name2,
                        Convert.ToDecimal(item_quantity2),
                        Convert.ToDecimal(item_unitPrice2)));
            InvoiceModelAlias.InvoiceType invoice = new InvoiceModelAlias.InvoiceType(merchantEmail, payerEmail, itemList,
                currencyCode);
            invoice.paymentTerms = paymentTerms;
            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.UpdateInvoiceRequest request = new InvoiceModelAlias.UpdateInvoiceRequest(
               env, invoiceId, invoice);

            // Create service object and make the API call
            InvoiceAlias.InvoiceService service;
            InvoiceModelAlias.UpdateInvoiceResponse response;
            SignatureCredential cred = SetThirdPartyAuthorization(context);
            try
            {
                service = GetService(context);
                if (cred != null)
                {
                    response = service.UpdateInvoice(request, cred);
                }
                else
                {
                    response = service.UpdateInvoice(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);

            // ID of the updated invoice.
            keyResponseParams.Add("invoiceId", response.invoiceID);

            // Invoice number of the updated invoice.
            keyResponseParams.Add("invoiceNumber", response.invoiceNumber);

            // URL location where merchants view the updated invoice details.
            keyResponseParams.Add("invoiceUrl", response.invoiceURL);

            // The total amount of the invoice.
            keyResponseParams.Add("totalAmount", response.totalAmount.ToString());
            displayResponse(context, "UpdateInvoice", keyResponseParams, service.getLastRequest(),
                service.getLastResponse(), response.error, null);
        }
        /// <summary>
        /// API call example for MarkInvoiceAsPaid
        /// </summary>
        /// <param name="context"></param>
        private void MarkInvoiceAsPaid(HttpContext context)
        {
            // Collect input params
            // (Required) ID of the invoice to mark as paid.
            string invoiceId = context.Request.Params["invoiceId"];

            // (Optional) Optional note associated with the payment.
            string note = context.Request.Params["note"];

            //  (Required) Date when the invoice was paid.
            string paymentDate = context.Request.Params["paymentDate"];

            //(Optional) Method that can be used to mark an invoice as paid when the payer pays offline.
            // It is one of the following values:
            //BankTransfer – Payment is made by a bank transfer.
            //Cash – Payment is made in cash.
            //Check – Payment is made by check.
            //CreditCard – Payment is made by a credit card.
            //DebitCard – Payment is made by a debit card.
            //Other – Payment is made by a method not specified in this list.
            //PayPal – Payment is made by PayPal.
            //WireTransfer – Payment is made by a wire transfer.
            string paymentMethod = context.Request.Params["paymentMethod"];

            InvoiceModelAlias.OtherPaymentDetailsType paymentDetails = new InvoiceModelAlias.OtherPaymentDetailsType();
            if (note != string.Empty)
            {
                paymentDetails.note = note;
            }
            if (paymentDate != string.Empty)
            {
                paymentDetails.date = paymentDate;
            }
            if (paymentMethod != string.Empty)
            {
                paymentDetails.method =
                    (InvoiceModelAlias.PaymentMethodsType)Enum.Parse(typeof(InvoiceModelAlias.PaymentMethodsType), paymentMethod);
            }
            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.MarkInvoiceAsPaidRequest request =
                new InvoiceModelAlias.MarkInvoiceAsPaidRequest(env, invoiceId, paymentDetails);

            // Create service object and make the API call

            InvoiceModelAlias.MarkInvoiceAsPaidResponse response;
            InvoiceAlias.InvoiceService service;
            SignatureCredential cred = SetThirdPartyAuthorization(context);
            try
            {
                service = GetService(context);
                if (cred != null)
                {
                    response = service.MarkInvoiceAsPaid(request, cred);
                }
                else
                {
                    response = service.MarkInvoiceAsPaid(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);

            //  ID of the invoice marked as paid.
            keyResponseParams.Add("invoiceId", response.invoiceID);

            // Number of the invoice marked as paid.
            keyResponseParams.Add("invoiceNumber", response.invoiceNumber);

            // URL location where merchants view the invoice details.
            keyResponseParams.Add("invoiceUrl", response.invoiceURL);
            displayResponse(context, "MarkInvoiceAsPaid", keyResponseParams, service.getLastRequest(),
                service.getLastResponse(), response.error, null);
        }
Exemple #4
0
 /**
  	  * Constructor with arguments
  	  */
 public UpdateInvoiceRequest(RequestEnvelope requestEnvelope, string invoiceID, InvoiceType invoice)
 {
     this.requestEnvelope = requestEnvelope;
     this.invoiceID = invoiceID;
     this.invoice = invoice;
 }
Exemple #5
0
 /**
  	  * Constructor with arguments
  	  */
 public CancelInvoiceRequest(RequestEnvelope requestEnvelope)
 {
     this.requestEnvelope = requestEnvelope;
 }
    // # 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;
    }
    // # CreateAndSendInvoice API Operation 
    // Use the CreateAndSendInvoice API operation to create and send an invoice.   
    public CreateAndSendInvoiceResponse CreateAndSendInvoiceAPIOperation()
    {
        // Create the CreateAndSendInvoiceResponse object
        CreateAndSendInvoiceResponse responseCreateAndSendInvoice = new CreateAndSendInvoiceResponse();

        try
        {
            // # CreateAndSendInvoiceRequest
            // Use the CreateAndSendInvoiceRequest message to create and send a new
            // invoice. The requester should authenticate the caller and verify that
            // the merchant requesting the invoice has an existing PayPal account in
            // good standing. Once the invoice is created, PayPal sends it to the
            // specified payer, who is notified 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";

            List<InvoiceItemType> invoiceItemList = new List<InvoiceItemType>();

            // InvoiceItemType which takes mandatory params:
            // 
            // * `Item Name` - SKU or name of the item.
            // * `Quantity` - Item count.
            // * `Amount` - Price of the item, in the currency specified by the
            // invoice.
            InvoiceItemType invoiceItem = new InvoiceItemType("Item", Convert.ToDecimal("2"), Convert.ToDecimal("4.00"));
            invoiceItemList.Add(invoiceItem);

            // Invoice item.
            InvoiceItemListType itemList = new InvoiceItemListType(invoiceItemList);

            // InvoiceType which takes mandatory params:
            // 
            // * `Merchant Email` - Merchant email address.
            // * `Personal Email` - Payer email address.
            // * `InvoiceItemList` - List of items included in this invoice.
            // * `CurrencyCode` - Currency used for all invoice item amounts and
            // totals.
            // * `PaymentTerms` - Terms by which the invoice payment is due. It is
            // one of the following values:
            //  * DueOnReceipt - Payment is due when the payer receives the invoice.
            //  * DueOnDateSpecified - Payment is due on the date specified in the
            //  invoice.
            //  * Net10 - Payment is due 10 days from the invoice date.
            //  * Net15 - Payment is due 15 days from the invoice date.
            //  * Net30 - Payment is due 30 days from the invoice date.
            //  * Net45 - Payment is due 45 days from the invoice date.
            InvoiceType invoice = new InvoiceType("*****@*****.**", "*****@*****.**", itemList, "USD", PaymentTermsType.DUEONRECEIPT);

            // CreateAndSendInvoiceRequest which takes mandatory params:
            // 
            // * `Request Envelope` - Information common to each API operation, such
            // as the language in which an error message is returned.
            // * `Invoice` - Merchant, payer, and invoice information.
            CreateAndSendInvoiceRequest requestCreateAndSendInvoice = new CreateAndSendInvoiceRequest(envelopeRequest, invoice);

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

            // # API call 
            // Invoke the CreateAndSendInvoice method in service
            responseCreateAndSendInvoice = service.CreateAndSendInvoice(requestCreateAndSendInvoice);

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

                // # Success values
                if (responseCreateAndSendInvoice.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // ID of the created invoice.
                    logger.Info("Invoice ID : " + responseCreateAndSendInvoice.invoiceID + "\n");
                    Console.WriteLine("Invoice ID : " + responseCreateAndSendInvoice.invoiceID + "\n");
                }
                // # Error Values			
                else
                {
                    List<ErrorData> errorMessages = responseCreateAndSendInvoice.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 responseCreateAndSendInvoice;
    }
Exemple #8
0
 /**
  	  * Constructor with arguments
  	  */
 public MarkInvoiceAsRefundedRequest(RequestEnvelope requestEnvelope, string invoiceID, OtherPaymentRefundDetailsType refundDetail)
 {
     this.requestEnvelope = requestEnvelope;
     this.invoiceID = invoiceID;
     this.refundDetail = refundDetail;
 }
Exemple #9
0
 /**
  	  * Constructor with arguments
  	  */
 public MarkInvoiceAsUnpaidRequest(RequestEnvelope requestEnvelope, string invoiceID)
 {
     this.requestEnvelope = requestEnvelope;
     this.invoiceID = invoiceID;
 }
Exemple #10
0
 /**
  	  * Constructor with arguments
  	  */
 public GetInvoiceDetailsRequest(RequestEnvelope requestEnvelope, string invoiceID)
 {
     this.requestEnvelope = requestEnvelope;
     this.invoiceID = invoiceID;
 }
Exemple #11
0
 /**
  	  * Constructor with arguments
  	  */
 public MarkInvoiceAsPaidRequest(RequestEnvelope requestEnvelope, string invoiceID, OtherPaymentDetailsType payment)
 {
     this.requestEnvelope = requestEnvelope;
     this.invoiceID = invoiceID;
     this.payment = payment;
 }
Exemple #12
0
 /**
  	  * Constructor with arguments
  	  */
 public CreateInvoiceRequest(RequestEnvelope requestEnvelope, InvoiceType invoice)
 {
     this.requestEnvelope = requestEnvelope;
     this.invoice = invoice;
 }
 /// <summary>
 /// Constructor with arguments
 /// </summary>
 public GetInvoiceDetailsRequest(RequestEnvelope requestEnvelope)
 {
     this.requestEnvelope = requestEnvelope;
 }
 /// <summary>
 /// Constructor with arguments
 /// </summary>
 public GenerateInvoiceNumberRequest(RequestEnvelope requestEnvelope)
 {
     this.requestEnvelope = requestEnvelope;
 }
        /// <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);
        }
Exemple #16
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;
 }
    // # GetInvoiceDetails API Operation
    // Use the GetInvoiceDetails API operation to get detailed information about an invoice.
    public GetInvoiceDetailsResponse GetInvoiceDetailsAPIOperation()
    {
        // Create the GetInvoiceDetailsResponse object;
        GetInvoiceDetailsResponse responseGetInvoiceDetails = new GetInvoiceDetailsResponse();

        try
        {
            // # GetInvoiceDetailsRequest
            // Use the GetInvoiceDetailsRequest message to get detailed information
            // about 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";

            // GetInvoiceDetailsRequest 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 retrieve.
            GetInvoiceDetailsRequest getInvoiceDetailsRequest = new GetInvoiceDetailsRequest(envelopeRequest, "INV2-ZC9R-X6MS-RK8H-4VKJ");

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

            // # API call  
            // Invoke the GetInvoiceDetails method
            responseGetInvoiceDetails = service.GetInvoiceDetails(getInvoiceDetailsRequest);

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

                // # Success values
                if (responseGetInvoiceDetails.responseEnvelope.ack.ToString().Trim().ToUpper().Equals("SUCCESS"))
                {
                    // Status of the invoice searched.
                    logger.Info("Status : " + responseGetInvoiceDetails.invoiceDetails.status + "\n");
                    Console.WriteLine("Status : " + responseGetInvoiceDetails.invoiceDetails.status + "\n");

                }
                // # Error Values                
                else
                {
                    List<ErrorData> errorMessages = responseGetInvoiceDetails.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 responseGetInvoiceDetails;
    }
Exemple #18
0
 /**
  	  * Constructor with arguments
  	  */
 public SendInvoiceRequest(RequestEnvelope requestEnvelope, string invoiceID)
 {
     this.requestEnvelope = requestEnvelope;
     this.invoiceID = invoiceID;
 }
Exemple #19
0
        public void requestEnvelopeSerialization()
        {
            RequestEnvelope env = new RequestEnvelope("en_US");
            Assert.AreEqual("errorLanguage=en_US&", env.ToNVPString(""));
            Assert.AreEqual("requestEnvelope.errorLanguage=en_US&", env.ToNVPString("requestEnvelope."));

            env.detailLevel = DetailLevelCode.RETURNALL;
            Assert.AreEqual("requestEnvelope.detailLevel=ReturnAll&requestEnvelope.errorLanguage=en_US&",
                                                                    env.ToNVPString("requestEnvelope."));
        }
    // # 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;
    }