59 lines
2.2 KiB
Java
59 lines
2.2 KiB
Java
|
|
package com.paypal;
|
||
|
|
|
||
|
|
import com.paypal.http.HttpRequest;
|
||
|
|
import com.paypal.http.HttpResponse;
|
||
|
|
import com.paypal.http.exceptions.HttpException;
|
||
|
|
import com.paypal.orders.AmountWithBreakdown;
|
||
|
|
import com.paypal.orders.OrderRequest;
|
||
|
|
import com.paypal.orders.OrdersCreateRequest;
|
||
|
|
import com.paypal.orders.PurchaseUnitRequest;
|
||
|
|
import java.io.IOException;
|
||
|
|
import java.util.ArrayList;
|
||
|
|
import org.json.JSONObject;
|
||
|
|
|
||
|
|
public class ErrorSample extends PayPalClient {
|
||
|
|
public void createError1() {
|
||
|
|
OrdersCreateRequest request = new OrdersCreateRequest();
|
||
|
|
request.requestBody(new OrderRequest());
|
||
|
|
System.out.println("Request Body: {}\n");
|
||
|
|
System.out.println("Response:");
|
||
|
|
try {
|
||
|
|
HttpResponse httpResponse = this.client.execute((HttpRequest)request);
|
||
|
|
} catch (IOException e) {
|
||
|
|
HttpException h = (HttpException)e;
|
||
|
|
JSONObject message = new JSONObject(h.getMessage());
|
||
|
|
System.out.println(prettyPrint(message, ""));
|
||
|
|
System.out.println();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public void createError2() {
|
||
|
|
OrdersCreateRequest request = new OrdersCreateRequest();
|
||
|
|
request.requestBody(new OrderRequest()
|
||
|
|
.checkoutPaymentIntent("INVALID")
|
||
|
|
.purchaseUnits(new ArrayList<>() {
|
||
|
|
{
|
||
|
|
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 httpResponse = this.client.execute((HttpRequest)request);
|
||
|
|
} catch (IOException e) {
|
||
|
|
HttpException h = (HttpException)e;
|
||
|
|
JSONObject message = new JSONObject(h.getMessage());
|
||
|
|
System.out.println(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();
|
||
|
|
}
|
||
|
|
}
|