-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathPatchOrderSample.cs
82 lines (75 loc) · 3.04 KB
/
PatchOrderSample.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using BraintreeHttp;
using PayPalCheckoutSdk.Core;
using PayPalCheckoutSdk.Orders;
using Samples.AuthorizeIntentExamples;
namespace Samples
{
public class PatchOrderSample
{
/**
This method can be used to build the patch request body.
*/
private static List<Patch<Object>> BuildPatchRequest()
{
var patches = new List<Patch<Object>>
{
new Patch<Object>
{
Op= "replace",
Path= "/intent",
Value= "CAPTURE"
},
new Patch<Object>
{
Op= "replace",
Path= "/purchase_units/@reference_id=='PUHF'/description",
Value= "Physical Goods"
}
};
return patches;
}
/*
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;
}
/*
This is the driver method which invokes the patchOrder function with Order Id
to patch an order details.
To get the new Order id, we are using the createOrder to create new order
and then we are using the newly created order id.
*/
// static void Main(string[] args)
// {
// HttpResponse createdResponse = CreateOrderSample.CreateOrder(true).Result;
// Console.WriteLine("\nAfter PATCH (Changed Intent and Amount):");
// PatchOrder(createdResponse.Result<Order>().Id, true).Wait();
// }
}
}