Skip to content

Commit

Permalink
docs: Updated documentations and instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
tamimattafi committed Jun 12, 2021
1 parent d025527 commit 144ee65
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 146 deletions.
169 changes: 23 additions & 146 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
# Tezro OpenApi for JVM and Android
This repository contains the JVM implementation of Tezro OpenApi. It offers an easy and simple integration with your app.
It also has a support for android and a sample app demonstrating the usage of this library and the API in general.
This repository contains the JVM implementation of Tezro OpenApi.
It offers an easy and simple integration with your app.

It also has a support for android. Check the sample app for usage examples.

## Getting Started

After creating an account in [**Tezro**](https://tezro.com/), you will be able to create and external shop through **Settings -> External Shop**.

You will get your own **KeyId** and **Secret** that you will be using inside your app.
If you are willing to make only public requests such as creating orders, getting a specific order data.. You only need a **KeyId** (Suitable for a client app such as android or desktop)
You will get your own `KeyId` and `Secret` that you will be using inside your app.
If you are willing to make only public requests such as creating orders, getting a specific order data.. You only need a `KeyId` (Recommended for a client apps such as android or desktop).

For a detailed information on how to get your keys please visit our registration instruction below:

[**Registration**](./instructions/registration/registration.md)

## Installation

Our library is published to **mavenCentral**, so you need to include this repository in your project.
Our library is published to `mavenCentral`, so you need to include this repository in your project.

**Gradle**
```groovy
Expand All @@ -29,152 +35,23 @@ dependencies {
<artifactId>shop</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.tezro.api</groupId>
<artifactId>shop-android-widget</artifactId>
<version>1.0.1</version>
</dependency>
```

## Usage
For more information on how to use the api, please visit the instruction pages below:

### Android Widget

1. Before using this library you have to initialize it using your **KeyId**.
This is suitable to call only onces when your application is created:
```kotlin
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
ShopWidget.init(keyId = "your-key-id-goes-here", isTestMode = true)
}
}
```

`isTestMode` indicates whether to use development or production API.

2. Integrating `TezroPayButton` to your view:
```xml
<com.tezro.api.shop.widget.views.TezroPayButton
android:id="@+id/btnTezroPay"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
```

3. Customize the button (currently only through code):
```kotlin
tezroPayButton.apply {
buttonLabel = "1 USD"
isAutomaticRedirectEnabled = true
isQRCodeEnabled = false
isSilentUpdate = false
paymentQRLabel = "Scan this QR and pay!"
}
```
[**Android**](./instructions/usage/shop-widget-usage.md)

Follow this [**Link**](https://gitlab.i-link.pro/tezro/tezro-android-open-api/-/blob/master/docs/shop-android-widget/shop-android-widget/com.tezro.api.shop.widget.views/-tezro-pay-button/index.md#properties) to read more about these properties

4. Implement `TezroPayButton.TezroPayButtonDelegate` to listen to events:
```kotlin
override fun onRequestOrderInit() {
//Indicates that user has clicked but no order data was provided
tezroPayButton.initOrder(
orderId = UUID.randomUUID().toString(),
name = "Test order ${Random().nextInt()}",
amount = "1",
currency = Order.Currency.USD,
confirmAmountUrl = "https://www.google.com",
expiryDate = Date(System.currentTimeMillis() + 100000),
photos = listOf("https://prod-buydo.oss-accelerate.aliyuncs.com/9a537dfd2e9a493f8fef4d35d119a43b.jpg"),
attributes = listOf(Attribute("Color", "Red"))
)
}

override fun onLoadingOrderStart() {
//Called after `tezroPayButton.initOrder`, indicates that loading order has started
showToast("Creating order...")
}
[**JVM (Desktop/Backend)**](./instructions/usage/shop-usage.md)

override fun onNewOrderDataLoaded(order: Order) {
//Called when loading order finishes, this is a suitable place to check for new status
when(order.status) {
Order.Status.CREATED -> TODO()
Order.Status.EXPIRED -> TODO()
Order.Status.ADDRESS_CONFIRMED -> TODO()
Order.Status.CONFIRMED -> TODO()
Order.Status.DELIVERED -> TODO()
Order.Status.RECEIVED -> TODO()
Order.Status.DISPUTED -> TODO()
}
}

override fun onLoadingOrderError(error: Error) {
//Called when loading order fails, show error to the users
showToast("Something went wrong $error...")
}
```

5. Assign it to your button using:
```kotlin
tezroPayButton.delegate = myDelegateImplementation
```

+ To update button data when users come back to your app, call this in your `onResume`:
```kotlin
override fun onResume() {
super.onResume()
tezroPayButton.updateOrder()
}
```

+ You can manually set orders to this button using:
```kotlin
tezroPayButton.order = myOrder
```
This is suitable if you want load your data using our JVM implementation while respecting your architecture rules.

+ `TezroPayButton` is an open class, all methods and properties are open so you can extend it and customize it the way it suits you.
```kotlin
class CustomTezroButton(
context: Context,
attributeSet: AttributeSet
) : TezroPayButton(context, attributeSet) {
...
}
```

+ `TezroPayButton` uses XML resources for styles, colors and size. You can override these resources to customize your button within your resources.

### JVM (Desktop/Backend)
1. Before using this library you have to initialize it using your **KeyId**, and **Secret** if you want to call private methods.
```kotlin
val shopService = Shop.initShopService(
keyId = "your-key-id-goes-here",
secret = "your_secret_goes_here",
isTestMode = true
)
```
### Documentations
For a detailed information about methods and objects, please visit our documentation pages below:

`isTestMode` indicates whether to use development or production API.
`initShopService` will always give you a new instance of `IShopService`. It is your responsibility to handle implement singleton pattern.

2. After that, your service is ready to handle your calls, here's an example of creating an order:
```kotlin
val request = shopService.createOrder(
orderId = UUID.randomUUID().toString(),
name = "Test order ${Random().nextInt()}",
amount = "1",
currency = Order.Currency.USD,
confirmAmountUrl = "https://www.google.com",
expiryDate = Date(System.currentTimeMillis() + 100000),
photos = listOf("https://prod-buydo.oss-accelerate.aliyuncs.com/9a537dfd2e9a493f8fef4d35d119a43b.jpg"),
attributes = listOf(Attribute("Color", "Red"))
)

request.setSuccessListener { order ->
//Handle your new order
}.setErrorListener { error ->
//Handle errors
}.enqueue()
```
The request will run on a background thread, so no need to worry about blocking the current thread.
Follow this **[Link](https://gitlab.i-link.pro/tezro/tezro-android-open-api/-/blob/master/docs/shop/shop/com.tezro.api.shop.service/-i-shop-service/index.md#functions)** to check all methods that you can call through this service.
[**Android**](./docs/shop-android-widget/index.md)

### Documentations
* [**Shop**](https://gitlab.i-link.pro/tezro/tezro-android-open-api/-/blob/master/docs/shop/index.md)
* [**Shop-Android-Widget**](https://gitlab.i-link.pro/tezro/tezro-android-open-api/-/blob/master/docs/shop-android-widget/index.md)
[**JVM (Desktop/Backend)**](./docs/shop/index.md)
19 changes: 19 additions & 0 deletions instructions/registration/registration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Registration

To register a new shop, please download [**Tezro**](https://tezro.com/) mobile app or use the web/desktop version.

## When you open the app you will be asked to sign in:
![Welcome Screen](./screens/authorization_screen.jpg)

Create a new account or use your existing one.

## After completing authorization steps, head to the settings tab, then click on **External Shop**:
![Settings Tab](./screens/settings_screen.jpg)

## This will proceed you to a registration form, enter your shop's data:
![External Shop Screen](./screens/shop_creation_screen.jpg)

## After completing the form, please click save to receive your `KeyId` and `Secret`:
![External Shop Screen](./screens/shop_details_screen.jpg)

## That's it! You are now ready to use the api!
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
45 changes: 45 additions & 0 deletions instructions/usage/shop-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Usage - JVM (Desktop/Backend)
Before using this library you have to initialize it using your `KeyId` and `Secret` if you are willing to call private methods.

Create a new instance of shop service:
```kotlin
val shopService = Shop.initShopService(
keyId = "your-key-id-goes-here",
secret = "your_secret_goes_here",
isTestMode = true
)
```

`isTestMode` indicates whether to use development or production API. To get a development `keyId` and `secret` you need to download Tezro-dev version and retrieve them from there.

`initShopService` will always give you a new instance of `IShopService`. Creating a new instance might not be cheap so it is recommended to implement singleton pattern.

Once you create an instance of the service, you can call any method depending on the access level you provide `(KeyId + Secret = Full Access`.

Here's an example of creating a new order:
```kotlin
//Create a request
val request = shopService.createOrder(
orderId = UUID.randomUUID().toString(),
name = "Test order ${Random().nextInt()}",
amount = "1",
currency = Order.Currency.USD,
confirmAmountUrl = "https://www.google.com",
expiryDate = Date(System.currentTimeMillis() + 100000),
photos = listOf("https://prod-buydo.oss-accelerate.aliyuncs.com/9a537dfd2e9a493f8fef4d35d119a43b.jpg"),
attributes = listOf(Attribute("Color", "Red"))
)

//Set up listeners to your request and enqueue it
request.setSuccessListener { order ->
//Handle your new order
}.setErrorListener { error ->
//Handle errors
}.enqueue()

//To cancel your request call
request.cancel()
```

The request will run on a background thread, so no need to worry about blocking the current thread.
Follow this **[Link](../../docs/shop/shop/com.tezro.api.shop.service/-i-shop-service/index.md)** to check all methods that you can call through this service.
107 changes: 107 additions & 0 deletions instructions/usage/shop-widget-usage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
# Usage - Android Widget

Before using this library you have to initialize it using your `KeyId`.

Initialization needs to happen only onces during your application's lifetime:
```kotlin
class MyApplication : Application() {
override fun onCreate() {
super.onCreate()
ShopWidget.init(keyId = "your-key-id-goes-here", isTestMode = true)
}
}
```

`isTestMode` indicates whether to use development or production API. To get a development `keyId` you need to download Tezro-dev version and retrieve them from there.

Integrating `TezroPayButton` to your view:
```xml
<com.tezro.api.shop.widget.views.TezroPayButton
android:id="@+id/btnTezroPay"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
```

Customize the button (currently only through code, xml attributes will be available in future updates):
```kotlin
tezroPayButton.apply {
buttonLabel = "1 USD"
isAutomaticRedirectEnabled = true
isQRCodeEnabled = false
isSilentUpdate = false
paymentQRLabel = "Scan this QR and pay!"
}
```

Follow this [**Link**](../../docs/shop-android-widget/shop-android-widget/com.tezro.api.shop.widget.views/-tezro-pay-button/index.md) to read more about these properties

Implement `TezroPayButton.TezroPayButtonDelegate` to listen to events:
```kotlin
override fun onRequestOrderInit() {
//Indicates that user has clicked but no order data was provided
tezroPayButton.initOrder(
orderId = UUID.randomUUID().toString(),
name = "Test order ${Random().nextInt()}",
amount = "1",
currency = Order.Currency.USD,
confirmAmountUrl = "https://www.google.com",
expiryDate = Date(System.currentTimeMillis() + 100000),
photos = listOf("https://prod-buydo.oss-accelerate.aliyuncs.com/9a537dfd2e9a493f8fef4d35d119a43b.jpg"),
attributes = listOf(Attribute("Color", "Red"))
)
}

override fun onLoadingOrderStart() {
//Called after `tezroPayButton.initOrder`, indicates that loading order has started
showToast("Creating order...")
}

override fun onNewOrderDataLoaded(order: Order) {
//Called when loading order finishes, this is a suitable place to check for new status
when(order.status) {
Order.Status.CREATED -> TODO()
Order.Status.EXPIRED -> TODO()
Order.Status.ADDRESS_CONFIRMED -> TODO()
Order.Status.CONFIRMED -> TODO()
Order.Status.DELIVERED -> TODO()
Order.Status.RECEIVED -> TODO()
Order.Status.DISPUTED -> TODO()
}
}

override fun onLoadingOrderError(error: Error) {
//Called when loading order fails, show error to the users
showToast("Something went wrong $error...")
}
```

Assign it to your button using:
```kotlin
tezroPayButton.delegate = myDelegateImplementation
```

To update button data when users come back to your app, call this in your `onResume`:
```kotlin
override fun onResume() {
super.onResume()
tezroPayButton.updateOrder()
}
```

You can manually set orders to this button using:
```kotlin
tezroPayButton.order = myOrder
```
This is suitable if you want load your data using our JVM implementation while respecting your architecture rules.

`TezroPayButton` is an open class, all methods and properties are open so you can extend it and customize it the way it suits you.
```kotlin
class CustomTezroButton(
context: Context,
attributeSet: AttributeSet
) : TezroPayButton(context, attributeSet) {
...
}
```

`TezroPayButton` uses XML resources for styles, colors and size. You can override these resources to customize your button within your resources.

0 comments on commit 144ee65

Please sign in to comment.