Create() public method

public Create ( APIContext apiContext ) : Invoice
apiContext APIContext APIContext used for the API call.
return Invoice
Example #1
0
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <returns>Invoice</returns>
 public Invoice Create(APIContext apiContext)
 {
     return(Invoice.Create(apiContext, this));
 }
        protected override void RunSample()
        {
            // ### Api Context
            // Pass in a `APIContext` object to authenticate 
            // the call and to send a unique request id 
            // (that ensures idempotency). The SDK generates
            // a request id if you do not pass one explicitly. 
            // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
            var apiContext = Configuration.GetAPIContext();

            // ### Create an invoice
            // For demonstration purposes, we will create a new invoice for this sample.
            var invoice = new Invoice()
            {
                // #### Merchant Information
                // Information about the merchant who is sending the invoice.
                merchant_info = new MerchantInfo()
                {
                    email = "*****@*****.**",
                    first_name = "Dennis",
                    last_name = "Doctor",
                    business_name = "Medical Professionals, LLC",
                    phone = new Phone()
                    {
                        country_code = "001",
                        national_number = "4083741550"
                    },
                    address = new InvoiceAddress()
                    {
                        line1 = "1234 Main St.",
                        city = "Portland",
                        state = "OR",
                        postal_code = "97217",
                        country_code = "US"
                    }
                },
                // #### Billing Information
                // Email address of invoice recipient and optional billing information.
                // > Note: PayPal currently only allows one recipient.
                billing_info = new List<BillingInfo>()
                {
                    new BillingInfo()
                    {
                        // **(Required)** Email address of the invoice recipient.
                        email = "*****@*****.**"
                    }
                },
                // #### Invoice Items
                // List of items to be included in the invoice.
                // > Note: 100 max per invoice.
                items = new List<InvoiceItem>()
                {
                    new InvoiceItem()
                    {
                        name = "Sutures",
                        quantity = 100,
                        unit_price = new Currency()
                        {
                            currency = "USD",
                            value = "5"
                        }
                    }
                },
                // #### Invoice Note
                // Note to the payer. Maximum length is 4000 characters.
                note = "Medical Invoice 16 Jul, 2013 PST",
                // #### Payment Term
                // **(Optional)** Specifies the payment deadline for the invoice.
                // > Note: Either `term_type` or `due_date` can be sent, **but not both.**
                payment_term = new PaymentTerm()
                {
                    term_type = "NET_30"
                },
                // #### Shipping Information
                // Shipping information for entities to whom items are being shipped.
                shipping_info = new ShippingInfo()
                {
                    first_name = "Sally",
                    last_name = "Patient",
                    business_name = "Not applicable",
                    address = new InvoiceAddress()
                    {
                        line1 = "1234 Broad St.",
                        city = "Portland",
                        state = "OR",
                        postal_code = "97216",
                        country_code = "US"
                    }
                }
            };

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Create the invoice", invoice);
            #endregion

            // ### Create the invoice
            var createdInvoice = invoice.Create(apiContext);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordResponse(createdInvoice);
            #endregion

            // ### API issue workaround (PPTIPS-1932)
            // Temporary work around for Invoicing API - the API is populating
            // information in the invoice that it should not be since we didn't
            // specify it originally.
            createdInvoice.billing_info[0].address = null;
            createdInvoice.discount = null;
            createdInvoice.payment_term.due_date = null;

            // ### Apply some changes
            // Apply some changes to the invoice. For this sample, we will
            // change the `term_type` to `NET_45` indicating we want to change
            // when the payment is due from the original 30 days to 45 days.
            createdInvoice.payment_term.term_type = "NET_45";

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Update the invoice", createdInvoice);
            #endregion

            // ### Update the invoice
            var updatedInvoice = createdInvoice.Update(apiContext);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordResponse(updatedInvoice);
            #endregion

            // For more information, please visit [PayPal Developer REST API Reference](https://developer.paypal.com/docs/api/).
        }
        protected override void RunSample()
        {
            // ### Api Context
            // Pass in a `APIContext` object to authenticate 
            // the call and to send a unique request id 
            // (that ensures idempotency). The SDK generates
            // a request id if you do not pass one explicitly. 
            // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
            var apiContext = Configuration.GetAPIContext();

            // ### Create an invoice
            // For demonstration purposes, we will create a new invoice for this sample.
            var invoice = new Invoice()
            {
                // #### Merchant Information
                // Information about the merchant who is sending the invoice.
                merchant_info = new MerchantInfo()
                {
                    email = "*****@*****.**",
                    first_name = "Dennis",
                    last_name = "Doctor",
                    business_name = "Medical Professionals, LLC",
                    phone = new Phone()
                    {
                        country_code = "001",
                        national_number = "4083741550"
                    },
                    address = new InvoiceAddress()
                    {
                        line1 = "1234 Main St.",
                        city = "Portland",
                        state = "OR",
                        postal_code = "97217",
                        country_code = "US"
                    }
                },
                // #### Billing Information
                // Email address of invoice recipient and optional billing information.
                // > Note: PayPal currently only allows one recipient.
                billing_info = new List<BillingInfo>()
                {
                    new BillingInfo()
                    {
                        // **(Required)** Email address of the invoice recipient.
                        email = "*****@*****.**"
                    }
                },
                // #### Invoice Items
                // List of items to be included in the invoice.
                // > Note: 100 max per invoice.
                items = new List<InvoiceItem>()
                {
                    new InvoiceItem()
                    {
                        name = "Sutures",
                        quantity = 100,
                        unit_price = new Currency()
                        {
                            currency = "USD",
                            value = "5"
                        }
                    }
                },
                // #### Invoice Note
                // Note to the payer. Maximum length is 4000 characters.
                note = "Medical Invoice 16 Jul, 2013 PST",
                // #### Payment Term
                // **(Optional)** Specifies the payment deadline for the invoice.
                // > Note: Either `term_type` or `due_date` can be sent, **but not both.**
                payment_term = new PaymentTerm()
                {
                    term_type = "NET_30"
                },
                // #### Shipping Information
                // Shipping information for entities to whom items are being shipped.
                shipping_info = new ShippingInfo()
                {
                    first_name = "Sally",
                    last_name = "Patient",
                    business_name = "Not applicable",
                    address = new InvoiceAddress()
                    {
                        line1 = "1234 Broad St.",
                        city = "Portland",
                        state = "OR",
                        postal_code = "97216",
                        country_code = "US"
                    }
                }
            };

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Create the invoice", invoice);
            #endregion

            // Create the invoice
            var createdInvoice = invoice.Create(apiContext);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordResponse(createdInvoice);
            this.flow.AddNewRequest("Send the invoice", createdInvoice);
            #endregion

            // Send the created invoice
            createdInvoice.Send(apiContext);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordActionSuccess("Invoice sent successfully.");
            #endregion

            // Use the `PaymentDetail` object to specify the details of the payment.
            var paymentDetail = new PaymentDetail
            {
                method = "CASH",
                date = "2014-07-06 03:30:00 PST",
                note = "Cash received."
            };

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Mark the invoice as paid", paymentDetail);
            #endregion

            // Mark the invoice as paid.
            createdInvoice.RecordPayment(apiContext, paymentDetail);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordActionSuccess("Invoice successfully updated.");
            #endregion

            // Use the `PaymentDetail` object to specify the details of the payment.
            var refundDetail = new RefundDetail
            {
                date = "2014-07-06 03:30:00 PST",
                note = "Refund provided by cash."
            };

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Mark the invoice as refunded", refundDetail);
            #endregion

            createdInvoice.RecordRefund(apiContext, refundDetail);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordActionSuccess("Invoice successfully updated.");
            #endregion

            // For more information, please visit [PayPal Developer REST API Reference](https://developer.paypal.com/docs/api/).
        }
        public void CreatePayPalInvoice(int orderId)
        {
            var config      = ConfigManager.Instance.GetProperties();
            var accessToken = new OAuthTokenCredential(config).GetAccessToken();
            var apiContext  = new APIContext(accessToken);

            List <PackingSlipModel> order = dbConnect.GetPackingListInfo(orderId).ToList();

            List <InvoiceItem> items = order.Select(od => new InvoiceItem()
            {
                description     = od.Description,
                name            = od.Description,
                quantity        = od.Quantity,
                unit_of_measure = "QUANTITY",
                unit_price      = new Currency()
                {
                    currency = "USD", value = od.Price.ToString()
                }
            }).ToList();

            var invoice = new PayPal.Api.Invoice()
            {
                merchant_info = new MerchantInfo()
                {
                    address = new InvoiceAddress()
                    {
                        city         = "San Tan Valley",
                        country_code = "US",
                        state        = "AZ",
                        line1        = "440 E Cayon Rock Rd",
                        postal_code  = "85143",
                        phone        = new Phone()
                        {
                            national_number = "480-326-5306", country_code = "+1"
                        }
                    },
                    business_name = "The Ivey Way Designs",
                    email         = "*****@*****.**"
                },
                billing_info = new List <BillingInfo>()
                {
                    new BillingInfo()
                    {
                        email      = "*****@*****.**",
                        first_name = order[0].Name.Substring(0, order[0].Name.IndexOf(' ')),
                        last_name  = order[0].Name.Substring(order[0].Name.IndexOf(' ')),
                        address    = new InvoiceAddress()
                        {
                            city         = order[0].City,
                            country_code = "US",
                            state        = order[0].State,
                            line1        = order[0].Address,
                            postal_code  = order[0].ZipCode,
                            phone        = new Phone()
                            {
                                national_number = order[0].PhoneNumber, country_code = "+1"
                            }
                        }
                    }
                },
                //invoice_date = D),
                reference = "Order Number " + order[0].OrderNumber,

                shipping_cost = new ShippingCost()
                {
                    amount = new Currency()
                    {
                        currency = "USD", value = "5.00"
                    }
                },
                shipping_info = new ShippingInfo()
                {
                    address = new InvoiceAddress()
                    {
                        city         = order[0].City,
                        country_code = "US",
                        state        = order[0].State,
                        line1        = order[0].Address,
                        postal_code  = order[0].ZipCode,
                        phone        = new Phone()
                        {
                            national_number = order[0].PhoneNumber, country_code = "+1"
                        }
                    },
                    first_name = order[0].Name.Substring(0, order[0].Name.IndexOf(' ')),
                    last_name  = order[0].Name.Substring(order[0].Name.IndexOf(' '))
                },
                total_amount = new Currency()
                {
                    currency = "USD", value = order[0].OrderTotal.ToString()
                },
                items = items
            };

            try
            {
                var test = invoice.Create(apiContext);
                invoice.id = test.id;
                invoice.Send(apiContext);
            }
            catch (PayPal.PaymentsException ex)
            {
            }
        }