Exemplo n.º 1
0
        public async static Task <HttpResponse> CreatePayout(bool debug = false)
        {
            Console.WriteLine("Creating payout with complete payload");

            try {
                PayoutsPostRequest request = new PayoutsPostRequest();
                request.RequestBody(buildRequestBody());


                var response = await PayPalClient.client().Execute(request);

                var result = response.Result <CreatePayoutResponse>();
                if (debug)
                {
                    Console.WriteLine("Status: {0}", result.BatchHeader.BatchStatus);
                    Console.WriteLine("Batch Id: {0}", result.BatchHeader.PayoutBatchId);
                    Console.WriteLine("Links:");
                    foreach (LinkDescription link in result.Links)
                    {
                        Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
                    }
                }
                return(response);
            } catch (HttpException ex) {
                String errorString = ex.Message;
                Error  error       = ErrorUtil.deserializeError(errorString);
                ErrorUtil.printError(error);
                return(null);
            }
        }
Exemplo n.º 2
0
        public async static Task <HttpResponse> CreatePayout(bool debug = false)
        {
            Console.WriteLine("Creating payout with complete payload");
            PayoutsPostRequest request = new PayoutsPostRequest()
                                         .PayPalPartnerAttributionId("agSzCOx4Ab9pHxgawSO")
                                         .PayPalRequestId("M6a5KDUiH6-u6E3D");

            request.RequestBody(buildRequestBody());


            var response = await PayPalClient.client().Execute(request);

            var result = response.Result <CreatePayoutResponse>();

            if (debug)
            {
                Console.WriteLine("Status: {0}", result.BatchHeader.BatchStatus);
                Console.WriteLine("Batch Id: {0}", result.BatchHeader.PayoutBatchId);
                Console.WriteLine("Links:");
                foreach (LinkDescription link in result.Links)
                {
                    Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
                }
            }
            return(response);
        }
        public static async Task <HttpResponse> TestCreatePayoutRequest()
        {
            PayoutsPostRequest request = new PayoutsPostRequest();

            request.RequestBody(buildRequestBody());

            HttpResponse response = await TestHarness.client().Execute(request);

            return(response);
        }
Exemplo n.º 4
0
        public static async Task <HttpResponse> TestCreatePayoutRequest()
        {
            PayoutsPostRequest request = new PayoutsPostRequest()
                                         .PayPalPartnerAttributionId("agSzCOx4Ab9pHxgawSO")
                                         .PayPalRequestId("M6a5KDUiH6-u6E3D");

            request.RequestBody(buildRequestBody());

            HttpResponse response = await TestHarness.client().Execute(request);

            return(response);
        }
Exemplo n.º 5
0
        private async System.Threading.Tasks.Task levantar()
        {
            try
            {
                string emailPaypal = txt_emaillevantar.Text;
                double valor       = double.Parse(txt_moneylevantar.Text.Replace(".", ","));

                if (emailPaypal == String.Empty || emailPaypal.Contains("@") == false || emailPaypal.Contains(".") == false)
                {
                    throw new Exception("O email indicado não é válido.");
                }

                if (valor <= 0)
                {
                    throw new Exception("Valor indicado inválido");
                }

                int id_user = int.Parse(Session["id_user"].ToString());

                Models.User user = new User(id_user);

                double saldo = user.getSaldo();

                if (saldo - valor < 0)
                {
                    throw new Exception("O seu saldo não permite executar esta ação!");
                }

                var body = new CreatePayoutRequest()
                {
                    SenderBatchHeader = new SenderBatchHeader()
                    {
                        EmailMessage = $"O teu levantamento foi sucedido, recebeste {valor}",
                        EmailSubject = "Recebeste dinheiro da Food4U!!"
                    },
                    Items = new List <PayoutItem>()
                    {
                        new PayoutItem()
                        {
                            RecipientType = "EMAIL",
                            Amount        = new Currency()
                            {
                                CurrencyCode = "EUR",
                                Value        = valor.ToString().Replace(",", "."),
                            },
                            Receiver = emailPaypal,
                        }
                    }
                };

                PayoutsPostRequest request = new PayoutsPostRequest();
                request.RequestBody(body);
                Transacao.LevantarDinheiro(id_user, saldo, valor);

                var response = await CreatePayout.client().Execute(request);

                var result = response.Result <CreatePayoutResponse>();


                Debug.WriteLine("Status: {0}", result.BatchHeader.BatchStatus);
                Debug.WriteLine("Batch Id: {0}", result.BatchHeader.PayoutBatchId);
                Debug.WriteLine("Links:");
                foreach (LinkDescription link in result.Links)
                {
                    Debug.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
                }
            }
            catch (Exception erro)
            {
                ScriptManager.RegisterClientScriptBlock(this, typeof(Page), "MostrarNotificação", $"ShowNotification('Erro','{erro.Message}', 'error')", true);
            }
        }