Skip to content

Commit a9d3725

Browse files
committed
feat: Add 'categories' field to item in checkout request
1 parent 7ad184c commit a9d3725

File tree

6 files changed

+26
-4
lines changed

6 files changed

+26
-4
lines changed

affirm/src/main/java/com/affirm/android/model/Item.java

+11
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@
99
import com.google.gson.annotations.SerializedName;
1010

1111
import androidx.annotation.NonNull;
12+
import androidx.annotation.Nullable;
1213

1314
import java.math.BigDecimal;
15+
import java.util.List;
1416

1517
@AutoValue
1618
public abstract class Item implements Parcelable {
@@ -44,6 +46,13 @@ public static TypeAdapter<Item> typeAdapter(Gson gson) {
4446
@SerializedName("item_image_url")
4547
public abstract String imageUrl();
4648

49+
// An array of lists that indicate the various categories that apply to this product, and
50+
// the hierarchy of those category definitions. Each list in the array contains one or more
51+
// comma-separated strings, with the first string being the highest-level (widest) category.
52+
@Nullable
53+
@SerializedName("categories")
54+
public abstract List<List<String>> categories();
55+
4756
@AutoValue.Builder
4857
public abstract static class Builder {
4958
private BigDecimal mUnitPrice;
@@ -60,6 +69,8 @@ public abstract static class Builder {
6069

6170
public abstract Builder setImageUrl(String value);
6271

72+
public abstract Builder setCategories(@Nullable List<List<String>> categories);
73+
6374
abstract Item autoBuild();
6475

6576
public Builder setUnitPrice(@NonNull BigDecimal value) {

affirm/src/test/java/com/affirm/android/CheckoutFactory.java

+5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import com.affirm.android.model.Shipping;
1010

1111
import java.math.BigDecimal;
12+
import java.util.Arrays;
1213
import java.util.HashMap;
1314
import java.util.Map;
1415

@@ -22,6 +23,10 @@ public static Checkout create() {
2223
.setSku("wheel")
2324
.setUnitPrice(BigDecimal.valueOf(1000.0))
2425
.setUrl("http://merchant.com/great_deal_wheel")
26+
.setCategories(Arrays.asList(
27+
Arrays.asList("Apparel", "Pants"),
28+
Arrays.asList("Mens", "Apparel", "Pants")
29+
))
2530
.build();
2631

2732
final Map<String, Item> items = new HashMap<>();

affirm/src/test/java/com/affirm/android/CheckoutRequestTest.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
public class CheckoutRequestTest {
2222

2323
private static final String expectedCheckoutBody =
24-
"{\"checkout\":{\"items\":{\"wheel\":{\"display_name\":\"Great Deal Wheel\",\"sku\":\"wheel\",\"unit_price\":100000,\"qty\":1,\"item_url\":\"http://merchant.com/great_deal_wheel\",\"item_image_url\":\"http://www.image.com/111\"}},\"currency\":\"USD\",\"shipping\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"billing\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"shipping_amount\":100000,\"tax_amount\":10000,\"total\":110000,\"metadata\":{\"entity_name\":\"internal-sub_brand-name\",\"shipping_type\":\"UPS Ground\",\"webhook_session_id\":\"ABC123\",\"platform_type\":\"Affirm Android SDK\",\"platform_affirm\":\"\"},\"merchant\":{\"public_api_key\":\"Y8CQXFF044903JC0\",\"user_confirmation_url\":\"affirm://checkout/confirmed\",\"user_cancel_url\":\"affirm://checkout/cancelled\",\"user_confirmation_url_action\":\"GET\"},\"api_version\":\"v2\",\"meta\":{\"locale\":\"en_US\"}}}";
24+
"{\"checkout\":{\"items\":{\"wheel\":{\"display_name\":\"Great Deal Wheel\",\"sku\":\"wheel\",\"unit_price\":100000,\"qty\":1,\"item_url\":\"http://merchant.com/great_deal_wheel\",\"item_image_url\":\"http://www.image.com/111\",\"categories\":[[\"Apparel\",\"Pants\"],[\"Mens\",\"Apparel\",\"Pants\"]]}},\"currency\":\"USD\",\"shipping\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"billing\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"shipping_amount\":100000,\"tax_amount\":10000,\"total\":110000,\"metadata\":{\"entity_name\":\"internal-sub_brand-name\",\"shipping_type\":\"UPS Ground\",\"webhook_session_id\":\"ABC123\",\"platform_type\":\"Affirm Android SDK\",\"platform_affirm\":\"\"},\"merchant\":{\"public_api_key\":\"Y8CQXFF044903JC0\",\"user_confirmation_url\":\"affirm://checkout/confirmed\",\"user_cancel_url\":\"affirm://checkout/cancelled\",\"user_confirmation_url_action\":\"GET\"},\"api_version\":\"v2\",\"meta\":{\"locale\":\"en_US\"}}}";
2525

2626
private static final String expectedCheckoutWithCaasBody =
27-
"{\"checkout\":{\"items\":{\"wheel\":{\"display_name\":\"Great Deal Wheel\",\"sku\":\"wheel\",\"unit_price\":100000,\"qty\":1,\"item_url\":\"http://merchant.com/great_deal_wheel\",\"item_image_url\":\"http://www.image.com/111\"}},\"currency\":\"USD\",\"shipping\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"billing\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"shipping_amount\":100000,\"tax_amount\":10000,\"total\":110000,\"metadata\":{\"entity_name\":\"internal-sub_brand-name\",\"shipping_type\":\"UPS Ground\",\"webhook_session_id\":\"ABC123\",\"platform_type\":\"Affirm Android SDK\",\"platform_affirm\":\"\"},\"merchant\":{\"public_api_key\":\"Y8CQXFF044903JC0\",\"user_confirmation_url\":\"affirm://checkout/confirmed\",\"user_cancel_url\":\"affirm://checkout/cancelled\",\"caas\":\"4626b631-c5bc-4c4e-800b-dd5fa27ef8b8\",\"user_confirmation_url_action\":\"GET\"},\"api_version\":\"v2\",\"meta\":{\"locale\":\"en_US\"}}}";
27+
"{\"checkout\":{\"items\":{\"wheel\":{\"display_name\":\"Great Deal Wheel\",\"sku\":\"wheel\",\"unit_price\":100000,\"qty\":1,\"item_url\":\"http://merchant.com/great_deal_wheel\",\"item_image_url\":\"http://www.image.com/111\",\"categories\":[[\"Apparel\",\"Pants\"],[\"Mens\",\"Apparel\",\"Pants\"]]}},\"currency\":\"USD\",\"shipping\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"billing\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"shipping_amount\":100000,\"tax_amount\":10000,\"total\":110000,\"metadata\":{\"entity_name\":\"internal-sub_brand-name\",\"shipping_type\":\"UPS Ground\",\"webhook_session_id\":\"ABC123\",\"platform_type\":\"Affirm Android SDK\",\"platform_affirm\":\"\"},\"merchant\":{\"public_api_key\":\"Y8CQXFF044903JC0\",\"user_confirmation_url\":\"affirm://checkout/confirmed\",\"user_cancel_url\":\"affirm://checkout/cancelled\",\"caas\":\"4626b631-c5bc-4c4e-800b-dd5fa27ef8b8\",\"user_confirmation_url_action\":\"GET\"},\"api_version\":\"v2\",\"meta\":{\"locale\":\"en_US\"}}}";
2828

2929
private static final String expectedCheckoutWithCardAuthWindowBody =
30-
"{\"checkout\":{\"items\":{\"wheel\":{\"display_name\":\"Great Deal Wheel\",\"sku\":\"wheel\",\"unit_price\":100000,\"qty\":1,\"item_url\":\"http://merchant.com/great_deal_wheel\",\"item_image_url\":\"http://www.image.com/111\"}},\"currency\":\"USD\",\"shipping\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"billing\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"shipping_amount\":100000,\"tax_amount\":10000,\"total\":110000,\"metadata\":{\"entity_name\":\"internal-sub_brand-name\",\"shipping_type\":\"UPS Ground\",\"webhook_session_id\":\"ABC123\",\"platform_type\":\"Affirm Android SDK\",\"platform_affirm\":\"\"},\"merchant\":{\"public_api_key\":\"Y8CQXFF044903JC0\",\"user_confirmation_url\":\"affirm://checkout/confirmed\",\"user_cancel_url\":\"affirm://checkout/cancelled\",\"card_auth_window\":10,\"user_confirmation_url_action\":\"GET\"},\"api_version\":\"v2\",\"meta\":{\"locale\":\"en_US\"}}}";
30+
"{\"checkout\":{\"items\":{\"wheel\":{\"display_name\":\"Great Deal Wheel\",\"sku\":\"wheel\",\"unit_price\":100000,\"qty\":1,\"item_url\":\"http://merchant.com/great_deal_wheel\",\"item_image_url\":\"http://www.image.com/111\",\"categories\":[[\"Apparel\",\"Pants\"],[\"Mens\",\"Apparel\",\"Pants\"]]}},\"currency\":\"USD\",\"shipping\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"billing\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"shipping_amount\":100000,\"tax_amount\":10000,\"total\":110000,\"metadata\":{\"entity_name\":\"internal-sub_brand-name\",\"shipping_type\":\"UPS Ground\",\"webhook_session_id\":\"ABC123\",\"platform_type\":\"Affirm Android SDK\",\"platform_affirm\":\"\"},\"merchant\":{\"public_api_key\":\"Y8CQXFF044903JC0\",\"user_confirmation_url\":\"affirm://checkout/confirmed\",\"user_cancel_url\":\"affirm://checkout/cancelled\",\"card_auth_window\":10,\"user_confirmation_url_action\":\"GET\"},\"api_version\":\"v2\",\"meta\":{\"locale\":\"en_US\"}}}";
3131

3232
private static String generateExpectedCheckoutBody() {
3333
return String.format(expectedCheckoutBody, BuildConfig.VERSION_NAME);

affirm/src/test/java/com/affirm/android/model/CheckoutTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
@RunWith(RobolectricTestRunner.class)
1414
public class CheckoutTest {
1515

16-
private static final String expectCheckout = "{\"items\":{\"wheel\":{\"display_name\":\"Great Deal Wheel\",\"sku\":\"wheel\",\"unit_price\":100000,\"qty\":1,\"item_url\":\"http://merchant.com/great_deal_wheel\",\"item_image_url\":\"http://www.image.com/111\"}},\"currency\":\"USD\",\"shipping\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"billing\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"shipping_amount\":100000,\"tax_amount\":10000,\"total\":110000,\"metadata\":{\"entity_name\":\"internal-sub_brand-name\",\"shipping_type\":\"UPS Ground\",\"webhook_session_id\":\"ABC123\"}}";
16+
private static final String expectCheckout = "{\"items\":{\"wheel\":{\"display_name\":\"Great Deal Wheel\",\"sku\":\"wheel\",\"unit_price\":100000,\"qty\":1,\"item_url\":\"http://merchant.com/great_deal_wheel\",\"item_image_url\":\"http://www.image.com/111\",\"categories\":[[\"Apparel\",\"Pants\"],[\"Mens\",\"Apparel\",\"Pants\"]]}},\"currency\":\"USD\",\"shipping\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"billing\":{\"address\":{\"street1\":\"333 Kansas st\",\"city\":\"San Francisco\",\"region1_code\":\"CA\",\"postal_code\":\"94103\",\"country\":\"USA\"},\"name\":{\"full\":\"John Smith\"}},\"shipping_amount\":100000,\"tax_amount\":10000,\"total\":110000,\"metadata\":{\"entity_name\":\"internal-sub_brand-name\",\"shipping_type\":\"UPS Ground\",\"webhook_session_id\":\"ABC123\"}}";
1717

1818
private final Gson gson = new GsonBuilder()
1919
.registerTypeAdapterFactory(AffirmAdapterFactory.create())

samples-java/src/main/java/com/affirm/samples/MainFragment.java

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import java.io.InputStreamReader;
4848
import java.math.BigDecimal;
4949
import java.util.ArrayList;
50+
import java.util.Arrays;
5051
import java.util.HashMap;
5152
import java.util.List;
5253
import java.util.Map;
@@ -273,6 +274,10 @@ private Checkout checkoutModel() {
273274
.setSku("wheel")
274275
.setUnitPrice(BigDecimal.valueOf(1000.0))
275276
.setUrl("http://merchant.com/great_deal_wheel")
277+
.setCategories(Arrays.asList(
278+
Arrays.asList("Apparel", "Pants"),
279+
Arrays.asList("Mens", "Apparel", "Pants")
280+
))
276281
.build();
277282

278283
final Map<String, Item> items = new HashMap<>();

samples-kotlin/src/main/java/com/affirm/sampleskt/MainActivity.kt

+1
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ class MainActivity : AppCompatActivity(), Affirm.CheckoutCallbacks, Affirm.VcnCh
119119
.setSku("wheel")
120120
.setUnitPrice(BigDecimal.valueOf(1000.0))
121121
.setUrl("http://merchant.com/great_deal_wheel")
122+
.setCategories(listOf(listOf("Apparel", "Pants"), listOf("Mens", "Apparel", "Pants")))
122123
.build()
123124
val items: MutableMap<String, Item> = HashMap()
124125
items["wheel"] = item

0 commit comments

Comments
 (0)