Skip to content

Commit

Permalink
Version 0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
Travis CI User committed Jul 3, 2019
1 parent 820fbc9 commit 2a58140
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 138 deletions.
84 changes: 44 additions & 40 deletions doc/customer.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,11 @@
# Customers

Customers are managed via a `CustomerOperation`

A customer operation can be retrieved using the following.

```
val customerOperation = FlyBuy.customer.getCustomerOperation()
```

## Observe the customer

Returns a `LiveData` stream of the current customer to observe. The customer received will either be the logged in user or `null`

```
val customer: Customer = customerOperation.customers
```

## Create a Customer

Create a customer account using information from the user. Consent should be collected from the user (e.g. checkboxes)
Create a customer account using information from the user. Consent should be collected from the user (e.g. checkboxes).

```
```kotlin
fun createCustomer() {
val customerInfo = CustomerInfo (
name = "Marty McFly",
carType = "DeLorean",
Expand All @@ -32,20 +17,22 @@ Create a customer account using information from the user. Consent should be col
ageVerification = true
)

fun createProfile(): LiveData<WorkStatus> {
return customerOperation.create(customerInfo, customerConsent)
FlyBuy.customer.create(customerInfo, customerConsent) { customer, sdkError ->
// Handle customer or deal with error
}
}
```

## Sign Up a Customer
## Create a Customer with Login

Create a customer account with email and password using information from the user. Consent should be collected from the user (e.g. checkboxes)
Create a customer account with email and password using information from the user. Consent should be collected from the user (e.g. checkboxes).

```
```kotlin
fun createCustomerWithLogin() {
val loginInfo = LoginInfo (
email = "[email protected]",
password = "password"
}
)
val customerInfo = CustomerInfo (
name = "Marty McFly",
carType = "DeLorean",
Expand All @@ -57,66 +44,83 @@ Create a customer account with email and password using information from the use
ageVerification = true
)

fun signUp(): LiveData<WorkStatus> {
return customerOperation.signUp(customerInfo, loginInfo, customerConsent)
FlyBuy.customer.createWithLogin(customerInfo, loginInfo, customerConsent) { customer , sdkError ->
// Handle customer or deal with error
}
}
```

## "Upgrade" a Customer
## Sign Up a Customer

Link an email and password with the current anonymous logged in user
Link an email and password with the current anonymous logged in user.

```
```kotlin
fun signUp() {
val loginInfo = LoginInfo (
email = "[email protected]",
password = "password"
)

fun upgrade(): LiveData<WorkStatus> {
return customerOperation.upgrade(customerInfo)
FlyBuy.customer.signUp(loginInfo) { customer, sdkError ->
// Handle customer or deal with error
}
}
```

## Sign In

Sign the user in using existing credentials

```
```kotlin
fun login() {
val loginInfo = LoginInfo(
email = "[email protected]",
password = "password"
)

fun login(loginInfo: LoginInfo): LiveData<WorkStatus> {
return customerOperation.login(loginInfo)
FlyBuy.customer.login(loginInfo) { customer, sdkError ->
// Handle customer or deal with error
}
}
```

## Sign out the current Customer

Signs out the current customer.

```
fun signOut(): LiveData<WorkStatus> {
return customerOperation.logout()
```kotlin
fun signOut() {
FlyBuy.customer.signOut { sdkError ->
// Handle error
}
}
```

## Update a Customer

Update customer info for the logged in user

```
```kotlin
fun updateCustomer() {
val customerInfo = CustomerInfo (
name = "Marty McFly",
carType = "DeLorean",
carColor = "Silver",
licensePlate = "OUTATIME"
)

fun update(customerInfo: CustomerInfo): LiveData<WorkStatus> {
return customerOperation.updateCustomer(customerInfo)
FlyBuy.customer.update(customerInfo) { customer, sdkError ->
// Handle customer or deal with error
}
}
```

## Get the current Customer

Returns an instance of the current customer. This may not be accessed directly from the main thread.

```kotlin
FlyBuy.customer.current
```


47 changes: 24 additions & 23 deletions doc/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,42 @@ FlyBuy can leverage Google's Firebase Cloud Messaging (FCM) to get updates about

To pass the message to FlyBuy, override the `FirebaseMessagingService.onMessageReceived` method as follows.

```
```kotlin
override fun onMessageReceived(remoteMessage: RemoteMessage?) {
// result is a LiveData<WorkStatus> object that can be observed
val result = FlyBuy.onMessageReceived(remoteMessage)
FlyBuy.onMessageReceived(remoteMessage) { sdkError ->
// Handle error
}
}
```

You do not need to filter or check the body of the `remoteMessage` data, FlyBuy will inspect it and only process the notification if it is relevant to the SDK.

Since a device's push token can change, the FlyBuy SDK needs to be informed when that occurs. To do so, override the `FirebaseMessagingingService.onNewToken()` method as follows.

```
override fun onNewToken(token: String?) {
FlyBuy.onNewPushToken(token)
}
```kotlin
override fun onNewToken(token: String?) {
FlyBuy.onNewPushToken(token)
}
```

The SDK should also be updated with the push token when the app starts. The following code snippet provides an example function that can be called from `onCreate()` in your activity.

```
private fun updatePushToken() {
FirebaseInstanceId.getInstance().instanceId
.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Timber.w(task.exception, "getInstanceId failed")
return@OnCompleteListener
}
// Get new Instance ID token
task.result?.token?.let {
FlyBuy.getInstance(this).onNewPushToken(it)
}
})
}
```kotlin
private fun updatePushToken() {
FirebaseInstanceId.getInstance().instanceId
.addOnCompleteListener(OnCompleteListener { task ->
if (!task.isSuccessful) {
Timber.w(task.exception, "getInstanceId failed")
return@OnCompleteListener
}

// Get new Instance ID token
task.result?.token?.let {
FlyBuy.getInstance(this).onNewPushToken(it)
}

})
}
```

## Setting the Service Notification Title and Content
Expand Down
124 changes: 49 additions & 75 deletions doc/orders.md
Original file line number Diff line number Diff line change
@@ -1,95 +1,60 @@
# Orders

Orders are managed via a `OrdersOperation`
## Fetch Orders

Each operation can be retrieved using the following:
Fetch the latest orders with the server

```
val ordersOperation = FlyBuy.orders.getOrdersOperation()
```

## Observe the orders

Returns a `LiveData` stream of orders

```
openOrders = getOrdersOperation.orders.open()
closedOrders = getOrdersOperation.orders.closed()
```

## Syncing Orders

Syncs the latest orders with the server and returns a `LiveData<WorkStatus>` stream for observing status

```
fun sync(): LiveData<WorkStatus>? {
return ordersOperation.sync()
fun fetchOrders() {
FlyBuy.orders.fetch { orders, sdkError ->
// Handle orders or deal with error
}
}
```

## Redeem Order
## Claim Order

First, check that an order exists for a given redeem code
An order which is created in the FlyBuy service can be "claimed" by the SDK in order to associate it with the current customer.

```
fun checkCode(): LiveData<WorkStatus>? {
return redeemCode.value?.let {
ordersOperation.findOrder(it)
}
}
```
To get information about an unclaimed order, the app can call `fetch(redemptionCode, callback)`

Claim the order for the customer for the given redeem code

```
fun redeemOrder(): LiveData<WorkStatus>? {
return listOf(redeemCode.value, customerInfo.value).any {it == null}.let {
null
} ?: run {
ordersOperation.claimOrder(redeemCode.value!!, customerInfo.value!!)
}
```kotlin
fun fetchOrder() {
FlyBuy.orders.fetch(redemptionCode) { order, sdkError ->
// update order claim view with order details here
}
}
```

## Create Order

Create an order by passing order identifiers to the `create` method. There are numerous attributes available, but the only mandatory ones are the `siteID` and `partnerIdentifier`. Returns a `LiveData<WorkStatus>` stream for observing status

```
val info = CreateOrderInfo(
siteID = 101,
partnerIdentifier = "1234123",
customerCarColor = "#FF9900",
customerCarType = "Silver Sedan",
customerLicensePlate = "XYZ-456",
customerName = customerName
)
fun create(): LiveData<WorkStatus> {
return ordersOperation.findOrder(info)
To claim the order for the current customer, the app should call the `claim` method:

```kotlin
fun claimOrder() {
val customerInfo = CustomerInfo (
name = "Marty McFly",
carType = "DeLorean",
carColor = "Silver",
licensePlate = "OUTATIME"
)
FlyBuy.orders.claim(redemptionCode, customerInfo) { order, sdkError ->
// if sdkError == null, order has been claimed
}
}
```

#### Order Info attributes

| Attribute | Description |
| ---------------------- | ----------------------------------------------- |
| `siteID` | The FlyBuy Site Identifier |
| `partnerIdentifier` | Internal customer or order identifier. |
| `customerCarColor` | Color of the customer's vehicle |
| `customerCarType` | Make and model of the customer's vehicle |
| `customerLicensePlate` | License plate of the customer's vehicle |
| `customerName` | Customer's name |
| `pushToken` | The token used for push messages (or sent to the webhook) |
After an order is claimed, the app may want to call `FlyBuy.orders.fetch()` to update the list of orders. The newly claimed order should now appear in the list of open orders which is available via `FlyBuy.orders.open`.

## Updating Orders

Orders are always updated with an Order Event. Returns a `LiveData<WorkStatus>` stream for observing status
Orders are always updated with an Order Event.

```
fun create(): LiveData<WorkStatus> {
return ordersOperation.event(order, CustomerState.waiting)
```kotlin
fun updateOrder() {
FlyBuy.orders.event(order, CustomerState.WAITING) { order, sdkError ->
// if sdkError == null, order has been updated
}
}
```

#### Order Event attributes
Expand All @@ -103,10 +68,19 @@ Orders are always updated with an Order Event. Returns a `LiveData<WorkStatus>`

| Value | Description |
| ----------- | ------------------------------------------------------------------- |
| `created` | Order has been created |
| `enRoute` | Order tracking is started the customer is on their way |
| `nearby` | The customer is close to the site |
| `arrived` | The customer has arrived on premises |
| `waiting` | The customer is in a pickup area or manually said they were waiting |
| `completed` | The order is complete |
| `CREATED` | Order has been created |
| `EN_ROUTE` | Order tracking is started the customer is on their way |
| `NEARBY` | The customer is close to the site |
| `ARRIVED` | The customer has arrived on premises |
| `WAITING` | The customer is in a pickup area or manually said they were waiting |
| `COMPLETED` | The order is complete |

## Observe the orders

If you are using Android Jetpack, you can observe orders using `LiveData` streams of orders

```kotlin
val openOrders = FlyBuy.orders.open
val closedOrders = FlyBuy.orders.closed
```

Loading

0 comments on commit 2a58140

Please sign in to comment.