Skip to content
This repository has been archived by the owner on Jan 18, 2025. It is now read-only.

Commit

Permalink
Add support for DigitalPurchaseCheck
Browse files Browse the repository at this point in the history
Bug: 129364223
Change-Id: Ieee5d60e3bbfd2aa20099b8eaf3a4298397c7365
  • Loading branch information
taycaldwell committed Jul 15, 2019
1 parent 8bbeb5b commit 5e2c7c9
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 13 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ repositories {
}
dependencies {
compile group: 'com.google.actions', name: 'actions-on-google', version: '1.2.0'
compile group: 'com.google.actions', name: 'actions-on-google', version: '1.3.0'
}
```

Expand All @@ -40,7 +40,7 @@ If using maven, add the following to your pom.xml file.
<dependency>
<groupId>com.google.actions</groupId>
<artifactId>actions-on-google</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
</dependency>
```

Expand Down
3 changes: 2 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ dokka {
outputDirectory = "$buildDir/javadoc"
}

version = '1.0.0'
version = '1.0.2'

dependencies {
// Actions on Google JSON bindings
Expand Down Expand Up @@ -73,6 +73,7 @@ dependencies {
testCompile group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: '5.2.0'

compileClasspath group: "com.github.rholder", name: "gradle-one-jar", version: "1.0.4"

compile group: "org.jetbrains.kotlin", name: "kotlin-stdlib-jdk8", version: "$kotlin_version"
}

Expand Down
Binary file modified lib/libactions_java_lib.jar
Binary file not shown.
Binary file modified lib/libdialogflow_java_lib.jar
Binary file not shown.
28 changes: 19 additions & 9 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.actions</groupId>
<artifactId>actions-on-google</artifactId>
<version>1.2.0</version>
<version>1.3.0</version>
<packaging>jar</packaging>
<name>actions-on-google-java</name>
<url>http://actions.google.com</url>
Expand Down Expand Up @@ -60,7 +60,7 @@
<repositories>
<repository>
<id>local-repo</id>
<url>file://${project.basedir}/local-repo</url>
<url>file://${basedir}/local-repo</url>
</repository>
</repositories>

Expand Down Expand Up @@ -198,15 +198,13 @@
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
<testSourceDirectory>${project.basedir}/src/test/kotlin
</testSourceDirectory>

<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.4.1.Final</version>
</extension>
</extensions>

<plugins>
<plugin>
<artifactId>maven-install-plugin</artifactId>
Expand Down Expand Up @@ -237,15 +235,14 @@
<configuration>
<file>${basedir}/lib/libdialogflow_java_lib.jar</file>
<groupId>com.google.actions</groupId>
<packaging>jar</packaging>
<artifactId>dialogflow-bindings</artifactId>
<packaging>jar</packaging>
<version>2.0.0</version>
<localRepositoryPath>${basedir}/local-repo</localRepositoryPath>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
Expand Down Expand Up @@ -313,7 +310,6 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.jetbrains.dokka</groupId>
<artifactId>dokka-maven-plugin</artifactId>
Expand Down Expand Up @@ -341,7 +337,6 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
Expand All @@ -360,7 +355,22 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${project.build.finalName}-shade</finalName>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
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)
}
}
2 changes: 1 addition & 1 deletion src/main/resources/metadata.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=v1.2.0
version=v1.3.0
23 changes: 23 additions & 0 deletions src/test/kotlin/com/google/actions/api/AogResponseTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,29 @@ class AogResponseTest {
inputValueData.get("developerPayload").asString)
}

@Test
fun testDigitalPurchaseCheck() {
println("testDigitalPurchaseCheck")
val responseBuilder = ResponseBuilder(usesDialogflow = false)

responseBuilder.add(DigitalPurchaseCheck())

val response = responseBuilder.build()
val jsonOutput = response.toJson()
val intent = response.appResponse
?.expectedInputs?.get(0)
?.possibleIntents?.get(0) as ExpectedIntent
assertEquals("actions.intent.DIGITAL_PURCHASE_CHECK", intent.intent)
val gson = Gson()
val jsonObject = gson.fromJson(jsonOutput, JsonObject::class.java)
val inputValueData = jsonObject
.get("expectedInputs").asJsonArray.get(0).asJsonObject
.get("possibleIntents").asJsonArray.get(0).asJsonObject
.get("inputValueData").asJsonObject
assertEquals("type.googleapis.com/google.actions.transactions.v3.DigitalPurchaseCheckSpec",
inputValueData.get("@type").asString)
}

@Test
fun testTransactionRequirementsCheck() {
val orderOptions = OrderOptions().setRequestDeliveryAddress(false)
Expand Down

0 comments on commit 5e2c7c9

Please sign in to comment.