예제 #1
0
        public OnlineDebitCheckout MappingDebitCheckout()
        {
            // Instantiate a new checkout
            OnlineDebitCheckout checkout = new OnlineDebitCheckout();



            return(new OnlineDebitCheckout());
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="checkout"></param>
        /// <returns></returns>
        public static IDictionary <string, string> GetData(Checkout checkout)
        {
            IDictionary <string, string> data = new Dictionary <string, string>();

            // payment mode
            if (checkout.PaymentMode != null)
            {
                data["paymentMode"] = checkout.PaymentMode;
            }

            // receiver e-mail
            if (checkout.ReceiverEmail != null)
            {
                data["receiverEmail"] = checkout.ReceiverEmail;
            }

            // reference
            if (checkout.Reference != null)
            {
                data["reference"] = checkout.Reference;
            }

            // sender
            if (checkout.Sender != null)
            {
                if (checkout.Sender.Name != null)
                {
                    data["senderName"] = checkout.Sender.Name;
                }
                if (checkout.Sender.Email != null)
                {
                    data["senderEmail"] = checkout.Sender.Email;
                }
                if (checkout.Sender.Hash != null)
                {
                    data["senderHash"] = checkout.Sender.Hash;
                }

                // phone
                if (checkout.Sender.Phone != null)
                {
                    if (checkout.Sender.Phone.AreaCode != null)
                    {
                        data["senderAreaCode"] = checkout.Sender.Phone.AreaCode;
                    }
                    if (checkout.Sender.Phone.Number != null)
                    {
                        data["senderPhone"] = checkout.Sender.Phone.Number;
                    }
                }

                // documents
                if (checkout.Sender.Documents != null)
                {
                    var documents = checkout.Sender.Documents;
                    if (documents.Count == 1)
                    {
                        foreach (SenderDocument document in documents)
                        {
                            if (document != null)
                            {
                                if (document.Type.Equals("Cadastro de Pessoa Física"))
                                {
                                    data["senderCPF"] = document.Value;
                                }
                                else
                                {
                                    data["senderCNPJ"] = document.Value;
                                }
                            }
                        }
                    }
                }
            }

            // currency
            if (checkout.Currency != null)
            {
                data["currency"] = checkout.Currency;
            }

            // items
            if (checkout.Items.Count > 0)
            {
                var items = checkout.Items;
                int i     = 0;
                foreach (Item item in items)
                {
                    i++;

                    if (item.Id != null)
                    {
                        data["itemId" + i] = item.Id;
                    }
                    if (item.Description != null)
                    {
                        data["itemDescription" + i] = item.Description;
                    }
                    if (item.Quantity != null)
                    {
                        data["itemQuantity" + i] = item.Quantity.ToString();
                    }
                    if (item.Amount != null)
                    {
                        data["itemAmount" + i] = PagSeguroUtil.DecimalFormat(item.Amount);
                    }
                    if (item.Weight != null)
                    {
                        data["itemWeight" + i] = item.Weight.ToString();
                    }
                    if (item.ShippingCost != null)
                    {
                        data["itemShippingCost" + i] = PagSeguroUtil.DecimalFormat((decimal)item.ShippingCost);
                    }
                }
            }

            // extraAmount
            if (checkout.ExtraAmount != null)
            {
                data["extraAmount"] = PagSeguroUtil.DecimalFormat((decimal)checkout.ExtraAmount);
            }

            // shipping
            if (checkout.Shipping != null)
            {
                if (checkout.Shipping.ShippingType != null && checkout.Shipping.ShippingType.Value != null)
                {
                    data["shippingType"] = checkout.Shipping.ShippingType.Value.ToString();
                }

                if (checkout.Shipping.Cost != null)
                {
                    data["shippingCost"] = PagSeguroUtil.DecimalFormat((decimal)checkout.Shipping.Cost);
                }

                // address
                if (checkout.Shipping.Address != null)
                {
                    if (checkout.Shipping.Address.Street != null)
                    {
                        data["shippingAddressStreet"] = checkout.Shipping.Address.Street;
                    }
                    if (checkout.Shipping.Address.Number != null)
                    {
                        data["shippingAddressNumber"] = checkout.Shipping.Address.Number;
                    }
                    if (checkout.Shipping.Address.Complement != null)
                    {
                        data["shippingAddressComplement"] = checkout.Shipping.Address.Complement;
                    }
                    if (checkout.Shipping.Address.City != null)
                    {
                        data["shippingAddressCity"] = checkout.Shipping.Address.City;
                    }
                    if (checkout.Shipping.Address.State != null)
                    {
                        data["shippingAddressState"] = checkout.Shipping.Address.State;
                    }
                    if (checkout.Shipping.Address.District != null)
                    {
                        data["shippingAddressDistrict"] = checkout.Shipping.Address.District;
                    }
                    if (checkout.Shipping.Address.PostalCode != null)
                    {
                        data["shippingAddressPostalCode"] = checkout.Shipping.Address.PostalCode;
                    }
                    if (checkout.Shipping.Address.Country != null)
                    {
                        data["shippingAddressCountry"] = checkout.Shipping.Address.Country;
                    }
                }
            }

            // maxAge
            if (checkout.MaxAge != null)
            {
                data["maxAge"] = checkout.MaxAge.ToString();
            }
            // maxUses
            if (checkout.MaxUses != null)
            {
                data["maxUses"] = checkout.MaxUses.ToString();
            }

            // notificationURL
            if (checkout.NotificationURL != null)
            {
                data["notificationURL"] = checkout.NotificationURL;
            }

            // metadata
            if (checkout.MetaData.Items.Count > 0)
            {
                int i             = 0;
                var metaDataItems = checkout.MetaData.Items;
                foreach (MetaDataItem item in metaDataItems)
                {
                    if (!PagSeguroUtil.IsEmpty(item.Key) && !PagSeguroUtil.IsEmpty(item.Value))
                    {
                        i++;
                        data["metadataItemKey" + i]   = item.Key;
                        data["metadataItemValue" + i] = item.Value;

                        if (item.Group != null)
                        {
                            data["metadataItemGroup" + i] = item.Group.ToString();
                        }
                    }
                }
            }

            // parameter
            if (checkout.Parameter.Items.Count > 0)
            {
                var parameterItems = checkout.Parameter.Items;
                foreach (ParameterItem item in parameterItems)
                {
                    if (!PagSeguroUtil.IsEmpty(item.Key) && !PagSeguroUtil.IsEmpty(item.Value))
                    {
                        if (item.Group != null)
                        {
                            data[item.Key + "" + item.Group] = item.Value;
                        }
                        else
                        {
                            data[item.Key] = item.Value;
                        }
                    }
                }
            }

            //Verify if exists the credit card checkout data
            if (checkout is CreditCardCheckout)
            {
                CreditCardCheckout creditcard = (CreditCardCheckout)checkout;
                // billing
                if (creditcard.Billing != null)
                {
                    // address
                    if (creditcard.Billing.Address != null)
                    {
                        if (creditcard.Billing.Address.Street != null)
                        {
                            data["billingAddressStreet"] = creditcard.Billing.Address.Street;
                        }
                        if (creditcard.Billing.Address.Number != null)
                        {
                            data["billingAddressNumber"] = creditcard.Billing.Address.Number;
                        }
                        if (creditcard.Billing.Address.Complement != null)
                        {
                            data["billingAddressComplement"] = creditcard.Billing.Address.Complement;
                        }
                        if (creditcard.Billing.Address.City != null)
                        {
                            data["billingAddressCity"] = creditcard.Billing.Address.City;
                        }
                        if (creditcard.Billing.Address.State != null)
                        {
                            data["billingAddressState"] = creditcard.Billing.Address.State;
                        }
                        if (creditcard.Billing.Address.District != null)
                        {
                            data["billingAddressDistrict"] = creditcard.Billing.Address.District;
                        }
                        if (creditcard.Billing.Address.PostalCode != null)
                        {
                            data["billingAddressPostalCode"] = creditcard.Billing.Address.PostalCode;
                        }
                        if (creditcard.Billing.Address.Country != null)
                        {
                            data["billingAddressCountry"] = creditcard.Billing.Address.Country;
                        }
                    }
                }

                // holder
                if (creditcard.Holder != null)
                {
                    //holder name
                    if (creditcard.Holder.Name != null)
                    {
                        data["creditCardHolderName"] = creditcard.Holder.Name;
                    }
                    //holder phone
                    if (creditcard.Holder.Phone != null)
                    {
                        if (creditcard.Holder.Phone.AreaCode != null)
                        {
                            data["creditCardHolderAreaCode"] = creditcard.Holder.Phone.AreaCode;
                        }
                        if (creditcard.Holder.Phone.Number != null)
                        {
                            data["creditCardHolderPhone"] = creditcard.Holder.Phone.Number;
                        }
                    }
                    //holder document
                    if (creditcard.Holder.Document != null)
                    {
                        if (creditcard.Holder.Document.Value != null)
                        {
                            data["creditCardHolderCPF"] = creditcard.Holder.Document.Value;
                        }
                    }
                    //holder birth date
                    if (creditcard.Holder.Birthdate != null)
                    {
                        data["creditCardHolderBirthDate"] = creditcard.Holder.Birthdate;
                    }
                }

                // token
                if (creditcard.Token != null)
                {
                    data["creditCardToken"] = creditcard.Token;
                }

                // installment
                if (creditcard.Installment != null)
                {
                    if (creditcard.Installment.Quantity > 0)
                    {
                        data["installmentQuantity"] = creditcard.Installment.Quantity.ToString();
                    }
                    if (creditcard.Installment.Value > 0)
                    {
                        data["installmentValue"] = PagSeguroUtil.DecimalFormat((decimal)creditcard.Installment.Value);
                    }
                    if (creditcard.Installment.NoInterestInstallmentQuantity > 0)
                    {
                        data["noInterestInstallmentQuantity"] = creditcard.Installment.NoInterestInstallmentQuantity.ToString();
                    }
                }

                // payment method
                if (creditcard.PaymentMethod != null)
                {
                    data["paymentMethod"] = creditcard.PaymentMethod;
                }
            }


            //Verify if exists the boleto checkout data
            if (checkout is BoletoCheckout)
            {
                BoletoCheckout boleto = (BoletoCheckout)checkout;

                // payment method
                if (boleto.PaymentMethod != null)
                {
                    data["paymentMethod"] = boleto.PaymentMethod;
                }
            }

            //Verify if exists the online debit checkout data
            if (checkout is OnlineDebitCheckout)
            {
                OnlineDebitCheckout onlineDebit = (OnlineDebitCheckout)checkout;

                // payment method
                if (onlineDebit.PaymentMethod != null)
                {
                    data["paymentMethod"] = onlineDebit.PaymentMethod;
                }

                // bank name
                if (onlineDebit.BankName != null)
                {
                    data["bankName"] = onlineDebit.BankName;
                }
            }

            return(data);
        }
예제 #3
0
        static void Main(string[] args)
        {
            PagSeguroConfiguration.UrlXmlConfiguration = ".../.../.../.../.../Configuration/PagSeguroConfig.xml";

            bool isSandbox = false;

            EnvironmentConfiguration.ChangeEnvironment(isSandbox);

            // Instantiate a new checkout
            OnlineDebitCheckout checkout = new OnlineDebitCheckout();

            // Sets the payment mode
            checkout.PaymentMode = PaymentMode.DEFAULT;

            // Sets the receiver e-mail should will get paid
            checkout.ReceiverEmail = "*****@*****.**";

            // Sets the currency
            checkout.Currency = Currency.Brl;

            // Add items
            checkout.Items.Add(new Item("0001", "Notebook Prata", 1, 1300.00m));
            checkout.Items.Add(new Item("0002", "Notebook Rosa", 1, 150.99m));

            // Sets a reference code for this checkout, it is useful to identify this payment in future notifications.
            checkout.Reference = "REF1234";

            // Sets shipping information for this payment request
            checkout.Shipping = new Shipping();
            checkout.Shipping.ShippingType = ShippingType.Sedex;
            checkout.Shipping.Cost         = 0.00m;
            checkout.Shipping.Address      = new Address(
                "BRA",
                "SP",
                "Sao Paulo",
                "Jardim Paulistano",
                "01452002",
                "Av. Brig. Faria Lima",
                "1384",
                "5o andar"
                );

            // Sets your customer information.
            // If you using SANDBOX you must use an email @sandbox.pagseguro.com.br
            checkout.Sender = new Sender(
                "Joao Comprador",
                "*****@*****.**",
                new Phone("11", "56273440")
                );
            checkout.Sender.Hash = "b2806d600653cbb2b195f317ca9a1a58738187a02c05bf7f2280e2076262e73b";
            SenderDocument senderCPF = new SenderDocument(Documents.GetDocumentByType("CPF"), "12345678909");

            checkout.Sender.Documents.Add(senderCPF);

            // Sets the notification url
            checkout.NotificationURL = "http://www.lojamodelo.com.br";

            // Sets the bank information
            checkout.BankName = BankName.Bradesco;

            try
            {
                AccountCredentials credentials = new AccountCredentials("", "");
                Transaction        result      = TransactionService.CreateCheckout(credentials, checkout);

                Console.WriteLine(result);
                Console.ReadKey();
            }
            catch (PagSeguroServiceException exception)
            {
                Console.WriteLine(exception.Message + "\n");

                foreach (ServiceError element in exception.Errors)
                {
                    Console.WriteLine(element + "\n");
                }
                Console.ReadKey();
            }
        }