Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WirecardMobileServices/a0c04c00196e6b9b065efe1cafdae7f0 to your computer and use it in GitHub Desktop.
Save WirecardMobileServices/a0c04c00196e6b9b065efe1cafdae7f0 to your computer and use it in GitHub Desktop.
import com.jakewharton.rxrelay2.BehaviorRelay;
import com.jakewharton.rxrelay2.Relay;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import de.wirecard.epos.model.sale.builder.PurchaseRequest;
import de.wirecard.epos.model.sale.builder.payment.EftCardPurchasePayment;
import de.wirecard.epos.model.sale.sales.SaleItem;
import de.wirecard.epos.model.sale.sales.SaleItemType;
import de.wirecard.epos.model.with.With;
import de.wirecard.epos.model.with.WithBase;
import de.wirecard.epos.util.events.Event;
import de.wirecard.epos.util.events.TerminalEvent;
import de.wirecard.epos.util.events.acceptance.AppSignatureConfirmationEvent;
import de.wirecard.whitelabel.BaseTest;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
// discover active terminals before payment
// check terminal discovery section
epos.terminal().discoverDevices(); // ...
Relay<Event> eventRelay = BehaviorRelay.create();
WithBase withBase = With.base().scheduler(Schedulers.newThread());
// create list of sale items
List<SaleItem> items = new ArrayList<>(1);
items.add(new SaleItem(SaleItemType.PURCHASE, "item 1", new BigDecimal("10"), null, new BigDecimal("1"), new BigDecimal("20"), new BigDecimal("10"), null, null, null, null));
EftCardPurchasePayment payment = new EftCardPurchasePayment(
new BigDecimal("10"), // payment amount
null // notify callback url
);
PurchaseRequest purchaseRequest = new PurchaseRequest(
new BigDecimal("10"), // amount of whole Sale, mandatory field
"EUR", // currency code, mandatory field
"note", // optional
"shopId",// optional
"externalId",// optional
"customerId",// optional
"mail@email.com",// optional
"cashRegisterId",// optional
payment,
items, // optional
true, // unitPricesIncludeTax, optional
null // location, optional
);
epos.sales()
.operation()
.purchase(purchaseRequest)
//.purchase(purchaseRequest, withBase) // in case you want request to run on specific thread
.subscribeParallel(eventRelay)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(saleId -> {
// sale was performed successfully
// saleId String is returned, you can load whole sale object by calling epos.sales().getSale(String saleId)
}, throwable -> {
// handle error
});
eventRelay
.observeOn(AndroidSchedulers.mainThread())
.subscribe(event -> {
if (event instanceof TerminalEvent.SignatureRequest) {
String img = "image in Base64 format";
((TerminalEvent.SignatureRequest) event).signatureEntered(img.getBytes()); // image in base 64
((TerminalEvent.SignatureRequest) event).signatureCanceled(); // sale canceled, because signature was not collected
}
else if (event instanceof TerminalEvent.SignatureConfirmation) {
((TerminalEvent.SignatureConfirmation) event).getEnteredSignature(); // signature confirmation can be performed in terminal or in app
if (event instanceof AppSignatureConfirmationEvent) { // this event indicates it has to be confirmed in app side
((AppSignatureConfirmationEvent) event).signatureConfirmed(); // signature confirmed in app
((AppSignatureConfirmationEvent) event).signatureCanceled(); // signature confirmation canceled in app
}
}
else if (event instanceof TerminalEvent.PaymentInfo) { // provided some information during payment which can be shown to user
((TerminalEvent.PaymentInfo) event).getAppLabel();
((TerminalEvent.PaymentInfo) event).getApplicationId();
((TerminalEvent.PaymentInfo) event).getCardholderName();
((TerminalEvent.PaymentInfo) event).getPanTag();
}
else if (event instanceof Event.Update) { // update events indicates change of progress
String update = ((Event.Update) event).getMessage(context);
}
else if (event instanceof BaseTerminalUiEvent) {
((BaseTerminalUiEvent)event).getTitle(context); // update events indicates change of progress when you are using Android based terminal
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment