Skip to content

Commit 5d968e9

Browse files
Updated README.md
1 parent cc8942d commit 5d968e9

File tree

1 file changed

+45
-49
lines changed

1 file changed

+45
-49
lines changed

README.MD

Lines changed: 45 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,27 @@ An environment which supports TLS 1.2 (see the TLS-update site for more informat
1818
Get client ID and client secret by going to https://developer.paypal.com/developer/applications and generating a REST API app. Get <b>Client ID</b> and <b>Secret</b> from there.
1919

2020
```dotnet
21+
using System;
2122
using PayPalCheckoutSdk.Core;
23+
using PayPalCheckoutSdk.Orders;
24+
using BraintreeHttp;
25+
using System.Collections.Generic;
26+
using System.Threading.Tasks;
27+
28+
public class CaptureOrderSample
29+
{
30+
static String clientId = "PAYPAL-CLIENT-ID";
31+
static String secret = "PAYPAL-CLIENT-SECRET";
2232
23-
public class Credentials {
24-
static String clientId = "CLIENT-ID";
25-
static String secret = "CLIENT-SECRET";
26-
33+
public static HttpClient client()
34+
{
2735
// Creating a sandbox environment
28-
var environment = new SandboxEnvironment(clientId, secret);
29-
36+
PayPalEnvironment environment = new SandboxEnvironment(clientId, secret);
37+
3038
// Creating a client for the environment
31-
var client = new PayPalHttpClient(environment);
39+
PayPalHttpClient client = new PayPalHttpClient(environment);
40+
return client;
41+
}
3242
}
3343
```
3444

@@ -37,11 +47,9 @@ public class Credentials {
3747
This will create an order and print order id for the created order
3848

3949
```dotnet
40-
using PayPalCheckoutSdk.Orders;
41-
42-
public class CreateOrderExample {
43-
static void main(String[] args){
44-
50+
public async static Task<HttpResponse> createOrder()
51+
{
52+
HttpResponse response;
4553
// Construct a request object and set desired parameters
4654
// Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders
4755
var order = new OrderRequest() {
@@ -50,68 +58,56 @@ public class CreateOrderExample {
5058
{
5159
new PurchaseUnitRequest()
5260
{
53-
ReferenceId = "test_ref_id1",
5461
Amount = new AmountWithBreakdown()
5562
{
5663
CurrencyCode = "USD",
5764
Value = "100.00"
5865
}
5966
}
60-
},
67+
},
6168
ApplicationContext = new ApplicationContext()
6269
{
6370
ReturnUrl = "https://www.example.com",
6471
CancelUrl = "https://www.example.com"
6572
}
6673
};
67-
68-
74+
75+
6976
// Call API with your client and get a response for your call
7077
var request = new OrdersCreateRequest();
7178
request.Prefer("return=representation");
7279
request.RequestBody(order);
73-
try
74-
{
75-
HttpResponse response = await client().Execute(request);
76-
var statusCode = response.StatusCode;
77-
Order result = response.Result<Payment>();
78-
}
79-
catch(HttpException httpException)
80+
response = await client().Execute(request);
81+
var statusCode = response.StatusCode;
82+
Order result = response.Result<Order>();
83+
Console.WriteLine("Status: {0}", result.Status);
84+
Console.WriteLine("Order Id: {0}", result.Id);
85+
Console.WriteLine("Intent: {0}", result.Intent);
86+
Console.WriteLine("Links:");
87+
foreach (LinkDescription link in result.Links)
8088
{
81-
var statusCode = httpException.StatusCode;
82-
var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
89+
Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
8390
}
91+
return response;
8492
}
85-
}
8693
```
8794

8895
### Capturing an Order
89-
This will capture an order
96+
Before capturing an order, order should be approved by the buyer using the approve link in create order response
9097
```dotnet
91-
using PayPalCheckoutSdk.Orders;
92-
93-
public class CaptureOrderExample {
94-
static void main(String[] args){
95-
98+
public async static Task<HttpResponse> captureOrder()
99+
{
96100
// Construct a request object and set desired parameters
97-
// Here, OrdersCaptureRequest() creates a POST request to /v2/checkout/orders
98-
// Replace ORDER-ID with the order id from create order
99-
var request = new OrdersCaptureRequest("ORDER-ID");
100-
101-
request.RequestBody(order);
102-
try
103-
{
104-
HttpResponse response = await client().Execute(request);
105-
var statusCode = response.StatusCode;
106-
Order result = response.Result<Payment>();
107-
}
108-
catch(HttpException httpException)
109-
{
110-
var statusCode = httpException.StatusCode;
111-
var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
112-
}
101+
// Replace ORDER-ID with the approved order id from create order
102+
var request = new OrdersCaptureRequest("69E54436G09638353");
103+
request.RequestBody(new OrderActionRequest());
104+
HttpResponse response = await client().Execute(request);
105+
var statusCode = response.StatusCode;
106+
Order result = response.Result<Order>();
107+
Console.WriteLine("Status: {0}", result.Status);
108+
Console.WriteLine("Capture Id: {0}", result.Id);
109+
return response;
113110
}
114-
}
115111
```
116112
## Running tests
117113

0 commit comments

Comments
 (0)