Exemplo n.º 1
0
        protected override void RunSample()
        {
            // ### 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 = Configuration.GetAPIContext();

            // ### Batch Payout ID
            // The ID of the batch payout to lookup.
            var payoutBatchId = "6L3FZTTJE2NR8";

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.AddNewRequest("Retrieve payout details", description: "ID: " + payoutBatchId);
            #endregion

            // ### Payout.Get()
            // Retrieves the details of the specified batch payout.
            var payout = Payout.Get(apiContext, payoutBatchId);

            // ^ Ignore workflow code segment
            #region Track Workflow
            this.flow.RecordResponse(payout);
            #endregion

            // For more information, please visit [PayPal Developer REST API Reference](https://developer.paypal.com/docs/api/).
        }
        public void PayoutCreateAndGetTest()
        {
            try
            {
                var apiContext = TestingUtil.GetApiContext();
                this.RecordConnectionDetails();

                var payout = PayoutTest.GetPayout();
                var payoutSenderBatchId = "batch_" + System.Guid.NewGuid().ToString().Substring(0, 8);
                payout.sender_batch_header.sender_batch_id = payoutSenderBatchId;
                var createdPayout = payout.Create(apiContext, false);
                this.RecordConnectionDetails();

                Assert.IsNotNull(createdPayout);
                Assert.IsTrue(!string.IsNullOrEmpty(createdPayout.batch_header.payout_batch_id));
                Assert.AreEqual(payoutSenderBatchId, createdPayout.batch_header.sender_batch_header.sender_batch_id);

                var payoutBatchId   = createdPayout.batch_header.payout_batch_id;
                var retrievedPayout = Payout.Get(apiContext, payoutBatchId);
                this.RecordConnectionDetails();

                Assert.IsNotNull(payout);
                Assert.AreEqual(payoutBatchId, retrievedPayout.batch_header.payout_batch_id);
            }
            catch (ConnectionException)
            {
                this.RecordConnectionDetails(false);
                throw;
            }
        }
Exemplo n.º 3
0
        public void PayoutGetTest()
        {
            var payoutBatchId = "8NX77PFLN255E";
            var payout        = Payout.Get(TestingUtil.GetApiContext(), payoutBatchId);

            Assert.IsNotNull(payout);
            Assert.AreEqual(payoutBatchId, payout.batch_header.payout_batch_id);
        }
Exemplo n.º 4
0
        public void Payouts(IEnumerable <AdminPayoutsViewModel> models)
        {
            var apiToken = new OAuthTokenCredential(settings.ClientId, settings.ClientSecret)
                           .GetAccessToken();

            var apiContext = new APIContext(apiToken);

            var payoutItems = new List <PayoutItem>();

            foreach (var model in models)
            {
                var payoutItem = new PayoutItem
                {
                    recipient_type = PayoutRecipientType.EMAIL,
                    amount         = new Currency
                    {
                        value    = model.Amount.ToString(),
                        currency = "EUR"
                    },
                    receiver       = model.Email,
                    note           = $"{model.Email} have a payment of  {model.Amount}",
                    sender_item_id = Guid.NewGuid().ToString()
                };

                payoutItems.Add(payoutItem);
            }

            var payout = new Payout
            {
                sender_batch_header = new PayoutSenderBatchHeader
                {
                    sender_batch_id = Guid.NewGuid().ToString().Substring(0, 8),
                    email_subject   = "You Have a Payment!"
                },
                items = payoutItems,
            };

            var createPayout = payout.Create(apiContext);

            var batchId = createPayout.batch_header.payout_batch_id;
            var get     = Payout.Get(apiContext, batchId);

            var price = decimal.Parse(get.batch_header.amount.value);

            var payoutPayPal = new PayoutPayPal
            {
                BatchId   = batchId,
                Amount    = price,
                CreatedOn = DateTime.UtcNow.AddHours(GlobalConstants.BULGARIAN_HOURS_FROM_UTC_TIME)
            };

            var forDelete = this.db.PaymentsToInstructors.ToList();

            this.db.PaymentsToInstructors.RemoveRange(forDelete);

            this.db.PayoutPayPals.Add(payoutPayPal);
            this.db.SaveChanges();
        }
