lori_sdk

A Flutter package to access Neomode's API (LORI).

Installation

Just follow the basic installation of any flutter plugin by adding the package to the project's pubspec.yaml.

Setting up this amazing package

To start you need to add the initialization code inside your main file.

void main() {
  ...
  // Widget call to avoid a bug within SharedPrefences library
  WidgetsFlutterBinding.ensureInitialized();
  // SDK init
  LoriApi.init('<LORI_API_URL>', '<LORI_CLIENT_ID>', '<LORI_CLIENT_SECRET>', <LORI_CATEGORY_VERSION>, '<OS_NAME_ANDROID_WEB_IOS>', '<OS_BUILD_NAME>', '<OS_VERSION>');
  ...
}

It's crucial to add the WidgetsFlutterBinding.ensureInitialized(); before the init call, otherwise the LoriApi won't work. Remember to replace the data inside the <> with the info gathered from Neomode.

Using the API to gather information for your app

Right now, the sdk has support for 88 endpoints from LORI's API. All methods return a Future with an ApiCallback type that can have a subtype depending on the method. Like the LoriApi().loadConfigurations() that has a return type of Future<ApiCallback>. The ApiCallback is a simple class with the following structure:

class ApiCallback<T> {
  ApiCallback({this.isSuccessful, this.resultData, this.resultErrorMessage, this.error});

  bool isSuccessful;
  T resultData;
  String resultErrorMessage;
  DioError error;
}

For key classes we've Singletons that delivery a StreamSubscription that will notify listeners when the key object change. All of them are listed below:

CartSingletion().registerToStream(Function callback); // Notify when the current Cart changes.
NotificationSingleton().registerToStream(Function callback); // Notify when a new object is added, updated or removed from the notifications list.
ProductSingleton().registerToStream(Function callback); // Notify when a new object is added, updated or removed from the saw products list.
SearchTermsSingleton().registerToStream(Function callback); // Notify when a new object is added, updated or removed from the list of searched terms.
UserSingleton().registerToStream(Function callback); // Notify when the current user changes.

To better help you with all the flows and how they should work we've created some kind of flowchart that can be accessed from here.

With this said, let's go to the list of available methods inside the SDK by today:

// Log in into the API using the credentials received by the init method.
LoriApi().loginClient(); // Return a Future<ApiCallback<void>>

// Log in a specific user into the API. If log in by sms you need only to pass the smsCode parameter. After this we have a CURRENT USER on the api.
LoriApi().loginUser({String username, String password, String smsCode}); // Return a Future<ApiCallback<void>>

// Refresh the auth token that was created when log in with a specific user.
LoriApi().refreshLogin(AuthResponse authResponse); // Return a Future<ApiCallback<void>>

// Logout the CURRENT USER from the API and the SDK.
LoriApi().logoutUser(); // Return a Future<ApiCallback<void>>

// Check if the email is already registered in this clientId
LoriApi().checkEmail(String email); // Return a Future<ApiCallback<void>>

// Load the UI configurations for the clientId.
LoriApi().loadConfigurations(); // Return a Future<ApiCallback<Configurations>>

// Load the tutorial that can be presented when the user is first opening the app.
LoriApi().loadTutorial(); // Return a Future<ApiCallback<List<TutorialItem>>>

// Load a product by it's id.
LoriApi().loadProduct(String productId); // Return a Future<ApiCallback<Product>>

// Load a list of related products by one another's product id.
LoriApi().loadProductRelated(String productId); // Return a Future<ApiCallback<List<Product>>>

// Load a list of products by a specific tag.
LoriApi().loadProductsByTag(String tags, String order, int page, int perPage); // Return a Future<ApiCallback<List<Product>>>

// Load a list of categories based on the api version received at the init method.
LoriApi().loadProductCategories(); // Return a Future<ApiCallback<List<Category>>>

// Load a category by it's id.
LoriApi().loadProductCategory(String categoryId); // Return a Future<ApiCallback<Category>>

// Load a list of subcategories by it's father's category id.
LoriApi().loadProductSubcategories(String categoryId); // Return a Future<ApiCallback<List<Subcategory>>>

// Load a list of products by it's father's subcategory id.
LoriApi().loadProductsFromSubcategory(String subcategoryId, String order, int page, int perPage); // Return a Future<ApiCallback<List<Product>>>

// Load a list of products by it's father's category id.
LoriApi().loadProductsFromCategory(String categoryId, String order, int page, int perPage); // Return a Future<ApiCallback<List<Product>>>

