Skip to content

The Order API

Kuei-Jung Hu edited this page Jun 24, 2020 · 3 revisions

The order API enables Virtusize to show your customers the items they have recently purchased as part of their Purchase History, and use those items to compare with new items they want to buy.

Table of Contents

1. Initialization

2. Create a VirtusizeOrder object for order data

3. Send an Order

1. Initialization

Make sure to set up the user ID in your Application class's onCreate method before you start.

  • Kotlin
lateinit var Virtusize: Virtusize
override fun onCreate() {
    super.onCreate()
    Virtusize = VirtusizeBuilder().init(this)
            .setApiKey(api_key)
            .setUserId(user_id)
            .setEnv(VirtusizeEnvironment.STAGING)
            .build()
}
  • Java
Virtusize Virtusize;
@Override
public void onCreate() {
super.onCreate();
Virtusize = new VirtusizeBuilder()
        .init(this)
        .setApiKey(api_key)
        .setUserId(user_id)
        .setEnv(VirtusizeEnvironment.STAGING)
        .build();

2. Create a VirtusizeOrder object for order data

The VirtusizeOrder object gets passed to the Virtusize.sendOrder method, and has the following attributes:

Note: * means the attribute is required

VirtusizeOrder

Attribute Data Type Example Description
externalOrderId* String "20200601586" The order ID provided by the client
items* A list of VirtusizeOrderItem objects See the table below A list of the order items.

VirtusizeOrderItem

Attribute Data Type Example Description
productId* String "A001" The provide ID provided by the client. It must be unique for a product.
size* String "S", "M", etc. The name of the size
sizeAlias String "Small", "Large", etc. The alias of the size is added if the size name is not identical from the product page
variantId String "A001_SIZES_RED" An ID that is set on the product SKU, color, or size if there are several options for the item
imageUrl* String "http://images.example.com/coat.jpg" The image URL of the item
color String "RED", "R', etc. The color of the item
gender String "W", "Women", etc. An identifier for the gender
unitPrice* Double 5100.00 The product price that is a double number with a maximum of 12 digits and 2 decimals (12, 2)
currency* String "JPY", "KRW", "USD", etc. Currency code
quantity* Int 1 The number of the item purchased. If it's not passed, It will be set to 1
url String "http://example.com/products/A001" The URL of the product page. Please make sure this is a URL that users can access

Samples

  • Kotlin
val order = VirtusizeOrder("20200601586")
order.items = mutableListOf(
    VirtusizeOrderItem(
        "A001",
        "L",
        "Large",
        "A001_SIZEL_RED",
        "http://images.example.com/products/A001/red/image1xl.jpg",
        "Red",
        "W",
        5100.00,
        "JPY",
        1,
        "http://example.com/products/A001"
    )
)
  • Java
VirtusizeOrder order = new VirtusizeOrder("20200601586");
ArrayList<VirtusizeOrderItem> items = new ArrayList<>();
items.add(new VirtusizeOrderItem(
        "A001",
        "L",
        "Large",
        "A001_SIZEL_RED",
        "http://images.example.com/products/A001/red/image1xl.jpg",
        "Red",
        "W",
        5100.00,
        "JPY",
        1,
        "http://example.com/products/A001"
));

3. Send an Order

Call the Virtusize.sendOrder method in your activity or fragment when the user places an order.

  • Kotlin

The onSuccess and onError callbacks are optional.

(application as App)
    .Virtusize
    .sendOrder(order,
        // This success callback is optional and gets called when the app successfully sends the order
        onSuccess = {
            Log.i(TAG, "Successfully sent the order")
        },
        // This error callback is optional and gets called when an error occurs when the app is sending the order
        onError = { error ->
            Log.e(TAG, error.message())
        })
  • Java

The SuccessResponseHandler and ErrorResponseHandler callbacks are optional.

app.Virtusize.sendOrder(order,
        // This success callback is optional and gets called when the app successfully sends the order
        new SuccessResponseHandler() {
            @Override
            public void onSuccess(@Nullable Object data) {
                Log.i(TAG, "Successfully sent the order");
            }
        },
        // This error callback is optional and gets called when an error occurs when the app is sending the order
        new ErrorResponseHandler() {
            @Override
             public void onError(@Nullable Integer errorCode, @Nullable String errorMessage, @NotNull VirtusizeError error) {
                Log.e(TAG, VirtusizeErrorKt.message(error));
            }
        }
);

Clone this wiki locally