-
Notifications
You must be signed in to change notification settings - Fork 135
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
[Woo POS][Cash & Receipts] Update customer with email and use action to send it #13034
Open
kidinov
wants to merge
10
commits into
trunk
Choose a base branch
from
13031-woo-poscash-receipts-update-customer-with-email-and-use-action-to-send-it
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
479f86e
Fluxc with the action to send an email
kidinov 421f9ee
Renamed availability checker to follow the convention
kidinov d471c83
Call repository when a button clicked
kidinov 62e345e
Fixed naming
kidinov 06789da
Update email state
kidinov 275f1c7
Code that updates email and sends order details there
kidinov 5eff1cc
Simplified the code
kidinov 2435dde
Update billing address
kidinov 18a93ac
WooPosTotalsPaymentReceiptRepositoryTest
kidinov 2f67f6f
Fixed formatting
kidinov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...rce/android/ui/woopos/home/totals/payment/receipt/WooPosTotalsPaymentReceiptRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package com.woocommerce.android.ui.woopos.home.totals.payment.receipt | ||
|
||
import com.woocommerce.android.model.Order | ||
import com.woocommerce.android.model.OrderMapper | ||
import com.woocommerce.android.tools.SelectedSite | ||
import com.woocommerce.android.ui.orders.creation.OrderCreateEditRepository | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.withContext | ||
import org.wordpress.android.fluxc.store.WCOrderStore | ||
import javax.inject.Inject | ||
|
||
class WooPosTotalsPaymentReceiptRepository @Inject constructor( | ||
private val selectedSite: SelectedSite, | ||
private val orderStore: WCOrderStore, | ||
private val orderCreateEditRepository: OrderCreateEditRepository, | ||
private val orderMapper: OrderMapper, | ||
) { | ||
suspend fun sendReceiptByEmail(orderId: Long, email: String): Result<Unit> = withContext(Dispatchers.IO) { | ||
val order = getOrderById(orderId) | ||
if (order == null) { | ||
return@withContext Result.failure(Exception("Failed to get order")) | ||
} | ||
|
||
if (updateOrderWithEmail(order, email).isFailure) { | ||
return@withContext Result.failure(Exception("Failed to update order with email")) | ||
} | ||
|
||
return@withContext triggerOrderReceiptSending(orderId) | ||
} | ||
|
||
private suspend fun triggerOrderReceiptSending(orderId: Long): Result<Unit> { | ||
val sendOrderResult = orderStore.sendOrderReceipt(selectedSite.get(), orderId) | ||
return if (sendOrderResult.isError) { | ||
Result.failure(Exception("Failed to send order receipt")) | ||
} else { | ||
Result.success(Unit) | ||
} | ||
} | ||
|
||
private suspend fun updateOrderWithEmail(order: Order, email: String): Result<Order> { | ||
val updatedBillingAddress = order.billingAddress.copy(email = email) | ||
val updatedCustomer = order.customer?.copy(billingAddress = updatedBillingAddress) | ||
return orderCreateEditRepository.createOrUpdateOrder( | ||
order = order.copy(customer = updatedCustomer) | ||
) | ||
} | ||
|
||
private suspend fun getOrderById(orderId: Long) = | ||
orderStore.getOrderByIdAndSite(orderId, selectedSite.get())?.let { | ||
orderMapper.toAppModel(it) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have no designs, so no handling of the error or success in this PR