Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Endpoint: Action send order details #3115

Merged
merged 3 commits into from
Dec 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,15 @@ class MockedStack_WCOrdersTest : MockedStack_Base() {
)
}

@Test
fun testSendOrderReceipt() = runBlocking {
interceptor.respondWith("wc-order-action-send-order-details-success.json")

val result = orderRestClient.sendOrderReceipt(siteModel, 0)

assertFalse(result.isError)
}

@Suppress("unused")
@Subscribe
fun onAction(action: Action<*>) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"data": {
"message": "Order details email sent to customer."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,19 @@ class WCOrderStoreTest {
}
}

@Test
fun testSendOrderReceipt() {
runBlocking {
val orderModel = OrderTestUtils.generateSampleOrder(42)
val site = SiteModel().apply { id = orderModel.localSiteId.value }
val orderId = 42L

orderStore.sendOrderReceipt(site, orderId)

verify(orderRestClient).sendOrderReceipt(site, orderId)
}
}

private fun setupMissingOrders(): MutableMap<WCOrderSummaryModel, OrderEntity?> {
return mutableMapOf<WCOrderSummaryModel, OrderEntity?>().apply {
(21L..30L).forEach { index ->
Expand Down
1 change: 1 addition & 0 deletions fluxc-processor/src/main/resources/wc-wp-api-endpoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
/orders/<id>/shipment-trackings/<tracking>#String/
/orders/<id>/shipment-trackings/providers/
/orders/<id>/receipt/
/orders/<id>/actions/send_order_details

/products/<id>/
/products/<id>/variations/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,6 +1023,19 @@ class OrderRestClient @Inject constructor(
return response.toWooPayload { it }
}

suspend fun sendOrderReceipt(
site: SiteModel,
orderId: Long,
): WooPayload<Unit> {
val response = wooNetwork.executePostGsonRequest(
site = site,
path = WOOCOMMERCE.orders.id(orderId).actions.send_order_details.pathV3,
clazz = Unit::class.java,
)

return response.toWooPayload { it }
}

private suspend fun doFetchOrderCount(site: SiteModel, filterByStatus: String?): FetchOrdersCountResponsePayload {
val url = WOOCOMMERCE.reports.orders.totals.pathV3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -728,6 +728,14 @@ class WCOrderStore @Inject constructor(
forceNew
)

suspend fun sendOrderReceipt(
site: SiteModel,
orderId: Long,
) = wcOrderRestClient.sendOrderReceipt(
site,
orderId
)

private suspend fun optimisticallyUpdateOrder(
orderId: Long,
localSiteId: LocalId,
Expand Down