use of com.braintreegateway.CreditCardAddressRequest in project J2PAY by tranxactive.
the class BraintreeGateway method createCustomer.
private HTTPResponse createCustomer(JSONObject apiParameters, Customer customer, CustomerCard customerCard, Currency currency, float amount) {
boolean hasException = false;
CustomerRequest customerRequest = new CustomerRequest();
customerRequest.firstName(customer.getFirstName()).lastName(customer.getLastName()).email(customer.getEmail()).phone(customer.getPhoneNumber());
CreditCardRequest card = customerRequest.creditCard();
card.cardholderName(customerCard.getName()).number(customerCard.getNumber()).cvv(customerCard.getCvv()).expirationDate(customerCard.getExpiryMonth() + "/" + customerCard.getExpiryYear());
CreditCardAddressRequest address = card.billingAddress();
address.countryCodeAlpha3(customer.getCountry().getCodeISO3()).postalCode(customer.getZip()).streetAddress(customer.getAddress()).region(customer.getState()).locality(customer.getCity());
Result<com.braintreegateway.Customer> createCustomer = null;
GeneralResponse successResponse = null;
ErrorResponse errorResponse = new ErrorResponse();
HTTPResponse httpResponse = new HTTPResponse();
try {
createCustomer = getGatewayObject(apiParameters).customer().create(customerRequest);
} catch (NotFoundException e) {
errorResponse.setMessage("No record found");
hasException = true;
} catch (AuthenticationException e) {
errorResponse.setMessage("Invalid credentials");
hasException = true;
} catch (AuthorizationException e) {
errorResponse.setMessage("Not authorized to perform this action");
hasException = true;
} catch (ConfigurationException e) {
errorResponse.setMessage("Configuratoin error");
hasException = true;
} catch (DownForMaintenanceException e) {
errorResponse.setMessage("Server is under maintenance");
hasException = true;
} catch (TimeoutException e) {
errorResponse.setMessage("Request time out");
hasException = true;
} catch (ForgedQueryStringException | InvalidChallengeException | InvalidSignatureException | UnexpectedException e) {
errorResponse.setMessage("Unexpected exception occured");
hasException = true;
} catch (ServerException e) {
errorResponse.setMessage("Server error");
hasException = true;
} catch (TooManyRequestsException e) {
errorResponse.setMessage("Too many requests");
hasException = true;
} catch (UpgradeRequiredException e) {
errorResponse.setMessage("Need to upgrade");
hasException = true;
}
if (hasException) {
processFinalResponse(null, httpResponse, successResponse, errorResponse);
return httpResponse;
}
if (createCustomer.isSuccess()) {
successResponse = new GeneralResponse();
successResponse.setMessage("Success");
successResponse.setTransactionId(createCustomer.getTarget().getId());
} else {
errorResponse.setMessage(createCustomer.getMessage());
}
processFinalResponse(null, httpResponse, successResponse, errorResponse);
return httpResponse;
}
Aggregations