Skip to content

Commit

Permalink
Merge pull request #56 from sailthru/purchase_channel
Browse files Browse the repository at this point in the history
Add channel, app_id, and device_id to purchases
  • Loading branch information
Brandon Wong authored Apr 30, 2019
2 parents c4f6e79 + 32ab178 commit 62b491f
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<groupId>com.sailthru.client</groupId>
<artifactId>sailthru-java-client</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
<packaging>jar</packaging>

<name>sailthru-java-client</name>
Expand Down
48 changes: 42 additions & 6 deletions src/main/com/sailthru/client/params/Purchase.java
Original file line number Diff line number Diff line change
@@ -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 <[email protected]>
*/
public class Purchase extends AbstractApiParams implements ApiParams {

public enum Channel {app, offline, online}

protected String email;
protected List<Map<String, Object>> items;
protected Integer incomplete;
Expand All @@ -40,6 +39,15 @@ public class Purchase extends AbstractApiParams implements ApiParams {
@SerializedName("purchase_keys")
protected Map<String, String> 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;
Expand Down Expand Up @@ -118,8 +126,36 @@ public Purchase setPurchaseKeys(Map<String, String> 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;
}

}
18 changes: 18 additions & 0 deletions src/test/com/sailthru/client/params/PurchaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 62b491f

Please sign in to comment.