public BoletoCheckout MappingDebitCheckout(int id) { // Instantiate a new checkout BoletoCheckout checkout = new BoletoCheckout(); // Sets the payment mode checkout.PaymentMode = PaymentMode.DEFAULT; // Sets the receiver e-mail should will get paid checkout.ReceiverEmail = "*****@*****.**"; //Email do participante que irá receber o boleto // Sets the currency checkout.Currency = Currency.Brl; // Extra amount to be added to the transaction total //checkout.ExtraAmount = 1.00m; // Add items checkout.Items.Add(new Uol.PagSeguro.Domain.Item("0001", "Resident Evil 6", 1, 10.00m)); checkout.Items.Add(new Uol.PagSeguro.Domain.Item("0002", "Megaman Collection", 2, 20.00m)); // Sets the notification url checkout.NotificationURL = "http://www.lojamodelo.com.br"; // Sets a reference code for this checkout, it is useful to identify this payment in future notifications. checkout.Reference = "REF1234"; //Vai o ID do pedido TicketGames // Sets your customer information. // If you using SANDBOX you must use an email @sandbox.pagseguro.com.br checkout.Sender = new Sender( "Joao Comprador", //Nome do participante "*****@*****.**", // Email do Participante new Phone("11", "56273440") // Telefone do Participante ); SenderDocument senderCPF = new SenderDocument(Documents.GetDocumentByType("CPF"), "37482628843"); // CPF do participante checkout.Sender.Documents.Add(senderCPF); checkout.Sender.Hash = "b2806d600653cbb2b195f317ca9a1a58738187a02c05bf7f2280e2076262e73b"; //Hash gerado no PagSeguroDirectPayment.getSenderHash(); // Sets shipping information checkout.Shipping = new Shipping(); checkout.Shipping.ShippingType = ShippingType.NotSpecified; checkout.Shipping.Cost = 0.00m; checkout.Shipping.Address = new Address( "BRA", "SP", "Sao Paulo", "Jardim Paulistano", "01452002", "Av. Brig. Faria Lima", "1384", "5o andar" ); //Endereço de entrega do participante return(checkout); }
public string Boleto(string documento, string nome, string email, string telefone, string codigoHash, decimal valor) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); BoletoCheckout checkout = new BoletoCheckout(); var endereco = GetEndereco(documento); checkout.PaymentMode = PaymentMode.DEFAULT; checkout.ReceiverEmail = "*****@*****.**"; checkout.Currency = Currency.Brl; checkout.Items.Add(new Item("0001", "Contabilidade Online", 1, valor)); checkout.Reference = documento; checkout.Shipping = new Shipping(); checkout.Shipping.ShippingType = ShippingType.Sedex; checkout.Shipping.Cost = 0.00m; checkout.Shipping.Address = new Address( "BRA", endereco.UF, endereco.Cidade, endereco.Bairro, endereco.CEP, endereco.TipoEnd + " " + endereco.Logradouro, endereco.Numrero, endereco.Complemento ); checkout.Sender = new Sender( nome, email, new Phone("11", telefone) ); checkout.Sender.Hash = codigoHash; SenderDocument senderCPF = new SenderDocument(Documents.GetDocumentByType("CNPJ"), documento); checkout.Sender.Documents.Add(senderCPF); try { AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox); Transaction result = TransactionService.CreateCheckout(credentials, checkout); GravaTransacao("2", codigoHash, Convert.ToDecimal(valor), result.PaymentLink, result.Code, result.LastEventDate.Day, result.LastEventDate.Month, documento); ///var corpo = " <html xmlns='http://www.w3.org/1999/xhtml'><head> <style type='text/css'> body, #bodyTable, #bodyCell, #bodyCell { height: 100% !important; margin: 0; padding: 0; width: 100% !important; font-family: Helvetica, Arial, 'Lucida Grande', sans-serif; } body, table, td, p, a, li, blockquote { -ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; font-weight: normal !important; } body, #bodyTable { background-color: #E1E1E1; } </style> <script type='text/javascript' src='http://gc.kis.v2.scr.kaspersky-labs.com/D23BDC46-5991-6E46-B0E9-985879E9A50E/main.js' charset='UTF-8'></script></head><body bgcolor='#E1E1E1' leftmargin='0' marginwidth='0' topmargin='0' marginheight='0' offset='0'><center style='background-color:#E1E1E1;'><table border='0' cellpadding='0' cellspacing='0' height='100%' width='100%' id='bodyTable' style='table-layout: fixed;max-width:100% !important;width: 100% !important;min-width: 100% !important;'><tr><td align='center' valign='top' id='bodyCell'><table bgcolor='#FFFFFF' border='0' cellpadding='0' cellspacing='0' width='500' id='emailBody'><tr><td align='center' valign='top'><table border='0' cellpadding='0' cellspacing='0' width='100%' style='color:#FFFFFF;' bgcolor='#F8F8F8'><tr><td align='center' valign='top'><table border='0' cellpadding='0' cellspacing='0' width='500' class='flexibleContainer'><tr><td align='center' valign='top' width='500' class='flexibleContainerCell'><table border='0' cellpadding='30' cellspacing='0' width='100%'><tr><td align='left' valign='top' class='textContent' style='color: dodgerblue; '><h1>Contfy</h1> </td></tr></table></td></tr></table></td></tr></table></td></tr><tr><td align='center' valign='top'><table border='0' cellpadding='0' cellspacing='0' width='100%' bgcolor='#FFFFFF'><tr> <td align='center' valign='top'> <table border='0' cellpadding='0' cellspacing='0' width='500' class='flexibleContainer'><tr><td align='center' valign='top' width='500' class='flexibleContainerCell'><table border='0' cellpadding='30' cellspacing='0' width='100%'><tr><td align='center' valign='top'><table border='0' cellpadding='0' cellspacing='0' width='100%'><tr><td valign='top' class='textContent'><h3 style='color:#5F5F5F;line-height:125%;font-family:Helvetica,Arial,sans-serif;font-size:20px;font-weight:normal;margin-top:0;margin-bottom:3px;text-align:left;'>Segue o link de pagamento para uso da CONTFY:</h3><br /> </td></tr></table></td> </tr></table></td></tr></table></td></tr></table></td></tr><tr><td align='center' valign='top'><table border='0' cellpadding='0' cellspacing='0' width='100%'> <tr style='padding-top:0;'> <td align='center' valign='top'> <table border='0' cellpadding='30' cellspacing='0' width='500' class='flexibleContainer'> <tr> <td style='padding-top:0;' align='center' valign='top' width='500' class='flexibleContainerCell'> <table border='0' cellpadding='0' cellspacing='0' width='50%' class='emailButton' style='background-color: #3498DB;'> <tr> <td align='center' valign='middle' class='buttonContent' style='padding-top:15px;padding-bottom:15px;padding-right:15px;padding-left:15px;'> <a style='color:#FFFFFF;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:20px;line-height:135%;' href='" + result.PaymentLink.ToString() + "' target='_blank'>Acesse aqui</a> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr><tr><td align='center' valign='top'><table border='0' cellpadding='0' cellspacing='0' width='100%' bgcolor='#FFFFFF'><tr><td align='center' valign='top'><table border='0' cellpadding='0' cellspacing='0' width='500' class='flexibleContainer'><tr><td align='center' valign='top' width='500' class='flexibleContainerCell'> <table border='0' cellpadding='30' cellspacing='0' width='100%'> <tr> <td align='center' valign='top'> <table border='0' cellpadding='0' cellspacing='0' width='100%'> <tr> <td valign='top' class='textContent'> <div style='text-align:left;font-family:Helvetica,Arial,sans-serif;font-size:15px;margin-bottom:0;color:#5F5F5F;line-height:135%;'>CONTFY tem a oferecer aos nossos clientes a tecnologia às suas mãos para facilitar e agilizar todo esse processo burocrático na qual, estamos preparado, tanto na contabilidade tradicional quanto na online.</div> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> <table bgcolor='#E1E1E1' border='0' cellpadding='0' cellspacing='0' width='500' id='emailFooter'> <tr> <td align='center' valign='top'> <table border='0' cellpadding='0' cellspacing='0' width='100%'> <tr> <td align='center' valign='top'> <!-- FLEXIBLE CONTAINER // --> <table border='0' cellpadding='0' cellspacing='0' width='500' class='flexibleContainer'> <tr> <td align='center' valign='top' width='500' class='flexibleContainerCell'> <table border='0' cellpadding='30' cellspacing='0' width='100%'> <tr> <td valign='top' bgcolor='#E1E1E1'> <div style='font-family:Helvetica,Arial,sans-serif;font-size:13px;color:#828282;text-align:center;line-height:120%;'> <div>Contfy © a sua contabilidade online.</div> </div> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </td> </tr> </table> </center></body></html>"; return(result.PaymentLink); } catch (PagSeguroServiceException exception) { return(exception.Message); } }
public bool EmissorBoleto(PessoaTomador pessoaTomador) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); BoletoCheckout checkout = new BoletoCheckout(); checkout.PaymentMode = PaymentMode.DEFAULT; checkout.ReceiverEmail = "*****@*****.**"; checkout.Currency = Currency.Brl; checkout.Items.Add(new Item("0001", "Contabilidade Online", 1, 69.90m)); checkout.Reference = pessoaTomador.Documento; 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" ); checkout.Sender = new Sender( pessoaTomador.Nome, pessoaTomador.Email, new Phone("11", pessoaTomador.Telefone) ); checkout.Sender.Hash = pessoaTomador.CodigoHash; SenderDocument senderCPF = new SenderDocument(Documents.GetDocumentByType("CPF"), "27952666878"); checkout.Sender.Documents.Add(senderCPF); checkout.NotificationURL = "http://www.lojamodelo.com.br"; try { AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox); Transaction result = TransactionService.CreateCheckout(credentials, checkout); return(true); } catch (PagSeguroServiceException exception) { return(false); } }
public PagSeguroResult BilletCheckout(Billet billet) { PagSeguroConfiguration.UrlXmlConfiguration = this.configuration; //bool isSandbox = true; EnvironmentConfiguration.ChangeEnvironment(this.isSandbox); // Instantiate a new checkout BoletoCheckout checkout = billet.MappingBilletCheckout(); try { AccountCredentials credentials = PagSeguroConfiguration.Credentials(this.isSandbox); Uol.PagSeguro.Domain.Transaction transaction = TransactionService.CreateCheckout(credentials, checkout); if (!string.IsNullOrEmpty(transaction.Code)) { pagSeguroResult.Success = true; pagSeguroResult.Code = transaction.Code; pagSeguroResult.FeeAmount = transaction.FeeAmount; pagSeguroResult.NetAmount = transaction.NetAmount; pagSeguroResult.Reference = transaction.Reference; pagSeguroResult.TransactionStatus = transaction.TransactionStatus.ToString(); pagSeguroResult.PaymentLink = transaction.PaymentLink; } return(pagSeguroResult); } catch (PagSeguroServiceException exception) { return(new PagSeguroResult() { Success = false }); //Gravar log do erro } }
static void Main(string[] args) { bool isSandbox = false; EnvironmentConfiguration.ChangeEnvironment(isSandbox); // Instantiate a new checkout BoletoCheckout checkout = new BoletoCheckout(); // 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", 2, 2000.00m)); checkout.Items.Add(new Item("0002", "Notebook Rosa", 2, 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 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"; try { AccountCredentials credentials = PagSeguroConfiguration.GetAccountCredentials(isSandbox); Transaction result = TransactionService.CreateCheckout(credentials, checkout); } catch (PagSeguroServiceException exception) { foreach (ServiceError element in exception.Errors) { } } }
/// <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); }
public BoletoCheckout MappingBilletCheckout() { // Instantiate a new checkout BoletoCheckout checkout = new BoletoCheckout(); // Sets the payment mode checkout.PaymentMode = PaymentMode.DEFAULT; checkout.PaymentMethod = "boleto"; // Sets the receiver e-mail should will get paid //checkout.ReceiverEmail = "*****@*****.**"; checkout.ReceiverEmail = "*****@*****.**"; // Sets the currency checkout.Currency = Currency.Brl; // Add items //foreach (var item in this.Items) //{ // checkout.Items.Add(new Uol.PagSeguro.Domain.Item(item.ProductId, item.Product, item.Quantity, Convert.ToDecimal(item.Value))); // checkout.Items.Add(new Item("0002", "Notebook Rosa", 2, 150.99m)); //} //foreach (var item in this.Items) //{ // checkout.Items.Add(new Uol.PagSeguro.Domain.Item(item.ProductId, item.Product, item.Quantity, Convert.ToDecimal(item.Value))); //} checkout.Items.Add(new Uol.PagSeguro.Domain.Item("2018", "Ticket Games", 1, Convert.ToDecimal(this.Price))); // Sets a reference code for this checkout, it is useful to identify this payment in future notifications. checkout.Reference = this.OrderId.ToString(); // Sets shipping information. checkout.Shipping = new Shipping(); checkout.Shipping.ShippingType = ShippingType.Sedex; checkout.Shipping.Cost = 0.00m; checkout.Shipping.Address = new Address( "BRA", this.ShippingAddress.State, this.ShippingAddress.City, this.ShippingAddress.District, this.ShippingAddress.ZipCode, this.ShippingAddress.Street, this.ShippingAddress.Number, string.Empty ); // Sets your customer information. // If you using SANDBOX you must use an email @sandbox.pagseguro.com.br checkout.Sender = new Sender( this.Buyer.Name, this.Buyer.Mail, new Phone(this.Buyer.DDD, this.Buyer.Phone) ); checkout.Sender.Hash = this.SenderHash; SenderDocument senderCPF = new SenderDocument(Documents.GetDocumentByType("CPF"), this.Buyer.CPF); checkout.Sender.Documents.Add(senderCPF); // Sets the notification url checkout.NotificationURL = "https://ticketgames.com.br"; return(checkout); }