Exemplo n.º 1
0
        public async Task <IActionResult> SubmitPayouts()
        {
            PayoutBatch payoutBatch = await _context.AddPayoutBatch(GetCurrentPayouts());

            if (payoutBatch.PayoutPaypalBatchId == null)
            {
                PayPalHttpClient client = _clientFactory.GetClient();
                try
                {
                    await client.AuthorizeAsync();

                    await client.CreatePayouts(payoutBatch);

                    await _context.SaveChangesAsync();
                }
                catch (Exception e)
                {
                    return(Json(e.Message));
                }
            }

            return(View(viewName: "Index", model: new List <UserPayoutVM>()));
        }
Exemplo n.º 2
0
        private List <UserPayoutVM> GetCurrentPayouts()
        {
            PayoutBatch         lastPayoutBatch = _context.PayoutBatches.OrderBy(p => p.ID).LastOrDefault();
            List <UserPayoutVM> userPayouts     = _context.Links
                                                  .Include(l => l.Owner)
                                                  .Include(l => l.Clicks)
                                                  .GroupBy(l => l.OwnerId)
                                                  .Where(group => group.First().OwnerId != null)
                                                  .Select(group => new UserPayoutVM
            {
                Email  = group.First().Owner.Email,
                Payout = _options.MoneyPerClick * group.Sum(l => l.Clicks.Where(
                                                                c => (c.DateTime <= DateTime.Now.AddDays(-1) && (lastPayoutBatch == null || c.DateTime >= lastPayoutBatch.ID)))
                                                            .Count())
            }).Where(u => u.Payout != 0).ToList();

            if (userPayouts == null)
            {
                return(new List <UserPayoutVM>());
            }

            return(userPayouts);
        }
Exemplo n.º 3
0
        public async void TestPayoutsItemCancelRequest()

        {
            var response = await PayoutsPostTest.TestCreatePayoutRequest();

            CreatePayoutResponse batch   = response.Result <CreatePayoutResponse>();
            PayoutsGetRequest    request = new PayoutsGetRequest(batch.BatchHeader.PayoutBatchId);


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

            PayoutBatch batchDetails = getResponse.Result <PayoutBatch>();

            Thread.Sleep(10000);

            PayoutsItemCancelRequest cancelRequest = new PayoutsItemCancelRequest(batchDetails.Items[0].PayoutItemId);

            HttpResponse cancelResponse = await TestHarness.client().Execute(cancelRequest);

            Assert.Equal(200, (int)cancelResponse.StatusCode);
            Assert.NotNull(cancelResponse.Result <PayoutItemResponse>());

            // Add your own checks here
        }
        public void payoutFunction(ApplicationCart cart)
        {
            // ### Api Context
            // Pass in a `APIContext` object to authenticate
            // the call and to send a unique request id
            // (that ensures idempotency). The SDK generates
            // a request id if you do not pass one explicitly.
            // See [Configuration.cs](/Source/Configuration.html) to know more about APIContext.
            var apiContext = PaypalConfiguration.GetAPIContext();

            // ### Initialize `Payout` Object
            // Initialize a new `Payout` object with details of the batch payout to be created.
            var payout = new Payout
            {
                // #### sender_batch_header
                // Describes how the payments defined in the `items` array are to be handled.
                sender_batch_header = new PayoutSenderBatchHeader
                {
                    sender_batch_id = "batch_" + System.Guid.NewGuid().ToString().Substring(0, 8),
                    email_subject   = "You have a payment"
                },
                // #### items
                // The `items` array contains the list of payout items to be included in this payout.
                // If `syncMode` is set to `true` when calling `Payout.Create()`, then the `items` array must only
                // contain **one** item.  If `syncMode` is set to `false` when calling `Payout.Create()`, then the `items`
                // array can contain more than one item.
                items = new List <PayoutItem>
                {
                    new PayoutItem
                    {
                        recipient_type = PayoutRecipientType.EMAIL,
                        amount         = new Currency
                        {
                            value    = cart.TotalPrice.ToString(),
                            currency = cart.Currency
                        },
                        receiver       = "*****@*****.**",
                        note           = "Thank you for shopping.",
                        sender_item_id = "item_1"
                    },
                    //new PayoutItem
                    //{
                    //    recipient_type = PayoutRecipientType.EMAIL,
                    //    amount = new Currency
                    //    {
                    //        value = "7",
                    //        currency = "USD"
                    //    },
                    //    receiver = "*****@*****.**",
                    //    note = "Thank you for coming.",
                    //    sender_item_id = "item_2"
                    //},
                    //new PayoutItem
                    //{
                    //    recipient_type = PayoutRecipientType.EMAIL,
                    //    amount = new Currency
                    //    {
                    //        value = "2.00",
                    //        currency = "USD"
                    //    },
                    //    receiver = "ng-facilitator_api1.narola.email",
                    //    note = "Thank you.",
                    //    sender_item_id = "item_3"
                    //}
                }
            };
            // ### Payout.Create()
            // Creates the batch payout resource.
            // `syncMode = false` indicates that this call will be performed **asynchronously**,
            // and will return a `payout_batch_id` that can be used to check the status of the payouts in the batch.
            // `syncMode = true` indicates that this call will be performed **synchronously** and will return once the payout has been processed.
            // > **NOTE**: The `items` array can only have **one** item if `syncMode` is set to `true`.
            var createdPayout = payout.Create(apiContext);

            PayoutBatch payoutPayment = Payout.Get(apiContext, createdPayout.batch_header.payout_batch_id);
        }