// Load a list of the most searched terms.
LoriApi().loadProductTerms(); // Return a Future<ApiCallback<List<String>>>

// Load a list of products by a string term.
LoriApi().loadProductsByTerm(String term, String order, int page, int perPage); // Return a Future<ApiCallback<List<Product>>>

// Load a list of banners.
LoriApi().loadBanners(); // Return a Future<ApiCallback<List<Banner>>>

// Load a list of promotions.
LoriApi().loadPromotions(); // Return a Future<ApiCallback<List<Promotion>>>

// Load a list answers and questions.
LoriApi().loadFaq(); // Return a Future<ApiCallback<List<Faq>>>

// Load the user terms of the clientId.
LoriApi().loadUserTerms(); // Return a Future<ApiCallback<UserTerms>>

// Load the user terms of the clientId.
LoriApi().loadPrivacyPolicy(); // Return a Future<ApiCallback<PrivacyPolicy>>

// Load a list of evaluations from a product.
LoriApi().loadProductEvaluations(String productId); // Return a Future<ApiCallback<Evaluation>>

// Load the evaluation form that the user must fullfil to send an evaluation.
LoriApi().loadProductEvaluationForm(); // Return a Future<ApiCallback<EvaluationForm>>

// Create an evaluation for a product.
LoriApi().crateProductEvaluation(String productId, List<OpinionResponse> responses); // Return a Future<ApiCallback<void>>

// Load a wishlist for the current LOGGED USER.
LoriApi().loadWishlist(); // Return a Future<ApiCallback<List<Product>>>

// Add a product to the wishlist of the current LOGGED USER.
LoriApi().addProductWishlist(String productId); // Return a Future<ApiCallback<void>>

// Remove a product to the wishlist of the current LOGGED USER.
LoriApi().removeProductWishlist(String productId); // Return a Future<ApiCallback<void>>

// Load all the stores registered within the clientId.
LoriApi().loadStores({double latitude, double longitude, int page = 1, int perPage = 100000}) // Return a Future<ApiCallback<StoreResult>>

// Load a list of complaints of the current LOGGED USER.
LoriApi().loadComplaints(); // Return a Future<ApiCallback<List<Complaints>>>

// Load a list of complaints types to show on the form to create a complaint.
LoriApi().loadComplaintTypes(); // Return a Future<ApiCallback<List<ComplaintType>>>

// Create a complaint for the current LOGGED USER.
LoriApi().createComplaint(String description, String orderId, bool isComplaint, String complaintType, {String externalOrderId}); // Return a Future<ApiCallback<void>>

// Validate all information within the current cart to check if it's a good cart. This method will handle the need of creating a new cart if none exists and/or the current cart is somehow buggy.
LoriApi().validateCart(); // Return a Future<ApiCallback<void>>

// Create a new cart within the API. THIS METHOD IS MANDATORY TO THE API. Everything only works if a cart was created. Make sure to call it.
LoriApi().createCart(); // Return a Future<ApiCallback<void>>

// Load the cart from API.
LoriApi().loadCart(); // Return a Future<ApiCallback<Cart>>

// Reset the cart to the initial state.
LoriApi().clearCart(); // Return a Future<ApiCallback<void>>

// Update a specific product quantity inside the cart. The quantity parameter is the quantity that will be ADDED to the current quantity.
LoriApi().updateCartItem(String skuId, int quantity); // Return a Future<ApiCallback<void>>

// Downgrade a specific product quantity inside the cart. The quantity parameter is the quantity that will be REMOVED from the current quantity.
LoriApi().downgradeCartItem(String skuId, int quantity); // Return a Future<ApiCallback<void>>

// Update the current cart owner. If no CURRENT USER the owner will be empty and if any CURRENT USER the CURRENT USER will be the new owner.
LoriApi().updateCartOwner(); // Return a Future<ApiCallback<void>>

// Update the latitude and the longitude of the current cart.
LoriApi().updateCartLocation(String lat, String lon); // Return a Future<ApiCallback<void>>

// Load a list of sellers that are available to fullfil the current cart items.
LoriApi().loadCartSellers(); // Return a Future<ApiCallback<List<Seller>>>

// Load a list of products with it's specific availability from the sellerId.
LoriApi().loadCartSellerItems(String sellerId); // Return a Future<ApiCallback<List<CartItem>>>

// Update the current cart seller that was selected.
LoriApi().updateCartSeller(String sellerId); // Return a Future<ApiCallback<void>>

// Update the current cart address that was selected.
LoriApi().updateCartAddress(String addressId); // Return a Future<ApiCallback<void>>

