Guest User

Untitled

a guest
Dec 14th, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. // create list of sale items
  2. List<SaleItem> items = new ArrayList<>(1);
  3. items.add(new SaleItem(SaleItemType.PURCHASE, "item 1", new BigDecimal("10"), null, new BigDecimal("1"), new BigDecimal("20"), new BigDecimal("10"), null, null, null));
  4.  
  5. // you can put requested objects or use more convenient way via builder which can lead you through mandatory fields
  6. accept.sales()
  7. .pay(SaleBuilder.newBuilder() // builder will guide you what you have to put
  8. .setAmount(new BigDecimal("10")) // amount of whole sale, mandatory field
  9. .setCurrency(Currency.getInstance("EUR")) // currency of whole sale, mandatory field
  10. .unitPricesIncludeTax() // choose if tax is included or excluded, mandatory field but you can choose from 3methods, unitPricesIncludeTax(), unitPricesExcludeTax(), setUnitPricesIncludeTax(boolean unitPricesIncludeTax)
  11. .addAlipayPayment(new BigDecimal("10"), "scannedConsumerIdFromAlipayApplication")
  12. //or
  13. .addWechatPayment(new BigDecimal("10"), "scannedConsumerIdFromWechatApplication")
  14. .setSaleItems(items)
  15. .setCashierId("cashier id")
  16. // ...
  17. .build()
  18. )
  19. .subscribeParallel(eventRelay)
  20. .observeOn(AndroidSchedulers.mainThread())
  21. .subscribe(saleId -> {
  22. // sale was performed successfully
  23. // saleId String is returned, you can load whole sale object by calling accept.sales().getSale(String saleId)
  24. }, throwable -> {
  25. // handle error
  26. });
  27. eventRelay
  28. .observeOn(AndroidSchedulers.mainThread())
  29. .subscribe(event -> {
  30. if (event instanceof Event.Update) { // update events indicates change of progress
  31. String update = ((Event.Update) event).getMessage(context);
  32. }
  33. else if (event instanceof Event.PasswordConfirmation) { //wechat payment method can ask for confirmation, that customer entered pin
  34. onPasswordConfirmation((Event.PasswordConfirmation) event);
  35. }
  36. });
Add Comment
Please, Sign In to add comment