public async static Task <HttpResponse> GetPayout(string batchId, bool debug = false)
        {
            try{
                PayoutsGetRequest request = new PayoutsGetRequest(batchId);
                var getResponse           = await PayPalClient.client().Execute(request);

                var result = getResponse.Result <PayoutBatch>();
                if (debug)
                {
                    Console.WriteLine("Status: {0}", result.BatchHeader.BatchStatus);
                    Console.WriteLine("Item: {0}", result.Items[0].PayoutItemId);
                    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(getResponse);
            } catch (HttpException ex) {
                String errorString = ex.Message;
                Error  error       = ErrorUtil.deserializeError(errorString);
                ErrorUtil.printError(error);
                return(null);
            }
        }
Exemple #2
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);
            }
        }
        /*
         *  This method cn be used to patch an order by passing the order id.
         */
        public async static Task <HttpResponse> PatchOrder(string orderId, bool debug = false)
        {
            var request = new OrdersPatchRequest <Object>(orderId);

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

            if (debug)
            {
                var ordersGetRequest = new OrdersGetRequest(orderId);
                response = await PayPalClient.client().Execute(ordersGetRequest);

                var result = response.Result <Order>();
                Console.WriteLine("Retrieved Order Status After Patch");
                Console.WriteLine("Status: {0}", result.Status);
                Console.WriteLine("Order Id: {0}", result.Id);
                Console.WriteLine("Intent: {0}", result.Intent);
                Console.WriteLine("Links:");
                foreach (LinkDescription link in result.Links)
                {
                    Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
                }
                AmountWithBreakdown amount = result.PurchaseUnits[0].Amount;
                Console.WriteLine("Total Amount: {0} {1}", amount.CurrencyCode, amount.Value);
                Console.WriteLine("Response JSON: \n {0}", PayPalClient.ObjectToJSONString(result));
            }
            return(response);
        }
        public async static Task <HttpResponse> CancelItem(string itemId, bool debug = false)
        {
            try {
                PayoutsItemCancelRequest request = new PayoutsItemCancelRequest(itemId);
                var cancelResponse = await PayPalClient.client().Execute(request);

                var result = cancelResponse.Result <PayoutItemResponse>();
                if (debug)
                {
                    Console.WriteLine("Batch: {0}", result.PayoutBatchId);
                    Console.WriteLine("Item: {0}", result.PayoutItemId);
                    Console.WriteLine("status: {0}", result.TransactionStatus);

                    Console.WriteLine("Links:");
                    foreach (LinkDescription link in result.Links)
                    {
                        Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
                    }
                }
                return(cancelResponse);
            } catch (HttpException ex) {
                String errorString = ex.Message;
                Error  error       = ErrorUtil.deserializeError(errorString);
                ErrorUtil.printError(error);
                return(null);
            }
        }
        /*
         *  Method for refund the capture. Valid capture Id should be
         *       passed an argument to this method.
         */
        public async static Task <HttpResponse> CapturesRefund(string CaptureId, bool debug = false)
        {
            var request = new CapturesRefundRequest(CaptureId);

            request.Prefer("return=representation");
            RefundRequest refundRequest = new RefundRequest()
            {
                Amount = new Money {
                    Value        = "20.00",
                    CurrencyCode = "USD"
                }
            };

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

            if (debug)
            {
                var result = response.Result <Refund>();
                Console.WriteLine("Status: {0}", result.Status);
                Console.WriteLine("Refund Id: {0}", result.Id);
                Console.WriteLine("Links:");
                foreach (LinkDescription link in result.Links)
                {
                    Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
                }
                Console.WriteLine("Response JSON: \n {0}", PayPalClient.ObjectToJSONString(result));
            }
            return(response);
        }
Exemple #6
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);
        }
Exemple #7
0
        public async static Task <HttpResponse> GetPayoutItem(string itemId, bool debug = false)
        {
            PayoutsItemGetRequest request = new PayoutsItemGetRequest(itemId);
            var getResponse = await PayPalClient.client().Execute(request);

            var result = getResponse.Result <PayoutItemResponse>();

            if (debug)
            {
                Console.WriteLine("Batch: {0}", result.PayoutBatchId);
                Console.WriteLine("Item: {0}", result.PayoutItemId);
                Console.WriteLine("Links:");
                foreach (LinkDescription link in result.Links)
                {
                    Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
                }
            }
            return(getResponse);
        }