A PowaTag SDK provides a module that adds the minimum classes to RxJava that make writing reactive components in Android applications easy and hassle-free.
Please read Getting Started for instruction on setting up your project.

The com.powatag.android.sdk.rx.RxManagerFactory provides access to the Rx manager classes:

  • RxLoginManager
  • RxProfileManager
  • RxBasketsManager
  • RxProductManager
  • RxWorkflowManager
  • RxCampaignManager
  • RxActManager
  • RxPaymentManager
  • RxPosManager
  • RxMerchantManager
  • RxCouponManager
  • RxTransactionManager
  • RxPowaTagExecutor

These classes contain all the methods described in the documentation examples but allow you to compose asynchronous and event-based implementation using observable sequences.

Tips for Interpreting Examples

While reading the documentation just keep the following tips in mind:

Obtaining an Instance of a Rx Manager

Instead of using:

ProductManager productManager = ManagerFactory.getInstance().getProductManager();

Use:

RxProductManager productManager = RxManagerFactory.getInstance().getRxProductManager();

Substituting Methods

The Bidco SDK documentation uses examples of asynchronous methods that use callbacks.

Just substitute the asynchronous code with RxJava code, so if you see:

paymentManager.authorize(invoice, passcodeEditText.getText().toString(), new PowaTagCallback<Void>() {
	@Override
	public void onSuccess(Void aVoid) {
		// The invoice is now authorised
	}
		
	@Override
	public void onError(PowaTagException e) {
	}
});

Replace it with this:

paymentManager.authorize(invoice, passcodeEditText.getText().toString()).subscribe(new Subscriber<Void>() {
	public void onCompleted() {
		// The invoice is now authorised		
	} 

	public void onError(Throwable e) {
	}
	public void onNext(Address addedAddress) {
	}
});

Handling Collections

When a collection is returned in a callback, just use the onNext method to iterate through the collection.

As an example, this code snippet shows how to retrieve the available discounts using a callback:

ManagerFactory.getInstance().getCouponManager().getAvailableDiscounts(basket, new PowaTagCallback<List<Discount>>() {
	@Override
	public void onSuccess(List<Discount> possibleDiscounts) {
		// Display all discounts to the user and use discount.getSavings() to show the savings.
	}

	@Override
	public void onError(PowaTagException e) {
	}
});

Instead use:

RxManagerFactory.getInstance().getCouponManager().getAvailableDiscounts(basket).subscribe(new Subscriber<List<Discount>>() {
	@Override
	public void onCompleted() {
	} 
	@Override
	public void onError(Throwable e) {
	}

	@Override
	public void onNext(List<Discount> possibleDiscounts) {
		// Display the discount to the user and use discount.getSavings() to show the savings.
	}
});