forked from rajarampadmanathan/Checkout-Java-SDK-1
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathErrorSample.java
More file actions
63 lines (55 loc) · 2.34 KB
/
ErrorSample.java
File metadata and controls
63 lines (55 loc) · 2.34 KB
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
package com.paypal;
import com.paypal.http.HttpResponse;
import com.paypal.http.exceptions.HttpException;
import org.json.JSONObject;
import java.io.IOException;
import java.util.*;
import com.paypal.orders.*;
public class ErrorSample extends PayPalClient {
/**
* Body has no required parameters (intent, purchase_units)
*/
public void createError1() {
OrdersCreateRequest request = new OrdersCreateRequest();
request.requestBody(new OrderRequest());
System.out.println("Request Body: {}\n");
System.out.println("Response:");
try {
HttpResponse<Order> response = client.execute(request);
} catch (IOException e){
HttpException h = (HttpException) e;
JSONObject message = new JSONObject(h.getMessage());
System.out.println(this.prettyPrint(message, ""));
System.out.println();
}
}
/**
* Body has invalid parameter value for intent
*/
public void createError2() {
OrdersCreateRequest request = new OrdersCreateRequest();
request.requestBody(new OrderRequest()
.checkoutPaymentIntent("INVALID")
.purchaseUnits(new ArrayList<PurchaseUnitRequest>() {{
add(new PurchaseUnitRequest().amountWithBreakdown(new AmountWithBreakdown().currencyCode("USD").value("100.00")));
}}));
System.out.println("Request Body:");
System.out.println("{\n\"intent\": \"INVALID\",\n\"purchase_units\": [\n{\n\"amount\": {\n\"currency_code\": \"USD\",\n\"value\": \"100.00\"\n}\n}\n]\n}\n");
System.out.println("Response:");
try {
HttpResponse<Order> response = client.execute(request);
} catch (IOException e){
HttpException h = (HttpException) e;
JSONObject message = new JSONObject(h.getMessage());
System.out.println(this.prettyPrint(message, ""));
System.out.println();
}
}
public static void main(String[] args) {
ErrorSample errorSample = new ErrorSample();
System.out.println("Calling createError1 (Body has no required parameters (intent, purchase_units))");
errorSample.createError1();
System.out.println("Calling createError2 (Body has invalid parameter value for intent)");
errorSample.createError2();
}
}