Skip to content

Commit fe4070b

Browse files
committed
Completed validate and confirm activity changes as well as integration test change to specify the different returns for the different save methods.
1 parent 860abb1 commit fe4070b

File tree

2 files changed

+33
-8
lines changed

2 files changed

+33
-8
lines changed

core/broadleaf-framework/src/main/java/org/broadleafcommerce/core/checkout/service/workflow/ValidateAndConfirmPaymentActivity.java

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public ProcessContext<CheckoutSeed> execute(ProcessContext<CheckoutSeed> context
109109
* that transaction
110110
*/
111111
Map<OrderPayment, PaymentTransaction> additionalTransactions = new HashMap<OrderPayment, PaymentTransaction>();
112-
List<PaymentResponseDTO> failedTransactions = new ArrayList<PaymentResponseDTO>();
112+
List<ResponseTransactionPair> failedTransactions = new ArrayList<ResponseTransactionPair>();
113113
// Used for the rollback handler; we want to make sure that we roll back transactions that have already been confirmed
114114
// as well as transctions that we are about to confirm here
115115
List<PaymentTransaction> confirmedTransactions = new ArrayList<PaymentTransaction>();
@@ -188,12 +188,13 @@ public ProcessContext<CheckoutSeed> execute(ProcessContext<CheckoutSeed> context
188188
transaction.setParentTransaction(tx);
189189
transaction.setOrderPayment(payment);
190190
transaction.setAdditionalFields(responseDTO.getResponseMap());
191+
transaction = orderPaymentService.save(transaction);
191192
additionalTransactions.put(payment, transaction);
192193

193194
if (responseDTO.isSuccessful()) {
194195
additionalConfirmedTransactions.put(payment, transaction.getType());
195196
} else {
196-
failedTransactions.add(responseDTO);
197+
failedTransactions.add(new ResponseTransactionPair(responseDTO, transaction.getId()));
197198
}
198199

199200
} else if (PaymentTransactionType.AUTHORIZE.equals(tx.getType()) ||
@@ -275,16 +276,16 @@ public ProcessContext<CheckoutSeed> execute(ProcessContext<CheckoutSeed> context
275276
*
276277
* @param responseDTOs
277278
*/
278-
protected void handleUnsuccessfulTransactions(List<PaymentResponseDTO> responseDTOs, ProcessContext<CheckoutSeed> context) throws Exception {
279+
protected void handleUnsuccessfulTransactions(List<ResponseTransactionPair> responseDTOs, ProcessContext<CheckoutSeed> context) throws Exception {
279280
//The Response DTO was not successful confirming/authorizing a transaction.
280281
String msg = "Attempting to confirm/authorize an UNCONFIRMED transaction on the order was unsuccessful.";
281282
if (LOG.isErrorEnabled()) {
282283
LOG.error(msg);
283284
}
284285

285286
if (LOG.isTraceEnabled()) {
286-
for (PaymentResponseDTO responseDTO : responseDTOs) {
287-
LOG.trace(responseDTO.getRawResponse());
287+
for (ResponseTransactionPair responseTransactionPair : responseDTOs) {
288+
LOG.trace(responseTransactionPair.getResponseDTO().getRawResponse());
288289
}
289290
}
290291

@@ -359,5 +360,26 @@ protected String getGatewayExpirationDateFormat(){
359360
}
360361
return format;
361362
}
363+
364+
protected class ResponseTransactionPair {
365+
PaymentResponseDTO responseDTO;
366+
Long transactionId;
367+
368+
ResponseTransactionPair() {
369+
this(null, null);
370+
}
371+
ResponseTransactionPair(PaymentResponseDTO responseDTO, Long transactionId) {
372+
this.responseDTO = responseDTO;
373+
this.transactionId = transactionId;
374+
}
375+
376+
public PaymentResponseDTO getResponseDTO() {
377+
return responseDTO;
378+
}
379+
380+
public Long getTransactionId() {
381+
return transactionId;
382+
}
383+
}
362384

363385
}

core/broadleaf-framework/src/test/groovy/org/broadleafcommerce/core/spec/checkout/service/workflow/ValidateAndConfirmPaymentActivitySpec.groovy

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ class ValidateAndConfirmPaymentActivitySpec extends BaseCheckoutActivitySpec {
174174
mockRequestService.translatePaymentTransaction(*_) >> new PaymentRequestDTO()
175175
OrderPaymentService mockOrderPaymentService = Mock()
176176
mockOrderPaymentService.createTransaction() >> new PaymentTransactionImpl()
177-
mockOrderPaymentService.save(_) >> {OrderPayment payment -> payment}
177+
mockOrderPaymentService.save(_ as OrderPayment) >> {OrderPayment payment -> payment}
178+
mockOrderPaymentService.save(_ as PaymentTransaction) >> {PaymentTransaction transaction -> transaction}
178179

179180
activity = new ValidateAndConfirmPaymentActivity().with {
180181
paymentConfigurationServiceProvider = mockProvider
@@ -218,7 +219,8 @@ class ValidateAndConfirmPaymentActivitySpec extends BaseCheckoutActivitySpec {
218219
mockRequestService.translatePaymentTransaction(*_) >> new PaymentRequestDTO()
219220
OrderPaymentService mockOrderPaymentService = Mock()
220221
mockOrderPaymentService.createTransaction() >> new PaymentTransactionImpl()
221-
mockOrderPaymentService.save(_) >> {OrderPayment payment -> payment}
222+
mockOrderPaymentService.save(_ as OrderPayment) >> {OrderPayment payment -> payment}
223+
mockOrderPaymentService.save(_ as PaymentTransaction) >> {PaymentTransaction transaction -> transaction}
222224

223225
activity = new ValidateAndConfirmPaymentActivity().with {
224226
paymentConfigurationServiceProvider = mockProvider
@@ -268,7 +270,8 @@ class ValidateAndConfirmPaymentActivitySpec extends BaseCheckoutActivitySpec {
268270
mockRequestService.translatePaymentTransaction(*_) >> new PaymentRequestDTO()
269271
OrderPaymentService mockOrderPaymentService = Mock()
270272
mockOrderPaymentService.createTransaction() >> new PaymentTransactionImpl()
271-
mockOrderPaymentService.save(_) >> {OrderPayment payment -> payment}
273+
mockOrderPaymentService.save(_ as OrderPayment) >> {OrderPayment payment -> payment}
274+
mockOrderPaymentService.save(_ as PaymentTransaction) >> {PaymentTransaction transaction -> transaction}
272275

273276
activity = new ValidateAndConfirmPaymentActivity().with {
274277
paymentConfigurationServiceProvider = mockProvider

0 commit comments

Comments
 (0)