This repository has been archived by the owner on Jan 18, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for DigitalPurchaseCheck
Bug: 129364223 Change-Id: Ieee5d60e3bbfd2aa20099b8eaf3a4298397c7365
- Loading branch information
1 parent
8bbeb5b
commit 5e2c7c9
Showing
8 changed files
with
110 additions
and
13 deletions.
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
Binary file not shown.
Binary file not shown.
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
63 changes: 63 additions & 0 deletions
63
src/main/kotlin/com/google/actions/api/response/helperintent/DigitalPurchaseCheck.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,63 @@ | ||
package com.google.actions.api.response.helperintent | ||
|
||
import com.google.api.services.actions_fulfillment.v2.model.DigitalPurchaseCheckSpec | ||
|
||
/** | ||
* Helper intent to verify a user meets the necessary conditions for completing | ||
* a digital purchase. | ||
* | ||
* ``` Java | ||
* @ForIntent("digitalPurchaseCheck") | ||
* public ActionResponse digitalPurchaseCheck(ActionRequest request) { | ||
* ResponseBuilder responseBuilder = getResponseBuilder(); | ||
* responseBuilder | ||
* .add(new DigitalPurchaseCheck()); | ||
* return responseBuilder.build(); | ||
* } | ||
* ``` | ||
* | ||
* The following code demonstrates how to handle a digital purchase check result. | ||
* | ||
* ``` Java | ||
* @ForIntent("actions_intent_DIGITAL_PURCHASE_CHECK") | ||
* public ActionResponse handlePurchaseResponse(ActionRequest request) { | ||
* ResponseBuilder responseBuilder = getResponseBuilder(); | ||
* String checkResult = request.getArgument("DIGITAL_PURCHASE_CHECK_RESULT").getTextValue(); | ||
* if (checkResult.equalsIgnoreCase("CAN_PURCHASE")) { | ||
* // User is eligible to perform digital purchases. | ||
* responseBuilder | ||
* .add(new CompletePurchase() | ||
* .setSkuId(skuId) | ||
* .setDeveloperPayload("Optional developer payload string)); | ||
* } else if (checkResult.equalsIgnoreCase("CANNOT_PURCHASE")) { | ||
* // User does not meet necessary conditions for completing a digital | ||
* // purchase. This may be due to location, device or other factors. | ||
* responseBuilder.add("You are not eligible to perform this digital purchase.").endConversation(); | ||
* } else if (purchaseResult.equalsIgnoreCase("RESULT_TYPE_UNSPECIFIED")) { | ||
* responseBuilder.add("Digital purchase check failed. Do you want to try again?").endConversation(); | ||
* } else { | ||
* responseBuilder.add("There was an internal error. Please try again later").endConversation(); | ||
* } | ||
* return responseBuilder.build(); | ||
* } | ||
* ``` | ||
*/ | ||
class DigitalPurchaseCheck : HelperIntent { | ||
private val map: HashMap<String, Any> = HashMap<String, Any>() | ||
|
||
override val name: String | ||
get() = "actions.intent.DIGITAL_PURCHASE_CHECK" | ||
|
||
override val parameters: Map<String, Any> | ||
get() { | ||
prepareMap() | ||
map.put("@type", | ||
"type.googleapis.com/google.actions.transactions.v3.DigitalPurchaseCheckSpec") | ||
return map | ||
} | ||
|
||
private fun prepareMap() { | ||
val spec = DigitalPurchaseCheckSpec() | ||
spec.toMap(map) | ||
} | ||
} |
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 |
---|---|---|
@@ -1 +1 @@ | ||
version=v1.2.0 | ||
version=v1.3.0 |
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