public final class PaymentTransactionAddedMessage extends GenericMessageImpl<Payment>
AddTransaction
update action.
withCustomerAndFilledCart(client(), (customer, cart) -> { final MonetaryAmount totalAmount = cart.getTotalPrice(); final PaymentMethodInfo paymentMethodInfo = PaymentMethodInfoBuilder.of() .paymentInterface(randomKey()) .method("CREDIT_CARD") .build(); final TransactionDraft chargeTransaction = TransactionDraftBuilder .of(TransactionType.CHARGE, totalAmount, ZonedDateTime.now()) .build(); final PaymentDraftBuilder paymentDraftBuilder = PaymentDraftBuilder.of(totalAmount) .customer(customer) .paymentMethodInfo(paymentMethodInfo) .amountPaid(totalAmount) .transactions(Collections.singletonList(chargeTransaction)); final Payment payment = client().executeBlocking(PaymentCreateCommand.of(paymentDraftBuilder.build())); assertThat(payment.getCustomer()).isEqualTo(payment.getCustomer()); assertThat(payment.getPaymentMethodInfo()).isEqualTo(paymentMethodInfo); assertThat(payment.getAmountPlanned()).isEqualTo(totalAmount); final MonetaryAmount firstRefundAmount = EURO_10; final TransactionDraft firstRefundTransaction = TransactionDraftBuilder.of(TransactionType.REFUND, firstRefundAmount, ZonedDateTime.now()).build(); final Payment paymentWithFirstRefund = client().executeBlocking(PaymentUpdateCommand.of(payment, asList(SetAmountRefunded.of(firstRefundAmount), AddTransaction.of(firstRefundTransaction)))); assertThat(paymentWithFirstRefund.getTransactions()).hasSize(2); assertThat(paymentWithFirstRefund.getTransactions().get(0).getId()).isNotEmpty(); final Query<PaymentTransactionAddedMessage> messageQuery = MessageQuery.of().withPredicates(m -> m.resource().is(payment)) .forMessageType(PaymentTransactionAddedMessage.MESSAGE_HINT); assertEventually(() -> { final PagedQueryResult<PaymentTransactionAddedMessage> messageQueryResult = client().executeBlocking(messageQuery); assertThat(messageQueryResult.getTotal()).isGreaterThanOrEqualTo(1L); final PaymentTransactionAddedMessage paymentTransactionAddedMessage = messageQueryResult.head().get(); assertThat(paymentTransactionAddedMessage.getTransaction().getTimestamp()).isEqualTo(firstRefundTransaction.getTimestamp()); }); final MonetaryAmount secondRefundAmount = EURO_5; final TransactionDraft secondRefundTransaction = TransactionDraftBuilder.of(TransactionType.REFUND, secondRefundAmount, ZonedDateTime.now()).build(); final MonetaryAmount totalRefundAmount = secondRefundAmount.add(paymentWithFirstRefund.getAmountRefunded()); final Payment paymentWithSecondRefund = client().executeBlocking(PaymentUpdateCommand.of(paymentWithFirstRefund, asList(SetAmountRefunded.of(totalRefundAmount), AddTransaction.of(secondRefundTransaction)))); assertThat(paymentWithSecondRefund.getTransactions()).hasSize(3); assertThat(paymentWithSecondRefund.getAmountRefunded()).isEqualTo(totalRefundAmount); });
See the test code.
Payment
,
AddTransaction
Modifier and Type | Field and Description |
---|---|
static MessageDerivateHint<PaymentTransactionAddedMessage> |
MESSAGE_HINT |
static String |
MESSAGE_TYPE |
resource, resourceUserProvidedIdentifiers, resourceVersion, sequenceNumber, type
Modifier and Type | Method and Description |
---|---|
Transaction |
getTransaction() |
as, equals, getPayload, getResource, getResourceUserProvidedIdentifiers, getResourceVersion, getSequenceNumber, getType, hashCode, toReference
getCreatedAt, getId, getLastModifiedAt, getVersion
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
referenceOfId, referenceTypeId, typeReference
getCreatedAt, getId, getLastModifiedAt, getVersion
hasSameIdAs, toResourceIdentifier
public static final String MESSAGE_TYPE
public static final MessageDerivateHint<PaymentTransactionAddedMessage> MESSAGE_HINT
public Transaction getTransaction()