|
| 1 | +package com.checkout.inventory; |
| 2 | + |
| 3 | +import com.checkout.EmptyResponse; |
| 4 | +import com.checkout.inventory.request.InventoryAdjustmentRequest; |
| 5 | +import com.checkout.inventory.request.InventoryLevelsQueryFilter; |
| 6 | +import com.checkout.inventory.request.InventoryReservationRequest; |
| 7 | +import com.checkout.inventory.request.InventorySetLevelsRequest; |
| 8 | +import com.checkout.inventory.request.InventorySetProductRequest; |
| 9 | +import com.checkout.inventory.response.InventoryLevels; |
| 10 | +import com.checkout.inventory.response.InventoryProductKnowledge; |
| 11 | +import com.checkout.inventory.response.InventoryReservation; |
| 12 | + |
| 13 | +import java.util.concurrent.CompletableFuture; |
| 14 | + |
| 15 | +/** |
| 16 | + * The Inventory client: stock levels, atomic multi-variant reservations, stock adjustments, and |
| 17 | + * per-variant product knowledge for AI agents. Every operation on this client requires the |
| 18 | + * {@code agentic:inventory} OAuth scope; it does not accept a secret or public API key. |
| 19 | + * |
| 20 | + * <p>Error responses ({@code 404}, {@code 409}, {@code 422}) are surfaced the same way as every |
| 21 | + * other domain in this SDK: as a {@link com.checkout.CheckoutApiException} carrying the raw |
| 22 | + * {@code Map<String, Object>} error body, not a typed class (this SDK has no domain that |
| 23 | + * deserializes error bodies into a dedicated type). For the inventory endpoints, that map |
| 24 | + * contains: {@code request_id} (String, for support and correlation), {@code error_type} |
| 25 | + * (String, a high-level classification), {@code error_codes} (array of String, in |
| 26 | + * {@code [subject]_[error]} form), and, present only on an {@code insufficient_stock} conflict, |
| 27 | + * {@code variant_id} (String, the first failing variant) and {@code available} (Integer, its |
| 28 | + * current sellable availability).</p> |
| 29 | + */ |
| 30 | +public interface InventoryClient { |
| 31 | + |
| 32 | + /** |
| 33 | + * Applies a relative adjustment to a variant's on-hand stock. |
| 34 | + * |
| 35 | + * @param request the adjustment to apply |
| 36 | + * @return the variant's resulting stock levels |
| 37 | + */ |
| 38 | + CompletableFuture<InventoryLevels> adjustInventory(InventoryAdjustmentRequest request); |
| 39 | + |
| 40 | + /** |
| 41 | + * Applies a relative adjustment to a variant's on-hand stock. |
| 42 | + * |
| 43 | + * @param request the adjustment to apply |
| 44 | + * @param idempotencyKey an optional idempotency key sent as {@code Cko-Idempotency-Key} |
| 45 | + * @return the variant's resulting stock levels |
| 46 | + */ |
| 47 | + CompletableFuture<InventoryLevels> adjustInventory(InventoryAdjustmentRequest request, String idempotencyKey); |
| 48 | + |
| 49 | + /** |
| 50 | + * Retrieves the current stock levels for a variant. |
| 51 | + * |
| 52 | + * @param variantId the identifier of the variant |
| 53 | + * @return the variant's current stock levels |
| 54 | + */ |
| 55 | + CompletableFuture<InventoryLevels> getInventoryLevels(String variantId); |
| 56 | + |
| 57 | + /** |
| 58 | + * Retrieves the current stock levels for a variant. |
| 59 | + * |
| 60 | + * @param variantId the identifier of the variant |
| 61 | + * @param filter optional query parameters, for example {@code expand=product} |
| 62 | + * @return the variant's current stock levels |
| 63 | + */ |
| 64 | + CompletableFuture<InventoryLevels> getInventoryLevels(String variantId, InventoryLevelsQueryFilter filter); |
| 65 | + |
| 66 | + /** |
| 67 | + * Sets absolute stock levels for a variant. Creates the inventory item if it does not exist. |
| 68 | + * |
| 69 | + * @param variantId the identifier of the variant |
| 70 | + * @param request the absolute stock levels to set |
| 71 | + * @return the variant's resulting stock levels |
| 72 | + */ |
| 73 | + CompletableFuture<InventoryLevels> setInventoryLevels(String variantId, InventorySetLevelsRequest request); |
| 74 | + |
| 75 | + /** |
| 76 | + * Creates an atomic multi-variant stock hold. |
| 77 | + * |
| 78 | + * @param request the reservation to create |
| 79 | + * @return the created reservation |
| 80 | + */ |
| 81 | + CompletableFuture<InventoryReservation> createInventoryReservation(InventoryReservationRequest request); |
| 82 | + |
| 83 | + /** |
| 84 | + * Creates an atomic multi-variant stock hold. |
| 85 | + * |
| 86 | + * @param request the reservation to create |
| 87 | + * @param idempotencyKey an optional idempotency key sent as {@code Cko-Idempotency-Key} |
| 88 | + * @return the created reservation |
| 89 | + */ |
| 90 | + CompletableFuture<InventoryReservation> createInventoryReservation(InventoryReservationRequest request, String idempotencyKey); |
| 91 | + |
| 92 | + /** |
| 93 | + * Retrieves a reservation. |
| 94 | + * |
| 95 | + * @param reservationId the identifier of the reservation |
| 96 | + * @return the reservation |
| 97 | + */ |
| 98 | + CompletableFuture<InventoryReservation> getInventoryReservation(String reservationId); |
| 99 | + |
| 100 | + /** |
| 101 | + * Commits a held reservation, converting the hold into a permanent stock deduction. |
| 102 | + * |
| 103 | + * @param reservationId the identifier of the reservation |
| 104 | + * @return the committed reservation |
| 105 | + */ |
| 106 | + CompletableFuture<InventoryReservation> commitInventoryReservation(String reservationId); |
| 107 | + |
| 108 | + /** |
| 109 | + * Releases a held reservation, returning the held quantities to available stock. |
| 110 | + * |
| 111 | + * @param reservationId the identifier of the reservation |
| 112 | + * @return the released reservation |
| 113 | + */ |
| 114 | + CompletableFuture<InventoryReservation> releaseInventoryReservation(String reservationId); |
| 115 | + |
| 116 | + /** |
| 117 | + * Beta. Retrieves the product knowledge for a variant. |
| 118 | + * |
| 119 | + * @param variantId the identifier of the variant |
| 120 | + * @return the variant's product knowledge |
| 121 | + */ |
| 122 | + CompletableFuture<InventoryProductKnowledge> getInventoryProduct(String variantId); |
| 123 | + |
| 124 | + /** |
| 125 | + * Beta. Sets (upserts) the product knowledge for a variant. |
| 126 | + * |
| 127 | + * @param variantId the identifier of the variant |
| 128 | + * @param request the product knowledge to set |
| 129 | + * @return the resulting product knowledge |
| 130 | + */ |
| 131 | + CompletableFuture<InventoryProductKnowledge> setInventoryProduct(String variantId, InventorySetProductRequest request); |
| 132 | + |
| 133 | + /** |
| 134 | + * Beta. Deletes the product knowledge for a variant. |
| 135 | + * |
| 136 | + * @param variantId the identifier of the variant |
| 137 | + * @return an empty response |
| 138 | + */ |
| 139 | + CompletableFuture<EmptyResponse> deleteInventoryProduct(String variantId); |
| 140 | + |
| 141 | + // Synchronous methods |
| 142 | + |
| 143 | + InventoryLevels adjustInventorySync(InventoryAdjustmentRequest request); |
| 144 | + |
| 145 | + InventoryLevels adjustInventorySync(InventoryAdjustmentRequest request, String idempotencyKey); |
| 146 | + |
| 147 | + InventoryLevels getInventoryLevelsSync(String variantId); |
| 148 | + |
| 149 | + InventoryLevels getInventoryLevelsSync(String variantId, InventoryLevelsQueryFilter filter); |
| 150 | + |
| 151 | + InventoryLevels setInventoryLevelsSync(String variantId, InventorySetLevelsRequest request); |
| 152 | + |
| 153 | + InventoryReservation createInventoryReservationSync(InventoryReservationRequest request); |
| 154 | + |
| 155 | + InventoryReservation createInventoryReservationSync(InventoryReservationRequest request, String idempotencyKey); |
| 156 | + |
| 157 | + InventoryReservation getInventoryReservationSync(String reservationId); |
| 158 | + |
| 159 | + InventoryReservation commitInventoryReservationSync(String reservationId); |
| 160 | + |
| 161 | + InventoryReservation releaseInventoryReservationSync(String reservationId); |
| 162 | + |
| 163 | + InventoryProductKnowledge getInventoryProductSync(String variantId); |
| 164 | + |
| 165 | + InventoryProductKnowledge setInventoryProductSync(String variantId, InventorySetProductRequest request); |
| 166 | + |
| 167 | + EmptyResponse deleteInventoryProductSync(String variantId); |
| 168 | + |
| 169 | +} |
0 commit comments