Exemplo n.º 5
0
        public ActionResult GetPayout()
        {
            var pay = CreatePayout();

            if (pay.batch_header.batch_status == "PENDING")
            {
                APIContext ApiContext = Configuration.GetAPIContext();
                var        payout     = new Payout();
                payout.Create(ApiContext);
                return(Json(Payout.Get(ApiContext, pay.batch_header.payout_batch_id), JsonRequestBehavior.AllowGet));
            }
            return(Json(-1, JsonRequestBehavior.AllowGet));
        }
Exemplo n.º 6
0
        private TransactionResponse CommitTransactionUsingLatestApi(TransactionRequest request)
        {
            Random random = new Random();

            int batchID1 = 1000000 + random.Next(1, 1000000);
            int batchID2 = 1000000 + random.Next(1, 1000000);

            var config = new Dictionary <string, string>();

            config["mode"]         = "live";
            config["clientId"]     = accountDetails.ClientID;
            config["clientSecret"] = accountDetails.ClientSecret;

            var accessToken = new OAuthTokenCredential(config).GetAccessToken();
            var apiContext  = new APIContext(accessToken);

            var payout = new Payout
            {
                sender_batch_header = new PayoutSenderBatchHeader
                {
                    sender_batch_id = batchID1.ToString(),
                    email_subject   = AppSettings.Payments.TransactionNote,
                    recipient_type  = PayoutRecipientType.EMAIL
                },
                items = new List <PayoutItem>()
                {
                    new PayoutItem
                    {
                        recipient_type = PayoutRecipientType.EMAIL,
                        amount         = new Currency
                        {
                            value    = request.Payment.ToShortClearString(),
                            currency = AppSettings.Site.CurrencyCode
                        },
                        note           = AppSettings.Payments.TransactionNote,
                        sender_item_id = batchID2.ToString(),
                        receiver       = request.PayeeId
                    }
                }
            };

            var result = payout.Create(apiContext);

            string PayoutBatchID = result.batch_header.payout_batch_id;

            return(new PayPalTransactionResponse(this, Payout.Get(apiContext, PayoutBatchID)));
        }
Exemplo n.º 7
0
    protected void Button1_Click1(object sender, EventArgs e)
    {
        var apiContext = Configuration.GetAPIContext();

        // 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    = "5",
                        currency = "USD"
                    },
                    receiver       = "*****@*****.**",
                    note           = "Thank you.",
                    sender_item_id = "item_1"
                }
                //new PayoutItem
                //{
                //    recipient_type = PayoutRecipientType.EMAIL,
                //    amount = new Currency
                //    {
                //        value = "0.10",
                //        currency = "USD"
                //    },
                //    receiver = "*****@*****.**",
                //    note = "Thank you.",
                //    sender_item_id = "item_2"
                //},
                //new PayoutItem
                //{
                //    recipient_type = PayoutRecipientType.EMAIL,
                //    amount = new Currency
                //    {
                //        value = "0.10",
                //        currency = "USD"
                //    },
                //    receiver = "*****@*****.**",
                //    note = "Thank you.",
                //    sender_item_id = "item_3"
                //}
            }
        };

        // ^ Ignore workflow code segment
        //#region Track Workflow
        //this.flow.AddNewRequest("Create payout", payout);
        //#endregion

        // ### 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, true);

        Label1.Text = createdPayout.batch_header.payout_batch_id;



        var payoutBatchId = Label1.Text;



        var payoutt = Payout.Get(apiContext, payoutBatchId);

        //var payoutItemId = Label1.Text;

        //var payoutItemDetails = PayoutItem.Get(apiContext, payoutItemId);
        Label2.Text = payoutt.batch_header.batch_status;
    }
        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);
        }