@@ -175,138 +175,6 @@ private GetChargeResponse _handleUpdateChargeMetadataResponse(HttpContext _conte
175175 return _result ;
176176 }
177177
178- /**
179- * Captures a charge
180- * @param chargeId Required parameter: Charge id
181- * @param request Optional parameter: Request for capturing a charge
182- * @param idempotencyKey Optional parameter: Example:
183- * @return Returns the GetChargeResponse response from the API call
184- */
185- public GetChargeResponse captureCharge (
186- final String chargeId ,
187- final CreateCaptureChargeRequest request ,
188- final String idempotencyKey
189- ) throws Throwable {
190-
191- HttpRequest _request = _buildCaptureChargeRequest (chargeId , request , idempotencyKey );
192- HttpResponse _response = getClientInstance ().executeAsString (_request );
193- HttpContext _context = new HttpContext (_request , _response );
194-
195- return _handleCaptureChargeResponse (_context );
196- }
197-
198- /**
199- * Captures a charge
200- * @param chargeId Required parameter: Charge id
201- * @param request Optional parameter: Request for capturing a charge
202- * @param idempotencyKey Optional parameter: Example:
203- */
204- public void captureChargeAsync (
205- final String chargeId ,
206- final CreateCaptureChargeRequest request ,
207- final String idempotencyKey ,
208- final APICallBack <GetChargeResponse > callBack
209- ) {
210- Runnable _responseTask = new Runnable () {
211- public void run () {
212-
213- HttpRequest _request ;
214- try {
215- _request = _buildCaptureChargeRequest (chargeId , request , idempotencyKey );
216- } catch (Exception e ) {
217- callBack .onFailure (null , e );
218- return ;
219- }
220-
221- // Invoke request and get response
222- getClientInstance ().executeAsStringAsync (_request , new APICallBack <HttpResponse >() {
223- public void onSuccess (HttpContext _context , HttpResponse _response ) {
224- try {
225- GetChargeResponse returnValue = _handleCaptureChargeResponse (_context );
226- callBack .onSuccess (_context , returnValue );
227- } catch (Exception e ) {
228- callBack .onFailure (_context , e );
229- }
230- }
231-
232- public void onFailure (HttpContext _context , Throwable _exception ) {
233- // Let the caller know of the failure
234- callBack .onFailure (_context , _exception );
235- }
236- });
237- }
238- };
239-
240- // Execute async using thread pool
241- APIHelper .getScheduler ().execute (_responseTask );
242- }
243-
244- /**
245- * Builds the HttpRequest object for captureCharge
246- */
247- private HttpRequest _buildCaptureChargeRequest (
248- final String chargeId ,
249- final CreateCaptureChargeRequest request ,
250- final String idempotencyKey ) throws IOException , APIException {
251- //the base uri for api requests
252- String _baseUri = Configuration .baseUri ;
253-
254- //prepare query string for API call
255- StringBuilder _queryBuilder = new StringBuilder (_baseUri + "/charges/{charge_id}/capture" );
256-
257- //process template parameters
258- Map <String , Object > _templateParameters = new HashMap <String , Object >();
259- _templateParameters .put ("charge_id" , chargeId );
260- APIHelper .appendUrlWithTemplateParameters (_queryBuilder , _templateParameters );
261- //validate and preprocess url
262- String _queryUrl = APIHelper .cleanUrl (_queryBuilder );
263-
264- //load all headers for the outgoing API request
265- Map <String , String > _headers = new HashMap <String , String >();
266- if (idempotencyKey != null ) {
267- _headers .put ("idempotency-key" , idempotencyKey );
268- }
269- _headers .put ("user-agent" , BaseController .userAgent );
270- _headers .put ("accept" , "application/json" );
271- _headers .put ("content-type" , "application/json" );
272-
273-
274- //prepare and invoke the API call request to fetch the response
275- HttpRequest _request = getClientInstance ().postBody (_queryUrl , _headers , APIHelper .serialize (request ),
276- Configuration .basicAuthUserName , Configuration .basicAuthPassword );
277-
278- // Invoke the callback before request if its not null
279- if (getHttpCallBack () != null ) {
280- getHttpCallBack ().OnBeforeRequest (_request );
281- }
282-
283- return _request ;
284- }
285-
286- /**
287- * Processes the response for captureCharge
288- * @return An object of type GetChargeResponse
289- */
290- private GetChargeResponse _handleCaptureChargeResponse (HttpContext _context )
291- throws APIException , IOException {
292- HttpResponse _response = _context .getResponse ();
293-
294- //invoke the callback after response if its not null
295- if (getHttpCallBack () != null ) {
296- getHttpCallBack ().OnAfterResponse (_context );
297- }
298-
299- //handle errors defined at the API level
300- validateResponse (_response , _context );
301-
302- //extract result from the http response
303- String _responseBody = ((HttpStringResponse )_response ).getBody ();
304- GetChargeResponse _result = APIHelper .deserialize (_responseBody ,
305- new TypeReference <GetChargeResponse >(){});
306-
307- return _result ;
308- }
309-
310178 /**
311179 * Updates a charge's payment method
312180 * @param chargeId Required parameter: Charge id
@@ -893,6 +761,138 @@ private ListChargesResponse _handleGetChargesResponse(HttpContext _context)
893761 return _result ;
894762 }
895763
764+ /**
765+ * Captures a charge
766+ * @param chargeId Required parameter: Charge id
767+ * @param request Optional parameter: Request for capturing a charge
768+ * @param idempotencyKey Optional parameter: Example:
769+ * @return Returns the GetChargeResponse response from the API call
770+ */
771+ public GetChargeResponse captureCharge (
772+ final String chargeId ,
773+ final CreateCaptureChargeRequest request ,
774+ final String idempotencyKey
775+ ) throws Throwable {
776+
777+ HttpRequest _request = _buildCaptureChargeRequest (chargeId , request , idempotencyKey );
778+ HttpResponse _response = getClientInstance ().executeAsString (_request );
779+ HttpContext _context = new HttpContext (_request , _response );
780+
781+ return _handleCaptureChargeResponse (_context );
782+ }
783+
784+ /**
785+ * Captures a charge
786+ * @param chargeId Required parameter: Charge id
787+ * @param request Optional parameter: Request for capturing a charge
788+ * @param idempotencyKey Optional parameter: Example:
789+ */
790+ public void captureChargeAsync (
791+ final String chargeId ,
792+ final CreateCaptureChargeRequest request ,
793+ final String idempotencyKey ,
794+ final APICallBack <GetChargeResponse > callBack
795+ ) {
796+ Runnable _responseTask = new Runnable () {
797+ public void run () {
798+
799+ HttpRequest _request ;
800+ try {
801+ _request = _buildCaptureChargeRequest (chargeId , request , idempotencyKey );
802+ } catch (Exception e ) {
803+ callBack .onFailure (null , e );
804+ return ;
805+ }
806+
807+ // Invoke request and get response
808+ getClientInstance ().executeAsStringAsync (_request , new APICallBack <HttpResponse >() {
809+ public void onSuccess (HttpContext _context , HttpResponse _response ) {
810+ try {
811+ GetChargeResponse returnValue = _handleCaptureChargeResponse (_context );
812+ callBack .onSuccess (_context , returnValue );
813+ } catch (Exception e ) {
814+ callBack .onFailure (_context , e );
815+ }
816+ }
817+
818+ public void onFailure (HttpContext _context , Throwable _exception ) {
819+ // Let the caller know of the failure
820+ callBack .onFailure (_context , _exception );
821+ }
822+ });
823+ }
824+ };
825+
826+ // Execute async using thread pool
827+ APIHelper .getScheduler ().execute (_responseTask );
828+ }
829+
830+ /**
831+ * Builds the HttpRequest object for captureCharge
832+ */
833+ private HttpRequest _buildCaptureChargeRequest (
834+ final String chargeId ,
835+ final CreateCaptureChargeRequest request ,
836+ final String idempotencyKey ) throws IOException , APIException {
837+ //the base uri for api requests
838+ String _baseUri = Configuration .baseUri ;
839+
840+ //prepare query string for API call
841+ StringBuilder _queryBuilder = new StringBuilder (_baseUri + "/charges/{charge_id}/capture" );
842+
843+ //process template parameters
844+ Map <String , Object > _templateParameters = new HashMap <String , Object >();
845+ _templateParameters .put ("charge_id" , chargeId );
846+ APIHelper .appendUrlWithTemplateParameters (_queryBuilder , _templateParameters );
847+ //validate and preprocess url
848+ String _queryUrl = APIHelper .cleanUrl (_queryBuilder );
849+
850+ //load all headers for the outgoing API request
851+ Map <String , String > _headers = new HashMap <String , String >();
852+ if (idempotencyKey != null ) {
853+ _headers .put ("idempotency-key" , idempotencyKey );
854+ }
855+ _headers .put ("user-agent" , BaseController .userAgent );
856+ _headers .put ("accept" , "application/json" );
857+ _headers .put ("content-type" , "application/json" );
858+
859+
860+ //prepare and invoke the API call request to fetch the response
861+ HttpRequest _request = getClientInstance ().postBody (_queryUrl , _headers , APIHelper .serialize (request ),
862+ Configuration .basicAuthUserName , Configuration .basicAuthPassword );
863+
864+ // Invoke the callback before request if its not null
865+ if (getHttpCallBack () != null ) {
866+ getHttpCallBack ().OnBeforeRequest (_request );
867+ }
868+
869+ return _request ;
870+ }
871+
872+ /**
873+ * Processes the response for captureCharge
874+ * @return An object of type GetChargeResponse
875+ */
876+ private GetChargeResponse _handleCaptureChargeResponse (HttpContext _context )
877+ throws APIException , IOException {
878+ HttpResponse _response = _context .getResponse ();
879+
880+ //invoke the callback after response if its not null
881+ if (getHttpCallBack () != null ) {
882+ getHttpCallBack ().OnAfterResponse (_context );
883+ }
884+
885+ //handle errors defined at the API level
886+ validateResponse (_response , _context );
887+
888+ //extract result from the http response
889+ String _responseBody = ((HttpStringResponse )_response ).getBody ();
890+ GetChargeResponse _result = APIHelper .deserialize (_responseBody ,
891+ new TypeReference <GetChargeResponse >(){});
892+
893+ return _result ;
894+ }
895+
896896 /**
897897 * Updates the card from a charge
898898 * @param chargeId Required parameter: Charge id
0 commit comments