From 32ab178f3b3a3312e27db84d516d68bf4add5583 Mon Sep 17 00:00:00 2001 From: Brandon Wong Date: Mon, 29 Apr 2019 18:22:21 -0400 Subject: [PATCH] Add channel, app_id, and device_id to purchases --- pom.xml | 2 +- .../com/sailthru/client/params/Purchase.java | 48 ++++++++++++++++--- .../sailthru/client/params/PurchaseTest.java | 18 +++++++ 3 files changed, 61 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 614588e..211e6ca 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ com.sailthru.client sailthru-java-client - 1.6.0 + 1.7.0 jar sailthru-java-client diff --git a/src/main/com/sailthru/client/params/Purchase.java b/src/main/com/sailthru/client/params/Purchase.java index 5f8cda5..6327fc1 100644 --- a/src/main/com/sailthru/client/params/Purchase.java +++ b/src/main/com/sailthru/client/params/Purchase.java @@ -1,20 +1,19 @@ package com.sailthru.client.params; -import com.google.gson.reflect.TypeToken; import com.google.gson.annotations.SerializedName; +import com.google.gson.reflect.TypeToken; import com.sailthru.client.ApiAction; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.Date; -import java.util.Map; import java.util.List; +import java.util.Map; -/** - * - * @author Prajwal Tuladhar - */ public class Purchase extends AbstractApiParams implements ApiParams { + + public enum Channel {app, offline, online} + protected String email; protected List> items; protected Integer incomplete; @@ -40,6 +39,15 @@ public class Purchase extends AbstractApiParams implements ApiParams { @SerializedName("purchase_keys") protected Map purchaseKeys; + @SerializedName("channel") + protected Channel channel; + + @SerializedName("app_id") + protected String appId; + + @SerializedName("device_id") + protected String deviceId; + public Purchase setEmail(String email) { this.email = email; return this; @@ -118,8 +126,36 @@ public Purchase setPurchaseKeys(Map purchaseKeys) { return this; } + public Channel getChannel() { + return channel; + } + + public Purchase setChannel(Channel channel) { + this.channel = channel; + return this; + } + + public String getAppId() { + return appId; + } + + public Purchase setAppId(String appId) { + this.appId = appId; + return this; + } + + public String getDeviceId() { + return deviceId; + } + + public Purchase setDeviceId(String deviceId) { + this.deviceId = deviceId; + return this; + } + @Override public ApiAction getApiCall() { return ApiAction.purchase; } + } diff --git a/src/test/com/sailthru/client/params/PurchaseTest.java b/src/test/com/sailthru/client/params/PurchaseTest.java index 69930e0..bb2e9f3 100644 --- a/src/test/com/sailthru/client/params/PurchaseTest.java +++ b/src/test/com/sailthru/client/params/PurchaseTest.java @@ -154,4 +154,22 @@ public void testSendTemplate() { assertEquals(expected, result); } + public void testSetChannel() { + Purchase purchase = new Purchase(); + purchase.setChannel(Purchase.Channel.online); + String expected = "{\"channel\":\"online\"}"; + String result = gson.toJson(purchase); + assertEquals(expected, result); + } + + public void testSetChannelApp() { + Purchase purchase = new Purchase(); + purchase.setChannel(Purchase.Channel.app); + purchase.setAppId("applesfghidodkdjfhikodie"); + purchase.setDeviceId("deviceid"); + String expected = "{\"channel\":\"app\",\"app_id\":\"applesfghidodkdjfhikodie\",\"device_id\":\"deviceid\"}"; + String result = gson.toJson(purchase); + assertEquals(expected, result); + } + }