// If you do not wish to use the Billing Address coming back from the Gateway, you can override the
// populateBillingInfo() method or set the useBillingAddressFromGateway property.
populateBillingInfo(responseDTO, payment, tempBillingAddress);
// Create the transaction for the payment
PaymentTransaction transaction = orderPaymentService.createTransaction();
transaction.setAmount(responseDTO.getAmount());
transaction.setRawResponse(responseDTO.getRawResponse());
transaction.setSuccess(responseDTO.isSuccessful());
transaction.setType(responseDTO.getPaymentTransactionType());
for (Entry<String, String> entry : responseDTO.getResponseMap().entrySet()) {
transaction.getAdditionalFields().put(entry.getKey(), entry.getValue());
}
//Set the Credit Card Info on the Additional Fields Map
if (PaymentType.CREDIT_CARD.equals(responseDTO.getPaymentType()) &&
responseDTO.getCreditCard().creditCardPopulated()) {
transaction.getAdditionalFields().put(PaymentAdditionalFieldType.NAME_ON_CARD.getType(),
responseDTO.getCreditCard().getCreditCardHolderName());
transaction.getAdditionalFields().put(PaymentAdditionalFieldType.CARD_TYPE.getType(),
responseDTO.getCreditCard().getCreditCardType());
transaction.getAdditionalFields().put(PaymentAdditionalFieldType.EXP_DATE.getType(),
responseDTO.getCreditCard().getCreditCardExpDate());
transaction.getAdditionalFields().put(PaymentAdditionalFieldType.LAST_FOUR.getType(),
responseDTO.getCreditCard().getCreditCardLastFour());
}
//TODO: validate that this particular type of transaction can be added to the payment (there might already
// be an AUTHORIZE transaction, for instance)
//Persist the order payment as well as its transaction
payment.setOrder(order);
transaction.setOrderPayment(payment);
payment.addTransaction(transaction);
payment = orderPaymentService.save(payment);
if (transaction.getSuccess()) {
orderService.addPaymentToOrder(order, payment, null);
} else {
// We will have to mark the entire payment as invalid and boot the user to re-enter their
// billing info and payment information as there may be an error either with the billing address/or credit card
handleUnsuccessfulTransaction(payment);