Skip to content

Commit 22f2a83

Browse files
Merge pull request #100 from alexanderjordanbaker/ResolveNullAppAccountTokenInConsumptionRequest
When appAccountToken is null in ConsumptionRequest
2 parents 2253964 + fae0716 commit 22f2a83

File tree

3 files changed

+67
-0
lines changed

3 files changed

+67
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package com.apple.itunes.storekit.model;
2+
3+
import com.fasterxml.jackson.core.JsonGenerator;
4+
import com.fasterxml.jackson.databind.JsonSerializer;
5+
import com.fasterxml.jackson.databind.SerializerProvider;
6+
7+
import java.io.IOException;
8+
import java.util.UUID;
9+
10+
public class AppAccountTokenNullSerializer extends JsonSerializer<UUID> {
11+
@Override
12+
public void serialize(UUID uuid, JsonGenerator jsonGenerator, SerializerProvider serializerProvider) throws IOException {
13+
jsonGenerator.writeString("");
14+
}
15+
}

src/main/java/com/apple/itunes/storekit/model/ConsumptionRequest.java

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
package com.apple.itunes.storekit.model;
44

55
import com.fasterxml.jackson.annotation.JsonProperty;
6+
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
67

78
import java.util.Objects;
89
import java.util.UUID;
@@ -36,6 +37,7 @@ public class ConsumptionRequest {
3637
@JsonProperty(SERIALIZED_NAME_DELIVERY_STATUS)
3738
private Integer deliveryStatus;
3839
@JsonProperty(SERIALIZED_NAME_APP_ACCOUNT_TOKEN)
40+
@JsonSerialize(nullsUsing = AppAccountTokenNullSerializer.class)
3941
private UUID appAccountToken;
4042
@JsonProperty(SERIALIZED_NAME_ACCOUNT_TENURE)
4143
private Integer accountTenure;

src/test/java/com/apple/itunes/storekit/client/AppStoreServerAPIClientTest.java

+50
Original file line numberDiff line numberDiff line change
@@ -450,6 +450,56 @@ public void testSendConsumptionData() throws APIException, IOException {
450450
client.sendConsumptionData("49571273", consumptionRequest);
451451
}
452452

453+
@Test
454+
public void testSendConsumptionDataWithNullAppAccountToken() throws APIException, IOException {
455+
AppStoreServerAPIClient client = getAppStoreServerAPIClient("", request -> {
456+
Assertions.assertEquals("PUT", request.method());
457+
Assertions.assertEquals("/inApps/v1/transactions/consumption/49571273", request.url().encodedPath());
458+
RequestBody body = request.body();
459+
Assertions.assertNotNull(body);
460+
Assertions.assertEquals(expectedMediaType, body.contentType());
461+
Buffer buffer = new Buffer();
462+
try {
463+
body.writeTo(buffer);
464+
} catch (IOException e) {
465+
throw new RuntimeException(e);
466+
}
467+
Map<String, Object> root;
468+
try {
469+
root = new ObjectMapper().readValue(buffer.readUtf8(), Map.class);
470+
} catch (JsonProcessingException e) {
471+
throw new RuntimeException(e);
472+
}
473+
Assertions.assertTrue((Boolean) root.get("customerConsented"));
474+
Assertions.assertEquals(1, ((Number) root.get("consumptionStatus")).intValue());
475+
Assertions.assertEquals(2, ((Number) root.get("platform")).intValue());
476+
Assertions.assertFalse((Boolean) root.get("sampleContentProvided"));
477+
Assertions.assertEquals(3, ((Number) root.get("deliveryStatus")).intValue());
478+
Assertions.assertEquals("", root.get("appAccountToken"));
479+
Assertions.assertEquals(4, ((Number) root.get("accountTenure")).intValue());
480+
Assertions.assertEquals(5, ((Number) root.get("playTime")).intValue());
481+
Assertions.assertEquals(6, ((Number) root.get("lifetimeDollarsRefunded")).intValue());
482+
Assertions.assertEquals(7, ((Number) root.get("lifetimeDollarsPurchased")).intValue());
483+
Assertions.assertEquals(4, ((Number) root.get("userStatus")).intValue());
484+
Assertions.assertEquals(3, ((Number) root.get("refundPreference")).intValue());
485+
});
486+
487+
ConsumptionRequest consumptionRequest = new ConsumptionRequest()
488+
.customerConsented(true)
489+
.consumptionStatus(ConsumptionStatus.NOT_CONSUMED)
490+
.platform(Platform.NON_APPLE)
491+
.sampleContentProvided(false)
492+
.deliveryStatus(DeliveryStatus.DID_NOT_DELIVER_DUE_TO_SERVER_OUTAGE)
493+
.accountTenure(AccountTenure.THIRTY_DAYS_TO_NINETY_DAYS)
494+
.playTime(PlayTime.ONE_DAY_TO_FOUR_DAYS)
495+
.lifetimeDollarsRefunded(LifetimeDollarsRefunded.ONE_THOUSAND_DOLLARS_TO_ONE_THOUSAND_NINE_HUNDRED_NINETY_NINE_DOLLARS_AND_NINETY_NINE_CENTS)
496+
.lifetimeDollarsPurchased(LifetimeDollarsPurchased.TWO_THOUSAND_DOLLARS_OR_GREATER)
497+
.userStatus(UserStatus.LIMITED_ACCESS)
498+
.refundPreference(RefundPreference.NO_PREFERENCE);
499+
500+
client.sendConsumptionData("49571273", consumptionRequest);
501+
}
502+
453503
@Test
454504
public void testHeaders() throws APIException, IOException {
455505
AppStoreServerAPIClient client = getClientWithBody("models/transactionInfoResponse.json", request -> {

0 commit comments

Comments
 (0)