コード例 #1
0
        public Aluno_pgto Pagar(Aluno_pgto ap)
        {
            EnvironmentConfiguration.ChangeEnvironment(isSandbox);

            // Instantiate a new preApproval request
            PreApprovalRequest preApproval = new PreApprovalRequest();

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

            // Sets a reference code for this preApproval request, it is useful to identify this payment in future notifications.
            preApproval.Reference = "AP" + ap.codigo.ToString();

            ap.CompletaCampos();

            // Sets your customer information.
            preApproval.Sender = new Sender(
                ap.aluno.nome,
                ap.aluno.email,
                new Phone(ap.aluno.ddd, ap.aluno.telefone)
                );

            valor = Convert.ToDecimal(ap.curso.valor);

            if (ap.aluno.codigo == 4284)
            {
                valor = 1;
            }

            preApproval.PreApproval = new PreApproval();

            // Sets the preApproval informations
            var now = DateTime.Now;

            preApproval.PreApproval                      = new PreApproval();
            preApproval.PreApproval.Charge               = Charge.Auto;
            preApproval.PreApproval.Name                 = "Assinatura " + ap.curso.titulo;
            preApproval.PreApproval.AmountPerPayment     = valor;
            preApproval.PreApproval.MaxAmountPerPeriod   = valor;
            preApproval.PreApproval.MaxPaymentsPerPeriod = 1;
            preApproval.PreApproval.Details              = string.Format("Todo dia {0} sera cobrado o valor de {1} referente a sua assinatura {2}. A assinatura esta sendo contratada ate o termino da vigencia, no entanto voce podera fazer o cancelamento quando quiser!", now.Day, preApproval.PreApproval.AmountPerPayment.ToString("C2"), ap.curso.titulo);
            preApproval.PreApproval.Period               = Period.Monthly;
            preApproval.PreApproval.DayOfMonth           = now.Day;
            preApproval.PreApproval.InitialDate          = now;
            preApproval.PreApproval.FinalDate            = now.AddMonths(qtd_max_meses);
            preApproval.PreApproval.MaxTotalAmount       = qtd_max_meses * valor;

            // Sets the url used by PagSeguro for redirect user after ends checkout process
            preApproval.RedirectUri = new Uri("https://www.cenbrap.com.br/Pagseguro/retorno");
            // Sets the url used for user review the signature or read the rules
            preApproval.ReviewUri = new Uri("https://www.cenbrap.com.br/Pagseguro/revisao");

            SenderDocument senderCPF = new SenderDocument(Documents.GetDocumentByType("CPF"), ap.aluno.cpf.Replace(".", "").Replace(" ", "").Replace("-", "").Replace("/", "").Replace(",", ""));

            preApproval.Sender.Documents.Add(senderCPF);

            try
            {
                //AccountCredentials credentials = new AccountCredentials(email, token);
                AccountCredentials credentials = PagSeguroConfiguration.Credentials(isSandbox);

                Uri preApprovalRedirectUri = preApproval.Register(credentials);

                ap.situacao = 0;
                ap.obs      = preApprovalRedirectUri.ToString();
                ap.txt      = "";

                ap.Alterar();
            }
            catch (PagSeguroServiceException exception)
            {
                ap.situacao = 1;
                ap.obs      = "";

                ap.txt = exception.Message + "\n";

                foreach (ServiceError element in exception.Errors)
                {
                    ap.txt += (element + "\n");
                }

                ap.Alterar();
            }

            return(ap);
        }
コード例 #2
0
 public void PgtoConcluido(Aluno_pgto pgto)
 {
     pgto.CompletaCampos();
     pgto.Confirma();
 }