Discount

Handles Discount related requests with IMS web services.

Discount

The SDK allows for the host application to retrieve discount related data, which in turn can be used by the host application to fetch data from the Discount system (see documentation for the Discount).

This service will take in an Identity and return the current discount and projected discount, alongside some useful discount information. Discount values may not always be available due to insufficient driving data.

Required information

*Identity: In order to fetch discount data, the application must have a valid user (represented by the Identity). That user must be active.

Concrete example

To fetch discount data, one can use the following snippet

let service = DiscountService(identity: identity)
service.fetchDiscount(then: { discount in
    guard !discount.value.isEmpty else {
        // failure
        return
    }
    completionHandler(.success(discount.value))
})

Discount Metadata

Represents the mapping between scores ranges and discounts. The mappings of scores are represented as Ranges of Doubles to be consistent with the scoring values.

Any valid user on the DriveSync system (identified via the Identity) should be able to know how discount is calculated (score ranges vs discounts), so that driver knows how his/her driving style affecting his/her discount.

Required information

*Identity: In order to fetch discount mapping data, the application must have a valid user (represented by the Identity). That user must be active.

Concrete example

To fetch discount mapping data, one can use the following snippet

let service = DiscountMetadataService(identity: identity)
service.fetchDiscountMetadata(then: { discount in
    guard !discount.value.isEmpty else {
        // failure
        return
    }
    completionHandler(.success(discount.value))
})

Discount by vehicle

The SDK allows for the host application to retrieve discount related data by vehicle, which in turn can be used by the host application to fetch data from the Discount system (see documentation for the Discount).

This service will take in an Identity and return the current discount and projected discount, alongside some useful discount information. Discount values may not always be available due to insufficient driving data.

Required information

*Identity: In order to fetch discount data, the application must have a valid user (represented by the Identity). That user must be active.

Since each account can be linked to multiple vehicles, vehicle ID is passed.

Concrete example

To fetch discount data by vehicle, one can use the following snippet

val discountService = DiscountService(identity)
discountService.fetchDiscountByVehicle(vehicleId) { result: Result<DiscountMetaData>? ->
     if (result?.value == null || result.throwable != null) {
            // failure
        } else {
            // Success
           val discountMetaData: DiscountMetaData = result?.value
            completionHandler(discountMetaData)
        }

 }

Last updated