Skip to content

Commit 292876d

Browse files
Merge pull request #7 from paypal/master
master to develop
2 parents 338839b + 5c7e556 commit 292876d

File tree

1 file changed

+53
-52
lines changed

1 file changed

+53
-52
lines changed

README.MD

Lines changed: 53 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,36 @@ An environment which supports TLS 1.2 (see the TLS-update site for more informat
1414

1515
## Usage
1616

17+
### Binaries
18+
19+
It is not mandatory to fork this repository for using the PayPal SDK. You can refer [PayPal Checkout Server SDK](https://developer.paypal.com/docs/checkout/reference/server-integration) for configuring and working with SDK without forking this code.
20+
21+
For contirbuting or referrring the samples, You can fork/refer this repository.
1722
### Setting up credentials
1823
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.
1924

2025
```dotnet
26+
using System;
2127
using PayPalCheckoutSdk.Core;
28+
using PayPalCheckoutSdk.Orders;
29+
using BraintreeHttp;
30+
using System.Collections.Generic;
31+
using System.Threading.Tasks;
2232
23-
public class Credentials {
24-
static String clientId = "CLIENT-ID";
25-
static String secret = "CLIENT-SECRET";
26-
33+
public class CaptureOrderSample
34+
{
35+
static String clientId = "PAYPAL-CLIENT-ID";
36+
static String secret = "PAYPAL-CLIENT-SECRET";
37+
38+
public static HttpClient client()
39+
{
2740
// Creating a sandbox environment
28-
var environment = new SandboxEnvironment(clientId, secret);
29-
41+
PayPalEnvironment environment = new SandboxEnvironment(clientId, secret);
42+
3043
// Creating a client for the environment
31-
var client = new PayPalHttpClient(environment);
44+
PayPalHttpClient client = new PayPalHttpClient(environment);
45+
return client;
46+
}
3247
}
3348
```
3449

@@ -37,11 +52,9 @@ public class Credentials {
3752
This will create an order and print order id for the created order
3853

3954
```dotnet
40-
using PayPalCheckoutSdk.Orders;
41-
42-
public class CreateOrderExample {
43-
static void main(String[] args){
44-
55+
public async static Task<HttpResponse> createOrder()
56+
{
57+
HttpResponse response;
4558
// Construct a request object and set desired parameters
4659
// Here, OrdersCreateRequest() creates a POST request to /v2/checkout/orders
4760
var order = new OrderRequest() {
@@ -50,83 +63,71 @@ public class CreateOrderExample {
5063
{
5164
new PurchaseUnitRequest()
5265
{
53-
ReferenceId = "test_ref_id1",
5466
Amount = new AmountWithBreakdown()
5567
{
5668
CurrencyCode = "USD",
5769
Value = "100.00"
5870
}
5971
}
60-
},
72+
},
6173
ApplicationContext = new ApplicationContext()
6274
{
6375
ReturnUrl = "https://www.example.com",
6476
CancelUrl = "https://www.example.com"
6577
}
6678
};
67-
68-
79+
80+
6981
// Call API with your client and get a response for your call
7082
var request = new OrdersCreateRequest();
7183
request.Prefer("return=representation");
7284
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)
85+
response = await client().Execute(request);
86+
var statusCode = response.StatusCode;
87+
Order result = response.Result<Order>();
88+
Console.WriteLine("Status: {0}", result.Status);
89+
Console.WriteLine("Order Id: {0}", result.Id);
90+
Console.WriteLine("Intent: {0}", result.Intent);
91+
Console.WriteLine("Links:");
92+
foreach (LinkDescription link in result.Links)
8093
{
81-
var statusCode = httpException.StatusCode;
82-
var debugId = httpException.Headers.GetValues("PayPal-Debug-Id").FirstOrDefault();
94+
Console.WriteLine("\t{0}: {1}\tCall Type: {2}", link.Rel, link.Href, link.Method);
8395
}
96+
return response;
8497
}
85-
}
8698
```
8799

88100
### Capturing an Order
89-
This will capture an order
101+
Before capturing an order, order should be approved by the buyer using the approve link in create order response
90102
```dotnet
91-
using PayPalCheckoutSdk.Orders;
92-
93-
public class CaptureOrderExample {
94-
static void main(String[] args){
95-
103+
public async static Task<HttpResponse> captureOrder()
104+
{
96105
// 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-
}
106+
// Replace ORDER-ID with the approved order id from create order
107+
var request = new OrdersCaptureRequest("69E54436G09638353");
108+
request.RequestBody(new OrderActionRequest());
109+
HttpResponse response = await client().Execute(request);
110+
var statusCode = response.StatusCode;
111+
Order result = response.Result<Order>();
112+
Console.WriteLine("Status: {0}", result.Status);
113+
Console.WriteLine("Capture Id: {0}", result.Id);
114+
return response;
113115
}
114-
}
115116
```
116117
## Running tests
117118

118119
To run integration tests using your client id and secret, run the `test` gradle command with the `-Pintegration` flag
119120
```sh
120-
$ dotnet test -v normal
121+
$ PAYPAL_CLIENT_ID=YOUR_SANDBOX_CLIENT_ID PAYPAL_CLIENT_SECRET=YOUR_SANDBOX_CLIENT_SECRET dotnet test -v normal
121122
```
122123

123124
You may use the client id and secret above for demonstration purposes.
124125

125126

126-
*NOTE*: This SDK is still in beta, is subject to change, and should not be used in production.
127-
128127
## Samples
129128

130129
You can start off by trying out [creating and capturing an order](/Samples/CaptureIntentExamples/RunAll.java).
131130

132131
To try out different samples for both create and authorize intent head to [this link](/Samples).
132+
133+
Note: Update the `PayPalClient.cs` with your sandbox client credentials or pass your client credentials as environment variable whie executing the samples.

0 commit comments

Comments
 (0)