-
Notifications
You must be signed in to change notification settings - Fork 79
/
Copy pathCapturePayment.java
99 lines (82 loc) · 3.75 KB
/
CapturePayment.java
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package samples.payments.coreServices;
import java.util.Properties;
import com.cybersource.authsdk.core.MerchantConfig;
import Api.CaptureApi;
import Data.Configuration;
import Invokers.ApiClient;
import Invokers.ApiException;
import Model.CapturePaymentRequest;
import Model.PtsV2PaymentsCapturesPost201Response;
import Model.PtsV2PaymentsPost201Response;
import Model.Ptsv2paymentsClientReferenceInformation;
import Model.Ptsv2paymentsidcapturesOrderInformation;
import Model.Ptsv2paymentsidcapturesOrderInformationAmountDetails;
import Model.Ptsv2paymentsidcapturesOrderInformationBillTo;
import Model.Ptsv2paymentsidcapturesPointOfSaleInformation;
public class CapturePayment {
private PtsV2PaymentsPost201Response paymentResponse;
private PtsV2PaymentsCapturesPost201Response response;
private Properties merchantProp;
private CapturePaymentRequest request;
private CapturePaymentRequest getRequest() {
request = new CapturePaymentRequest();
Ptsv2paymentsClientReferenceInformation client = new Ptsv2paymentsClientReferenceInformation();
client.code("test_capture");
request.setClientReferenceInformation(client);
Ptsv2paymentsidcapturesPointOfSaleInformation saleInformation = new Ptsv2paymentsidcapturesPointOfSaleInformation();
request.pointOfSaleInformation(saleInformation);
Ptsv2paymentsidcapturesOrderInformationBillTo billTo = new Ptsv2paymentsidcapturesOrderInformationBillTo();
billTo.country("US");
billTo.firstName("John");
billTo.lastName("Deo");
billTo.address1("1 Market St");
billTo.postalCode("94105");
billTo.locality("san francisco");
billTo.administrativeArea("CA");
billTo.email("[email protected]");
Ptsv2paymentsidcapturesOrderInformationAmountDetails amountDetails = new Ptsv2paymentsidcapturesOrderInformationAmountDetails();
amountDetails.totalAmount("100.00");
amountDetails.currency("USD");
Ptsv2paymentsidcapturesOrderInformation orderInformation = new Ptsv2paymentsidcapturesOrderInformation();
orderInformation.billTo(billTo);
orderInformation.amountDetails(amountDetails);
request.setOrderInformation(orderInformation);
return request;
}
public static void main(String args[]) throws Exception {
CapturePayment capturePayment=new CapturePayment();
capturePayment.process();
}
public PtsV2PaymentsCapturesPost201Response process() throws Exception {
String className=CapturePayment.class.getSimpleName();
System.out.println("[BEGIN] EXECUTION OF SAMPLE CODE: "+className+"\n");
ApiClient apiClient=new ApiClient();
try {
request = getRequest();
/* Read Merchant details. */
merchantProp = Configuration.getMerchantDetails();
MerchantConfig merchantConfig = new MerchantConfig(merchantProp);
ProcessPayment processPayment = new ProcessPayment();
paymentResponse = processPayment.process(Boolean.FALSE);
if (paymentResponse != null) {
CaptureApi captureApi = new CaptureApi(merchantConfig);
apiClient=Invokers.Configuration.getDefaultApiClient();
response = captureApi.capturePayment(request, paymentResponse.getId());
}
} catch (ApiException e) {
System.out.println("Exception on calling the Sample Code " +className+": "+apiClient.getRespBody()+"\n");
} finally {
System.out.println("API REQUEST HEADERS:");
System.out.println(apiClient.getRequestHeader() + "\n");
System.out.println("API REQUEST BODY:");
System.out.println(apiClient.getRequestBody() + "\n");
System.out.println("API RESPONSE CODE: " + apiClient.getResponseCode() + "\n");
System.out.println("API RESPONSE HEADERS:");
System.out.println(apiClient.getResponseHeader() + "\n");
System.out.println("API RESPONSE BODY:");
System.out.println(apiClient.getRespBody() + "\n");
System.out.println("[END] EXECUTION OF SAMPLE CODE:" + className + "\n");
}
return response;
}
}