/// <summary>
 /// Records a response in the last RequestFlowItem stored in the Items list.
 /// </summary>
 /// <param name="responseObject"></param>
 public void RecordResponse(IPayPalSerializableObject responseObject)
 {
     if (responseObject != null && this.Items.Any())
     {
         this.Items.Last().Response = PayPalCommon.FormatJsonString(responseObject.ConvertToJson());
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Records an exception encountered during this portion of the flow.
        /// </summary>
        /// <param name="ex">The exception to be recorded.</param>
        public void RecordException(Exception ex)
        {
            this.IsErrorResponse = true;

            if (ex is ConnectionException)
            {
                this.Response = PayPalCommon.FormatJsonString(((ConnectionException)ex).Response);
                if (string.IsNullOrEmpty(ex.Message))
                {
                    this.RecordError(string.Format("Error thrown from SDK as type {0}.", ex.GetType().ToString()));
                }
                else
                {
                    this.RecordError(ex.Message);
                }
            }
            else if (ex is PayPalException && ex.InnerException != null)
            {
                this.RecordError(ex.InnerException.Message);
            }
            else
            {
                this.RecordError(ex.Message);
            }
        }
 /// <summary>
 /// Adds a new RequestFlowItem to the list of Items.
 /// </summary>
 /// <param name="title">Title of this flow item.</param>
 /// <param name="requestObject">(Optional) The object used for the request.</param>
 /// <param name="description">(Optional) The description of the request.</param>
 public void AddNewRequest(string title, IPayPalSerializableObject requestObject = null, string description = "")
 {
     this.Items.Add(new RequestFlowItem()
     {
         Request     = requestObject == null ? string.Empty : PayPalCommon.FormatJsonString(requestObject.ConvertToJson()),
         Title       = title,
         Description = description
     });
 }
Esempio n. 4
0
        protected override void RunSample()
        {
            var apiContext = PayPalConfig.GetAPIContext();

            // A transaction defines the contract of a payment.
            var transaction = new Transaction()
            {
                amount = new Amount()
                {
                    currency = "USD",
                    total    = "7",
                    details  = new Details()
                    {
                        shipping = "1",
                        subtotal = "5",
                        tax      = "1"
                    }
                },
                description = "This is the payment transaction description.",
                item_list   = new PayPal.Api.ItemList()
                {
                    items = new List <Item>()
                    {
                        new Item()
                        {
                            name     = "Item Name",
                            currency = "USD",
                            price    = "1",
                            quantity = "5",
                            sku      = "sku"
                        }
                    },
                    shipping_address = new ShippingAddress
                    {
                        city           = "Johnstown",
                        country_code   = "US",
                        line1          = "52 N Main ST",
                        postal_code    = "43210",
                        state          = "OH",
                        recipient_name = "Basher Buyer"
                    }
                },
                invoice_number = PayPalCommon.GetRandomInvoiceNumber()
            };

            // A resource representing a Payer that funds a payment.
            var payer = new PayPal.Api.Payer()
            {
                payment_method      = "credit_card",
                funding_instruments = new List <FundingInstrument>()
                {
                    new FundingInstrument()
                    {
                        credit_card = new CreditCard()
                        {
                            billing_address = new Address()
                            {
                                city         = "Johnstown",
                                country_code = "US",
                                line1        = "52 N Main ST",
                                postal_code  = "43210",
                                state        = "OH"
                            },
                            cvv2         = "000",
                            expire_month = 01,
                            expire_year  = 2022,
                            first_name   = "Khademul",
                            last_name    = "Basher",
                            number       = "****************",
                            type         = "visa"
                        }
                    }
                },
                payer_info = new PayerInfo
                {
                    email = "*****@*****.**"
                }
            };

            // A Payment resource; create one using the above types and intent as `sale` or `authorize`
            var payment = new PayPal.Api.Payment()
            {
                intent       = "sale",
                payer        = payer,
                transactions = new List <Transaction>()
                {
                    transaction
                }
            };

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

            // Create a payment using a valid APIContext
            var createdPayment = payment.Create(apiContext);

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

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