This is an woocommerce api client for android
Built-based on the documentation: http://woocommerce.github.io/woocommerce-rest-api-docs/#introduction
Please note that files are still being moved around - the project should be stable before end Feb 2019
Step 1. Add the JitPack repository to your build file
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
Step 2. Add the dependency
<dependency>
<groupId>com.github.gilokimu</groupId>
<artifactId>woodroid</artifactId>
<version>0.2.0</version>
</dependency>
Step 1. Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Step 2. Add the dependency
dependencies {
implementation 'com.github.gilokimu:woodroid:0.2.0'
}
Generate API credentials (Consumer Key & Consumer Secret) following this instructions http://docs.woocommerce.com/document/woocommerce-rest-api/ .
Check out the WooCommerce API endpoints and data that can be manipulated in https://woocommerce.github.io/woocommerce-rest-api-docs/.
I have left consumer key and secret within the app, for you to test the app without an installation of wordpress. To use my installation of wordpress, here are the credentials:
username: demo password: demo2019 https://gilo.me/store/wp-admin
PS/ Do no harm
Setup for the new WP REST API integration (WooCommerce 2.6 or later):
val woocommerce = Woocommerce.Builder()
.setSiteUrl("http://example.com")
.setApiVersion(Woocommerce.API_V2)
.setConsumerKey("ck_XXXXX")
.setConsumerSecret("cs_XXXX")
.build()
Getting products example
woocommerce.ProductRepository().products().enqueue(object : Callback<List<Product>> {
override fun onResponse(call: Call<List<Product>>, response: Response<List<Product>>) {
val productsResponse = response.body()
for (product in productsResponse!!) {
products.add(product)
}
adapter.notifyDataSetChanged()
}
override fun onFailure(call: Call<List<Product>>, t: Throwable) {
}
})
The sdk currently supports :
- Order Notes
- Refunds
- Attributes
- Attribute Terms
- Product Category
- Shipping Class
- Product Tags
- Variations
- Coupons
- Customers
- Orders
- Products
- Reports
- Settings
- Payment gateway
The general resource method calls are
- Create - Pass the object to create
- List - a list of all items
- View single method - retries a single item
- Delete - deletes the resource
- Filter - provides a list that meets a criteria
Create an instance of the resource then pass onto a .create() function on the resource repository
val coupon = Coupon()
coupon.code = code
coupon.description = description
woocommerce.CouponRepository().create(coupon).enqueue(object : Callback<Coupon> {
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
val couponResponse = response.body()
finish()
}
override fun onFailure(call: Call<Coupon>, t: Throwable) {
}
})
woocommerce.CouponRepository().coupons().enqueue(object : Callback<List<Coupon>> {
override fun onResponse(call: Call<List<Coupon>>, response: Response<List<Coupon>>) {
val couponResponse = response.body()
for (coupon in couponResponse!!) {
coupons.add(coupon)
}
adapter.notifyDataSetChanged()
}
override fun onFailure(call: Call<List<Coupon>>, t: Throwable) {
}
})
val couponId = intent.getIntExtra("couponId", 0)
woocommerce.CouponRepository().coupon(couponId).enqueue(object : Callback<Coupon> {
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
val coupon = response.body()!!
etCode.setText(coupon.code.toUpperCase())
etDescription.setText(coupon.description)
}
override fun onFailure(call: Call<Coupon>, t: Throwable) {
}
})
woocommerce.CouponRepository().delete(couponId).enqueue(object : Callback<Coupon> {
override fun onResponse(call: Call<Coupon>, response: Response<Coupon>) {
if (response.isSuccessful) {
val coupon = response.body()!!
finish()
}else{
Toast.makeText(this@CouponActivity, "" + response.code() + " : " + response.message(), Toast.LENGTH_SHORT).show()
}
}
override fun onFailure(call: Call<Coupon>, t: Throwable) {
stopShowingLoading()
}
})
val filter = CouponFilter()
filter.search = "FEB"
woocommerce.CouponRepository().coupons(filter).enqueue(object : Callback<List<Coupon>> {
override fun onResponse(call: Call<List<Coupon>>, response: Response<List<Coupon>>) {
val couponResponse = response.body()
for (coupon in couponResponse!!) {
coupons.add(coupon)
}
adapter.notifyDataSetChanged()
}
override fun onFailure(call: Call<List<Coupon>>, t: Throwable) {
}
})
The sample app implements an MVVM approach which would look slightly different from the above. The methods are the same though
Contributions are highly welcomed, just create a PR
You can also reach out through slack in case of any issues with installation or feature request
You can donate to support the project futher. Donate with Crypto