public static AddPayment of(final Referenceable<Payment> payment) { return new AddPayment(Optional.ofNullable(payment).map(Referenceable::toReference).orElse(null)); }
/** * Method to remove all payments from the cart and then attaching a new created one. * @param cpd contains the data for the new payment * @return the newly created Payment object */ protected CompletionStage<Payment> removePaymentsAndCreateNew(final CreatePaymentData cpd) { final Cart cart = cpd.getCart(); final List<UpdateAction<Cart>> changeCartPaymentInfo = new ArrayList<>(); if (cart.getPaymentInfo() != null) { changeCartPaymentInfo.addAll(cart.getPaymentInfo().getPayments().stream() .map(RemovePayment::of) .collect(Collectors.toList())); } final Command<Payment> createPaymentCommand = PaymentCreateCommand.of(createPaymentDraft(cpd).build()); return cpd.getSphereClient().execute(createPaymentCommand) .thenCompose(p -> { changeCartPaymentInfo.add(AddPayment.of(p)); return cpd.getSphereClient().execute(CartUpdateCommand.of(cpd.getCart(), changeCartPaymentInfo)) .thenApplyAsync(c -> p); }); }
/** * Method to To add a new payment to the Cart * * @param cpd contains the data for the new payment * @return the newly created Payment object */ protected CompletionStage<Payment> addNewPayment(final CreatePaymentData cpd) { final Command<Payment> createPaymentCommand = PaymentCreateCommand.of(createPaymentDraft(cpd).build()); return cpd.getSphereClient().execute(createPaymentCommand) .thenCompose(p -> cpd.getSphereClient().execute(CartUpdateCommand.of(cpd.getCart(), AddPayment.of(p))) .thenApplyAsync(c -> p)); }
@Test public void addPayment() { withPayment(client(), payment -> { withCart(client(), cart -> { //add payment final CartUpdateCommand command = CartUpdateCommand.of(cart, AddPayment.of(payment)) .withExpansionPaths(m -> m.paymentInfo().payments()); final Cart cartWithPayment = client().executeBlocking(command); final Reference<Payment> paymentReference = cartWithPayment.getPaymentInfo().getPayments().get(0); assertThat(paymentReference).isEqualTo(payment.toReference()); assertThat(paymentReference).is(expanded(payment)); //query cart by payment final CartQuery cartQuery = CartQuery.of() .withPredicates(m -> m.paymentInfo().payments().isIn(singletonList(payment))); assertThat(client().executeBlocking(cartQuery).head()).contains(cartWithPayment); //remove payment final Cart cartWithoutPayment = client().executeBlocking(CartUpdateCommand.of(cartWithPayment, RemovePayment.of(payment))); assertThat(cartWithoutPayment.getPaymentInfo()).isNull(); return cartWithoutPayment; }); return payment; }); }
public static AddPayment of(final Referenceable<Payment> payment) { return new AddPayment(Optional.ofNullable(payment).map(Referenceable::toReference).orElse(null)); }
public static AddPayment of(final Referenceable<Payment> payment) { return new AddPayment(Optional.ofNullable(payment).map(Referenceable::toReference).orElse(null)); }