use of com.google.api.services.actions_fulfillment.v2.model.StructuredResponse in project dialogflow-transactions-java by actions-on-google.
the class TransactionsApp method transactionDecisionComplete.
// Check result of asking to perform transaction / place order
@ForIntent("Transaction Decision Complete")
public ActionResponse transactionDecisionComplete(ActionRequest request) {
ResourceBundle rb = ResourceBundle.getBundle("resources", request.getLocale());
// Check transaction decision value
Argument transactionDecisionValue = request.getArgument("TRANSACTION_DECISION_VALUE");
Map<String, Object> extension = null;
if (transactionDecisionValue != null) {
extension = transactionDecisionValue.getExtension();
}
String transactionDecision = null;
if (extension != null) {
transactionDecision = (String) extension.get("transactionDecision");
}
ResponseBuilder responseBuilder = getResponseBuilder(request);
if ((transactionDecision != null && transactionDecision.equals("ORDER_ACCEPTED"))) {
OrderV3 order = ((OrderV3) extension.get("order"));
order.setLastUpdateTime(Instant.now().toString());
// Update order status
PurchaseOrderExtension purchaseOrderExtension = order.getPurchase();
purchaseOrderExtension.setStatus("CONFIRMED");
purchaseOrderExtension.setUserVisibleStatusLabel("Order confirmed");
order.setPurchase(purchaseOrderExtension);
// Order update
OrderUpdateV3 orderUpdate = new OrderUpdateV3().setType("SNAPSHOT").setReason("Reason string").setOrder(order);
Map<String, Object> conversationData = request.getConversationData();
String orderId = (String) conversationData.get("UNIQUE_ORDER_ID");
String response = MessageFormat.format(rb.getString("transaction_decision_result_success"), orderId);
responseBuilder.add(response).add(new StructuredResponse().setOrderUpdateV3(orderUpdate));
} else {
responseBuilder.add(rb.getString("transaction_failed"));
}
return responseBuilder.endConversation().build();
}
Aggregations