Cancels an email or SMS notification.

See PayPal Developer documentation for more information.

Inheritance: PayPalSerializableObject
示例#1
0
        /// <summary>
        /// Cancels an invoice.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="invoiceId">ID of the invoice to cancel.</param>
        /// <param name="cancelNotification">CancelNotification</param>
        public static void Cancel(APIContext apiContext, string invoiceId, CancelNotification cancelNotification)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(invoiceId, "invoiceId");
            ArgumentValidator.Validate(cancelNotification, "cancelNotification");

            // Configure and send the request
            var pattern      = "v1/invoicing/invoices/{0}/cancel";
            var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { invoiceId });

            PayPalResource.ConfigureAndExecute(apiContext, HttpMethod.POST, resourcePath, cancelNotification.ConvertToJson());
        }
示例#2
0
 /// <summary>
 /// Cancels a sent invoice, by ID, and, optionally, sends a notification about the cancellation to the payer, merchant, and Cc: emails.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="cancelNotification">CancelNotification</param>
 public void Cancel(APIContext apiContext, CancelNotification cancelNotification)
 {
     Invoice.Cancel(apiContext, this.id, cancelNotification);
 }
示例#3
0
 /// <summary>
 /// Cancels an invoice.
 /// </summary>
 /// <param name="apiContext">APIContext used for the API call.</param>
 /// <param name="cancelNotification">CancelNotification</param>
 public void Cancel(APIContext apiContext, CancelNotification cancelNotification)
 {
     Invoice.Cancel(apiContext, this.id, cancelNotification);
 }
示例#4
0
        /// <summary>
        /// Cancels an invoice.
        /// </summary>
        /// <param name="apiContext">APIContext used for the API call.</param>
        /// <param name="invoiceId">ID of the invoice to cancel.</param>
        /// <param name="cancelNotification">CancelNotification</param>
        public static void Cancel(APIContext apiContext, string invoiceId, CancelNotification cancelNotification)
        {
            // Validate the arguments to be used in the request
            ArgumentValidator.ValidateAndSetupAPIContext(apiContext);
            ArgumentValidator.Validate(invoiceId, "invoiceId");
            ArgumentValidator.Validate(cancelNotification, "cancelNotification");

            // Configure and send the request
            var pattern = "v1/invoicing/invoices/{0}/cancel";
            var resourcePath = SDKUtil.FormatURIPath(pattern, new object[] { invoiceId });
            PayPalResource.ConfigureAndExecute(apiContext, HttpMethod.POST, resourcePath, cancelNotification.ConvertToJson());
        }
        public async Task<IHttpActionResult> Delete(int id, string email)
        {
            var order = await repository.RetrieveAsync(id);
            if (order == null)
            {
                return NotFound();
            }
            var payment = order.Payments.First();
            if (payment.PaymentType != PaymentType.PendingInvoice)
            {
                return NotFound();
            }

            //retrieve previous invoice
            APIContext apiContext = PaypalConfiguration.GetAPIContext();
            InvoiceDetails details = JsonConvert.DeserializeObject<InvoiceDetails>(payment.PaymentDetails);
            try
            {
                //check if old invoice is still valid
                var invoice = Invoice.Get(apiContext, details.id);

                //cancel invoice
                var cancelNotification = new CancelNotification
                {
                    subject = "Payment Canceled",
                    note = "The payment has been canceled.",
                    send_to_merchant = true,
                    send_to_payer = true
                };
                invoice.Cancel(apiContext, cancelNotification);
            }
            catch(Exception e)
            {
                //not valid, keep on trucking!
            }

            //create newinvoice
            Invoice newInvoice = CreateInvoice(email, order);

            newInvoice.id = order.OrderID.ToString();

            try
            {
                var createdInvoice = newInvoice.Create(apiContext);
                createdInvoice.Send(apiContext, true);

                var invoiceDetails = new
                {
                    id = createdInvoice.id,
                    email = email
                };

                payment.PaymentDetails = JsonConvert.SerializeObject(invoiceDetails);

                await repository.UpdateAsync(order, order.OrderID);
                return Ok(new { OrderID = order.OrderID });
            }
            catch (Exception ex)
            {
                await Logger.WriteLog(LogType.Error, ex.ToString());
                throw ex;
            }
        }
        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

            // Setup the cancellation notice.
            var cancelNotification = new CancelNotification
            {
                subject = "Payment Canceled",
                note = "The payment has been canceled.",
                send_to_merchant = true,
                send_to_payer = true
            };

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Send the cancellation notice", cancelNotification);
            #endregion

            createdInvoice.Cancel(apiContext, cancelNotification);

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

            // For more information, please visit [PayPal Developer REST API Reference](https://developer.paypal.com/docs/api/).
        }