Inheritance: PayPal.BasePayPalService
Exemplo n.º 1
0
        public void CreateAndSendInvoiceTest()
        {
            CreateAndSendInvoiceRequest cr = new CreateAndSendInvoiceRequest();
            cr.requestEnvelope = new RequestEnvelope();
            cr.requestEnvelope.errorLanguage = "en_US";
            cr.requestEnvelope.detailLevel = DetailLevelCode.RETURNALL;

            cr.invoice = new InvoiceType();
            cr.invoice.currencyCode = "USD";
            cr.invoice.merchantEmail = "*****@*****.**";
            cr.invoice.payerEmail = "*****@*****.**";
            cr.invoice.paymentTerms = PaymentTermsType.DUEONRECEIPT;

            cr.invoice.itemList = new InvoiceItemListType();
            cr.invoice.itemList.item = new List<InvoiceItemType>();
            cr.invoice.itemList.item.Add(new InvoiceItemType());
            cr.invoice.itemList.item[0].name = "product1";
            cr.invoice.itemList.item[0].quantity = 10;
            cr.invoice.itemList.item[0].unitPrice = 2;
            CreateAndSendInvoiceResponse cir = null;

            try
            {
                InvoiceService service = new InvoiceService();
                cir = service.CreateAndSendInvoice(cr);
            }
            catch (System.Exception e)
            {
                Console.Write(e.Message);
                Assert.Fail(e.Message);
            }

            Assert.AreEqual(AckCode.SUCCESS, cir.responseEnvelope.ack);
            Assert.IsNotNull(cir.invoiceNumber);
            Assert.IsNotNull(cir.invoiceID);
        }
Exemplo n.º 2
0
 private InvoiceService getService(HttpContext context)
 {
     InvoiceService service = new InvoiceService();
     if (context.Request.Params["authentication"] != null)
     {
         service.setAccessToken(context.Request.Params["accessToken"]);
         service.setAccessTokenSecret(context.Request.Params["tokenSecret"]);
     }
     if (context.Request.Params["permission$authentication"] != null)
     {
         service.setAccessToken(context.Request.Params["permission$accessToken"]);
         service.setAccessTokenSecret(context.Request.Params["permission$tokenSecret"]);
     }
     return service;
 }
Exemplo n.º 3
0
        public void CreateInvoiceForThirdPartyTest()
        {
            CreateInvoiceResponse cir = null;
            try
            {
                InvoiceService service = new InvoiceService();
                service.setAccessToken("MflQEeAERGJPxdFYxkH29I53S5Ahcsimnv7fwa14n8x985-ugCgTSA");
                service.setAccessTokenSecret("kQE-WPNw2n6soaxftD-1I8Nm0Ss");

                this.cr.invoice.merchantEmail = "*****@*****.**";
                cir = service.CreateInvoice(this.cr);
                Assert.AreEqual(AckCode.SUCCESS, cir.responseEnvelope.ack);
                Assert.IsNotNull(cir.invoiceID);
                Assert.IsNotNull(cir.invoiceNumber);
            }
            catch (System.Exception e)
            {
                Console.Write(e.Message);
                Assert.Fail(e.Message);
            }
        }
Exemplo n.º 4
0
        public void SendInvoiceTest()
        {
            SendInvoiceRequest sr = new SendInvoiceRequest();
            sr.requestEnvelope = new RequestEnvelope();
            sr.requestEnvelope.errorLanguage = "en_US";
            sr.requestEnvelope.detailLevel = DetailLevelCode.RETURNALL;

            SendInvoiceResponse sir = null;
            CreateInvoiceResponse cir = null;

            try
            {
                InvoiceService service = new InvoiceService();

                cir = service.CreateInvoice(this.cr);
                Assert.AreEqual(AckCode.SUCCESS, cir.responseEnvelope.ack);

                sr.invoiceID = cir.invoiceID;
                sir = service.SendInvoice(sr);
            }
            catch (System.Exception e)
            {
                Console.Write(e.Message);
                Assert.Fail(e.Message);
            }

            Assert.AreEqual(AckCode.SUCCESS, sir.responseEnvelope.ack);
            Assert.AreEqual(cir.invoiceID, sir.invoiceID);
        }
    // # 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;
    }
Exemplo n.º 6
0
 public void CreateInvoiceTest()
 {
     CreateInvoiceResponse cir = null;
     try
     {
         InvoiceService service = new InvoiceService();
         cir = service.CreateInvoice(this.cr);
         Assert.AreEqual(AckCode.SUCCESS, cir.responseEnvelope.ack);
         Assert.IsNotNull(cir.invoiceID);
         Assert.IsNotNull(cir.invoiceNumber);
     }
     catch (System.Exception e)
     {
         Console.Write(e.Message);
         Assert.Fail(e.Message);
     }
 }
    // # 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;
    }
        private InvoiceAlias.InvoiceService GetService(HttpContext context)
        {
            // Configuration map containing signature credentials and other required configuration.
            // For a full list of configuration parameters refer in wiki page
            // [https://github.com/paypal/sdk-core-dotnet/wiki/SDK-Configuration-Parameters]
            Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig();

            // Creating service wrapper object to make an API call by loading configuration map.
            InvoiceAlias.InvoiceService service = new InvoiceAlias.InvoiceService(configurationMap);

            return service;
        }
    // # 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;
    }
Exemplo n.º 10
0
        public void CreateInvoiceForThirdPartyTest()
        {
            CreateInvoiceResponse cir = null;
            try
            {
                InvoiceService service = new InvoiceService();
                service.setAccessToken("ih5acEwTvGxOGpvd4oSymRbHLvP4CccdqEvpEZmLO8uIk2C036.qqA");
                service.setAccessTokenSecret("i2mh1RUEMEHW2RfmawBPWeBfVK8");

                this.cr.invoice.merchantEmail = "*****@*****.**";
                cir = service.CreateInvoice(this.cr);
                Assert.AreEqual(AckCode.SUCCESS, cir.responseEnvelope.ack);
                Assert.IsNotNull(cir.invoiceID);
                Assert.IsNotNull(cir.invoiceNumber);
            }
            catch (System.Exception e)
            {
                Console.Write(e.Message);
                Assert.Fail(e.Message);
            }
        }
    // # 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;
    }