public async Task <Order> CaptureOrder(string OrderId, bool debug = true) { var request = new OrdersCaptureRequest(OrderId); request.Prefer("return=representation"); request.RequestBody(new OrderActionRequest()); //3. Call PayPal to capture an order var response = await PayPalClientService.Client().Execute(request); //4. Save the capture ID to your database. Implement logic to save capture to your database for future reference. //if (debug) //{ var result = response.Result <Order>(); Console.WriteLine("Status: {0}", result.Status); Console.WriteLine("Order Id: {0}", result.Id); Console.WriteLine("Intent: {0}", result.CheckoutPaymentIntent); 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("Capture Ids: "); foreach (PurchaseUnit purchaseUnit in result.PurchaseUnits) { foreach (Capture capture in purchaseUnit.Payments.Captures) { Console.WriteLine("\t {0}", capture.Id); } } PayPalCheckoutSdk.Orders.AmountWithBreakdown amount = result.PurchaseUnits[0].AmountWithBreakdown; Console.WriteLine("Buyer:"); Console.WriteLine("\tEmail Address: {0}\n\tName: {1}\n\tPhone Number: {2}", result.Payer.Email, result.Payer.Name.GivenName + " " + result.Payer.Name.Surname, result.Payer.AddressPortable.CountryCode ); //} return(result); //return Json(new //{ // id = result.Id, // CheckoutPaymentIntent = result.CheckoutPaymentIntent, // CreateTime = result.CreateTime, // Links = result.Links, // Payer = result.Payer, // PurchaseUnits = result.PurchaseUnits, // Status = result.Status, // UpdateTime = result.UpdateTime, // GivenName = result.Payer.Name.GivenName, // SurName = result.Payer.Name.Surname, //}); }
public async Task <Order> CreateOrder(CreateOrderCommand command, bool debug = true) { var request = new OrdersCreateRequest(); request.Prefer("return=representation"); request.RequestBody(BuildRequestBody(command)); //3. Call PayPal to set up a transaction var response = await PayPalClientService.Client().Execute(request); //if (debug) //{ var result = response.Result <Order>(); Console.WriteLine("Status: {0}", result.Status); Console.WriteLine("Order Id: {0}", result.Id); Console.WriteLine("Intent: {0}", result.CheckoutPaymentIntent /*Intent*/); Console.WriteLine("Links:"); foreach (LinkDescription link in result.Links) { Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method); } PayPalCheckoutSdk.Orders.AmountWithBreakdown amount = result.PurchaseUnits[0].AmountWithBreakdown /*Amount*/; Console.WriteLine("Total Amount: {0} {1}", amount.CurrencyCode, amount.Value); //} return(result); //return Json(new //{ // id = result.Id, // CheckoutPaymentIntent = result.CheckoutPaymentIntent, // CreateTime = result.CreateTime, // ExpirationTime = result.ExpirationTime, // Links = result.Links, // Payer = result.Payer, // PurchaseUnits = result.PurchaseUnits, // Status = result.Status, // UpdateTime = result.UpdateTime //}); }