// Update the current cart cep that was selected.
LoriApi().updateCartCep(String cep); // Return a Future<ApiCallback<void>>

// Load a list of available freights for the current cart address/cep.
LoriApi().loadCartFreights(); // Return a Future<ApiCallback<List<Freight>>

// Update the current cart freight that was selected.
LoriApi().updateCartFreight(String freightReference); // Return a Future<ApiCallback<void>>

// Load a list of available installments for the current cart items.
LoriApi().loadCartInstallments(); // Return a Future<ApiCallback<List<Installment>>>

// Update the current cart installment that was selected.
LoriApi().updateCartInstallment(String installmentNumber); // Return a Future<ApiCallback<void>>

// Update the current cart invoice cpf that was selected.
LoriApi().updateCartInvoiceCpf(String cpf); // Return a Future<ApiCallback<void>>

// Update the current cart pickup cpf that was selected.
LoriApi().updateCartPickupCpf(String cpf); // Return a Future<ApiCallback<void>>

// Load a list of available paymentMethods that are available for selection.
LoriApi().loadCartPayments(); // Return a Future<ApiCallback<List<PaymentMethod>>>

// Update the current cart payment method that was selected.
LoriApi().updateCartPaymentMethod(String paymentId); // Return a Future<ApiCallback<void>>

// Update the current cart payment method that was selected.
LoriApi().updateCartVoucher(String voucherCode); // Return a Future<ApiCallback<void>>

// Remove the current cart payment method that was selected.
LoriApi().removeCartVoucher(String voucherCode); // Return a Future<ApiCallback<void>>

// Update the current cart cvv and them validate it with the card that was selected. This method only need to be called when the PaymentMethod has the type of CreditCard.
LoriApi().updateCartCvv(String cvv); // Return a Future<ApiCallback<void>>

// Update the current cart dealer code that was selected.
LoriApi().updateCartDealerCode(String dealerCode); // Return a Future<ApiCallback<void>>

// Update the current cart device fingerprint that was generated by the TrustDefender.
LoriApi().updateCartFingerprint(String deviceFingerprint); // Return a Future<ApiCallback<void>>

// Try to finalize the current cart. If this method return success, the current cart will be reseted.
LoriApi().finalizeCart(); // Return a Future<ApiCallback<void>>

// Load a address from a valid CEP.
LoriApi().loadAddressByCep(String cep); // Return a Future<ApiCallback<AddressCep>>

// Load a list of available states for the clientId.
LoriApi().loadStates(); // Return a Future<ApiCallback<List<AddressState>>>

// Load a list of available states for the clientId AND the state.
LoriApi().loadCities(String state); // Return a Future<ApiCallback<List<AddressCity>>>

// Update the that later will be used to send push notifications. IMPORTANT: this method need to be called when a new user is logged and when has done logout.
LoriApi().updateNotificationToken(String token); // Return a Future<ApiCallback<void>>

// Log that a notification was opened by the user.
LoriApi().notificationOpened(String notificationId); // Return a Future<ApiCallback<void>>

// Request a new password for an e-mail.
LoriApi().recoverUser(String email); // Return a Future<ApiCallback<void>>

// Request the change of a phone number for an e-mail.
LoriApi().recoverPhone(String email); // Return a Future<ApiCallback<void>>

// Request an SMS Code for both login by sms and for request password change.
LoriApi().requestSmsCode(String email); // Return a Future<ApiCallback<SmsRequestResult>>

// Request the change of the current password for an e-mail using a sms code.
LoriApi().requestPasswordChange(String email, String smsCode, String password); // Return a Future<ApiCallback<void>>

// Try to create a new user within the API. Validates if the e-mail already exists.
LoriApi().createUser(String email, String fullName, String cpf, String phoneNumber, String password); // Return a Future<ApiCallback<User>>

// Load all information about the CURRENT USER.
LoriApi().loadUser(); // Return a Future<ApiCallback<User>>

// Update some information of the CURRENT USER.
LoriApi().updateUser(String fullName, String cpf, String phoneNumber, {String dateOfBirth, int gender, String password}); // Return a Future<ApiCallback<void>>

// Update the user picture of the CURRENT USER.
LoriApi().updateUserPhoto(List<int> bytes); // Return a Future<ApiCallback<String>>

// Create a new address for the CURRENT USER.
LoriApi().createUserAddress(UserAddress address); // Return a Future<ApiCallback<UserAddress>>

