Ejemplo n.º 1
0
 /**
  * Creates (and processes) a new Capture Transaction added as a related resource.
  *
  * @param apiContext {@link APIContext} used for the API call.
  * @param capture Capture
  * @return Capture
  * @throws PayPalRESTException
  */
 public Capture capture(APIContext apiContext, Capture capture) throws PayPalRESTException {
   if (apiContext == null) {
     throw new IllegalArgumentException("APIContext cannot be null");
   }
   if (apiContext.getAccessToken() == null || apiContext.getAccessToken().trim().length() <= 0) {
     throw new IllegalArgumentException("AccessToken cannot be null or empty");
   }
   if (apiContext.getHTTPHeaders() == null) {
     apiContext.setHTTPHeaders(new HashMap<String, String>());
   }
   apiContext
       .getHTTPHeaders()
       .put(Constants.HTTP_CONTENT_TYPE_HEADER, Constants.HTTP_CONTENT_TYPE_JSON);
   apiContext.setSdkVersion(new SDKVersionImpl());
   if (this.getId() == null) {
     throw new IllegalArgumentException("Id cannot be null");
   }
   if (capture == null) {
     throw new IllegalArgumentException("capture cannot be null");
   }
   Object[] parameters = new Object[] {this.getId()};
   String pattern = "v1/payments/orders/{0}/capture";
   String resourcePath = RESTUtil.formatURIPath(pattern, parameters);
   String payLoad = capture.toJSON();
   return configureAndExecute(apiContext, HttpMethod.POST, resourcePath, payLoad, Capture.class);
 }