-
Notifications
You must be signed in to change notification settings - Fork 3
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.
2. Create a VirtusizeOrder object for order data
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();The VirtusizeOrder object gets passed to the Virtusize.sendOrder method, and has the following attributes:
Note: * means the attribute is required
| 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. |
- 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"
));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));
}
}
);