// Update an existing address of the CURRENT USER.
LoriApi().updateUserAddress(UserAddress address); // Return a Future<ApiCallback<void>>

// Delete an existing address of the CURRENT USER.
LoriApi().deleteUserAddress(UserAddress address); // Return a Future<ApiCallback<void>>

// Load payment methods of the CURRENT USER.
LoriApi().loadUserPayments(); // Return a Future<ApiCallback<List<PaymentMethod>>>

// Create a new payment method for the CURRENT USER.
LoriApi().createUserPayment(String number, String cardHolder, String cvv, String expiration, String brand); // Return a Future<ApiCallback<PaymentMethod>>

// Delete a payment method of the CURRENT USER.
LoriApi().deleteUserPayment(String paymentId); // Return a Future<ApiCallback<void>>

// Load the card brand of the bin.
LoriApi().loadCardBrand(String bin); // Return a Future<ApiCallback<String>>

// Load all orders of the CURRENT USER.
LoriApi().loadOrders(); // Return a Future<ApiCallback<List<Order>>>

// Load a order by it's id of the CURRENT USER.
LoriApi().loadOrder(String orderId); // Return a Future<ApiCallback<Order>>

// Load a order's available payment methods. THIS METHOD MUST BE CALLED ONLY IF THE Order().isOrderRetryingPayment() is TRUE.
LoriApi().loadOrderPayments(Order order); // Return a Future<ApiCallback<List<PaymentMethod>>>

// Update the order payment method that was selected. THIS METHOD MUST BE CALLED ONLY IF THE Order().isOrderRetryingPayment() is TRUE.
LoriApi().updateOrderPayment(Order order, PaymentMethod paymentMethod); // Return a Future<ApiCallback<void>>

// Update the order cvv that was selected. THIS METHOD MUST BE CALLED ONLY IF THE Order().isOrderRetryingPayment() is TRUE and the payment method has a type of CreditCard.
LoriApi().updateOrderPaymentCvv(Order order, String cvv); // Return a Future<ApiCallback<void>>

// Load an order's available installments.
LoriApi().loadOrderInstallments(Order order); // Return a Future<ApiCallback<List<Installment>>>

// Update an order installment that was previously selected.
LoriApi().updateOrderInstallment(Order order, String installmentNumber); // Return a Future<ApiCallback<void>>

// Restart the payment process of an order after the payment method was updated. THIS METHOD MUST BE CALLED ONLY IF THE Order().isOrderRetryingPayment() is TRUE.
LoriApi().restartOrder(Order order); // Return a Future<ApiCallback<void>>

// Cancel an order. THIS METHOD MUST BE CALLED ONLY IF THE Order().isOrderRetryingPayment() is TRUE.
LoriApi().cancelOrder(Order order); // Return a Future<ApiCallback<void>>

I need help or i want to help you guys, what should i do?

Mail us at joao@neomode.com.br with your doubt or suggestion that we'll be very pleased to help you.

Remember, we do this with all love. From Curitiba <3

Libraries

addressCep
addressCity
addressState
authResponse
authResponseDao
authResponseDaoStub
brandConfigurations
buyedItem
cart
cartDao
cartDaoStub
cartItem
cartSingleton
category
check_email_response
complaint
complaintType
configurations
dealer
dealerRanking
evaluation
evaluationForm
extensions
faq
favoriteProduct
firebase_api
freight
installment
internalConfigurations
key_value
lori_api
lori_push_notification_token
lori_sdk_exception
lori_utils
mobileAuthResponseDao
mobileCartDao
mobileNotificationDao
mobileProductDao
mobileSearchTermsDao
mobileUserDao
notification
notificationDao
notificationDaoStub
notificationSingleton
opinion
opinionQuestion
opinionResponse
order
orderCodeType
orderInstallment
orderStep
paymentInfo
paymentMethod
privacyPolicy
product
productDao
productDaoStub
productImage
productOrder
productPaginationResult
productSingleton
productTag
promotion
promotionPolicy
ranking
sales_api
sales_catalog_api
sales_commerce_api
sales_commerce_carts_api
sales_marketing_api
sales_retailer_api
sales_search_api
searchTerm
searchTermsDao
searchTermsDaoStub
searchTermsSingleton
seller
sellerModality
skuAttribute
smsRequestResult
store
storeResult
trustDefenderConfiguration
tutorial
user
userAddress
userDao
userDaoStub
userPromotion
userSingleton
userTerms
voucher
webAuthResponseDao
webCartDao
webNotificationDao
webProductDao
webSearchTermsDao
webUserDao
whatsapp_configurations