public final class SetAmountRefunded extends UpdateActionImpl<Payment>
See also PaymentUpdateCommand.
withPayment(client(), payment -> { final MonetaryAmount refundedAmount = payment.getAmountPlanned().divide(2); final Payment updatedPayment = client().executeBlocking(PaymentUpdateCommand.of(payment, SetAmountRefunded.of(refundedAmount))); assertThat(updatedPayment.getAmountRefunded()).isEqualTo(refundedAmount); return updatedPayment; });
See the test code.
Example with multiple refunds:
withPayment(client(), payBuilder -> payBuilder.amountPaid(payBuilder.getAmountPlanned()), payment -> { final MonetaryAmount totalAmount = payment.getAmountPlanned(); assertThat(payment.getAmountPaid()).as("amount paid").isEqualTo(totalAmount); final MonetaryAmount firstRefundedAmount = totalAmount.scaleByPowerOfTen(-1); final Payment firstRefundPayment = client().executeBlocking(PaymentUpdateCommand.of(payment, asList(SetAmountRefunded.of(firstRefundedAmount)))); assertThat(firstRefundPayment.getAmountRefunded()).as("first refunded").isEqualTo(firstRefundedAmount); final MonetaryAmount secondRefundedAmount = firstRefundedAmount.multiply(2); //important, because SetAmountRefunded sets the total value final MonetaryAmount totalRefundedAmount = firstRefundPayment.getAmountRefunded().add(secondRefundedAmount); final Payment secondRefundPayment = client().executeBlocking(PaymentUpdateCommand.of(firstRefundPayment, asList(SetAmountRefunded.of(totalRefundedAmount)))); assertThat(secondRefundPayment.getAmountRefunded()).as("total refunded").isEqualTo(totalRefundedAmount); return secondRefundPayment; });
See the test code.
Payment
Modifier and Type | Method and Description |
---|---|
javax.money.MonetaryAmount |
getAmount()
Deprecated.
|
static SetAmountRefunded |
of(javax.money.MonetaryAmount amount)
Deprecated.
|
getAction
public static SetAmountRefunded of(@Nullable javax.money.MonetaryAmount amount)
@Nullable public javax.money.MonetaryAmount getAmount()