How to create subscription in Asp.net with pagseguro

Asked

Viewed 254 times

1

Hi I already searched everywhere and I couldn’t find how to integrate a subscription inside my system in Asp.net mvc with pagseguro. I used this code and my return is not working when I add this preapproval !

 //**********************Inicio do procedimento para gerar uma compra pela API do pagseguro
                    DateTime now = new DateTime();
                    var payment = new PaymentRequest();

                    payment.Items.Add(new Item("0001", "Notebook Prata", 1, 2430.00m));
                    payment.Items.Add(new Item("0002", "Mochila", 1, 150.99m));

                    payment.Sender = new Sender("José Comprador","[email protected]",new Phone("11","56273440"));

                    payment.PreApproval = new PreApproval
                    {
                        Charge = Charge.Auto,
                        Name = "Seguro contra roubo do Notebook",
                        AmountPerPayment = 100.00m,
                        MaxAmountPerPeriod = 100.00m,
                        Details = string.Format("test"),
                        Period = Period.Monthly,
                        DayOfMonth = now.Day,
                        InitialDate = now,
                        FinalDate = now.AddMonths(6),
                        MaxTotalAmount = 600.00m,
                        MaxPaymentsPerPeriod = 1,

                    };

                    payment.Currency = Currency.Brl;

                    SenderDocument senderCPF = new SenderDocument(Documents.GetDocumentByType("CPF"), "12345678909");
                    payment.Sender.Documents.Add(senderCPF);
                    AccountCredentials credentials = new AccountCredentials("[email protected]","ABC1234DEF");

                    Uri paymentRedirectUri = payment.Register(credentials);

                    return Redirect(paymentRedirectUri.AbsoluteUri);


                    //**************************************************************************

I’ve already looked at the method of @Ciganomorissonmendez that I help a lot but it is my first project and I have no concept on the subject.

1 answer

1

I solved the signature problem without items:

I used and the Pre-approved that is in the example of the folder dotnet->source->example->preapproval->createPreapproval
In that I had to change Preapprovalserializer.Cs because of a date problem that was generated
As explained by Margatho added the dateRead

namespace Uol.PagSeguro.XmlParse <- NameSpace
internal static class PreApprovalSerializer <- Classe
internal static void Read(XmlReader reader, PreApprovalRequestResponse preApprovalResponse) <- Método

switch (reader.Name)
                    {
                        case PreApprovalSerializer.Date: <- Ini
                            DateTime dateRead;                           
                            DateTime.TryParse(reader.ReadElementContentAsString(), out dateRead);
                            preApprovalResponse.RegistrationDate = dateRead;
                            break; <- fim
                        case PreApprovalSerializer.Code:
                            preApprovalResponse.Code = reader.ReadElementContentAsString();
                            break;
                        case PreApprovalSerializer.Status:
                            preApprovalResponse.Status = reader.ReadElementContentAsString();
                            break;
                        default:
                            XMLParserUtils.SkipElement(reader);
                            break;
                    }

So a subscription was created without product ! But I would not have found this result without having understood the previous conversation.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.