Ionic app development: Creating a Location-sharing app with Ionic!

Ionic app development: Creating a Location-sharing app with Ionic!
Most of the modern-day applications have the facility of Google maps and location-sharing. Whether a taxi-booking app or a social media app or a food-ordering app, all have this vital feature embedded in the apps. Since this feature has become essential, several businesses have developed advanced location-sharing apps or at least embedded this feature in diverse apps.
So, in this blog, we are going to look at the basic procedure to build a location-sharing app or integrate this vital feature in them. Here we will use Ionic, the popular cross-platform framework, for this purpose. The reason to consider Ionic app development is that this technology is easy to adopt, enables the development of captivating UI/UX, and feature-rich performance-based apps. It is built on AngularJS which offers various functionalities for development and a robust environment that makes the code more manageable. Also, Ionic utilizes Cordova plugins and allows widget development. Owing to such myriad benefits, a plethora of businesses hire Ionic application development company for architecting enterprise applications.
So let’s get started, but before that, let us have a quick look at the criteria that the Ionic developers would be assuming before starting with the development.
  1. We will be using Firebase for saving the data.
  2. We will create a custom directive for integrating Google Maps into our application.
  3. We will be creating a mobile app for the Android platform.

Steps to Architect a Location-sharing app with Ionic

Installations of relevant softwares

  • The first step is to install Node.js which automatically installs npm i.e. node package manager. Now you can install Ionic with the use of npm.
  • Also, install the required dependencies for the Android platform. After installing them, you need to create a blank Ionic project.
  • Now navigate to the project directory iMapApp. After this, you can add the desired platform, develop it, and emulate. Now, a blank app will probably be running in the Android emulator. But, this process of running the app in the emulator every time will be time-intensive. So, it is advisable to use Ionic CLI for running the application in the browser. Once again, it is essential to install the required dependencies with the use of npm.
  • After installing the dependencies, you need to run “ionic serve” in the terminal for the app to run in the browser.

UI Creation

  • You can begin with the addition of a new template for showing the map. Now create a new folder known as www/templates in the project directory. Also,create a file named map.html inside templates.
  • Google Maps will be rendered inside the HTML map where a div known as #map will be present. Also, there will be an input text box below the map for the users to fill the description and also a button for the details to be saved.
  • Now we will be using the “ionNavView” directive to create different templates based on various states. Add this directive to index.html page. The next step is the removal of the current contents of the body tag and addition of the “ionNavBar” directive above the “ionNavView” for building a top bar.
  • The title for the “ionNavBar” will be set from the rendered “ionView”.
  • For the proper organization of the app interfaces into multiple states, the Angular UI router module is utilized by Ionic. Now open www/js/app.js as we will define a state for the map.html template by writing the required code.
  • After implementing this code a new state for the URL “/map” is defined. This state will be rendering the template map.html and will be controlled by “MapCtrl” controller. To set the map as the default state, command “$urlRouterProvider.otherwise(‘/map’)” is used.
  • Now create a file- “controller.js” inside “www/js/” and also add its reference in the file called- “www/index.html”
  • Then define the angular module first for defining controller code inside “controller.js”
  • After this, define the controller “MapCtrl” and then enter the “starter.controllers” module into the starter app. After saving this, you can view the map.html template.
  • Then you should add the Google Map in map.html which can be done by the creation of a custom directive known as“map”. Let us now define the directive in controller.js and add the directive attribute to div #map in map.html.

Adding default parameters like longitude, latitude, zoom in the Maps

  • First, pass the longitude, latitude, and zoom parameters to the google map directive. With the use of parameter “attrs” you can access these attributes inside the link function of the directive.
  • For evaluation of AngularJS expressions, “scope.$eval” is used.
  • The next step is to include the Google Maps API reference in index.html. Using the default values, Google Map’s latitude and longitude can be defined. Also, define map options for Google Map.
  • With appropriate code, add style to “www/css/style.css” for styling the “#map” div.
  • Lastly, save all the modifications to view Google Maps on the map page.

Adding a marker to the Google Maps

  • We need to modify the directive with the right code. Marker’s default position is set as longitude and latitude that is passed as an attribute. Also, the draggable option is set as true.
  • After implementing the code and saving the changes, a draggable marker will be visible in Google Maps.

Tracking the position of Marker

  • For this purpose, we will be attaching a “dragend” event to the Google Maps marker. Also, for attaching the drag end event listener inside the directive, add the right code
  • After saving these changes, just try to drag the marker. Now inspect the browser console which must include the current longitude and latitude.

Saving all the details

  • In “MapCtrl”, define a $scope variable called “user” which will consist of information like longitude, latitude, and the data that the user enters.
  • In “MapCtrl” controller, create a function known as “saveDetails” which will use “scope.user” variable for fetching the required information.
  • Update the variables- “$scope.user.longitude” and “$scope.user.latitude” in the “dragend” event listener’s callback function when the users will move the marker on the map
  • For updating the model bindings, call the “scope.$apply” function. After this, you need to attach the following:
    • a ngModel directive to the description input text box
    • a ngClick directive to the save button
  • Now save the data to Firebase. For this, you will first need to register with Firebase if you don’t have an account. After logging in, you will get a unique firebase URL.
  • After signing to the Firebase account, in the dashboard, you will find a plus link next to this URL. Click on that plus link and enter the below-mentioned inputs to get a sub URL- /MapDetails.
    • value as 0
    • name as “MapDetails”
  • To use firebase in the app, Include the script references in index.html. Insert firebase in controller.js and MapCtrl controller. Create a firebase object inside this controller. Create an instance of the firebase object. Use the firebase push API inside the saveDetails function, for saving the data to firebase. Once saved, refresh the application.
  • Now just drag the marker to a certain location on the Maps, enter some description and save this. All this data should be present when you check the firebase dashboard.
  • After the data is saved, using the Ionic popup, create an alert for notifying the users. In the MapCtrl controller, inject the $ionicPopup. Again, in the MapCtrl controller, add a function known as “showAlert”.
  • This function calls the “$ionicPopup” service for showing a pop-up having a template and a title.
  • After this, you should call “showAlert” in the success callback of the push API call.
  • Finally, save all the changes and the details once again. After saving these details in Firebase,you will get a pop-up showing a success message. This completed the process.

Conclusion:

We just saw the step-by-step method to integrate Google maps in the Ionic Apps. We hope this will be useful to the Ionic developers and also to an Ionic app development company aiming to design impeccable apps with location-sharing functionality.
Was this blog useful to you? Let us know your vital thoughts in the comment section.

An Overview of Stripe Payment Processing in React Native Apps!

An Overview of Stripe Payment Processing in React Native Apps!
One of the vital segments of the React Native development is the payment integration process and this blog is all about that.
Well, making online payments through the web or mobile apps is a common practice today. As a result, millions of apps have the payment processing feature embedded in them. Various payment gateways are used for this purpose, like PayPal, Braintree, Stripe, Expo, RazorPay, AWS Amplify, etc. to name a few. Out of these, Stripe is one of the most widely used and fastest-growing gateways. It is also being extensively used in a diverse range of React Native apps and is a preferred choice of several React Native app development services worldwide.
So let us have a glimpse at what is Stripe, its working mechanism, and the step-by-step method to integrate it in the React Native applications.

What is Stripe?

As discussed earlier, Stripe is a popular payment gateway or a payment processing platform founded in 2010. It is used by individuals or businesses- small or large, for accepting payments via credit and debit cards, recurring payments used for subscriptions, sending payouts, and also process automated clearing house (ACH) transactions. It also serves as a third-party payment processor and supports various payment methods such as Google Pay, Apple Pay, Masterpass by Mastercard, Wechat Pay, Microsoft Pay, etc.
Stripe is quite easy to integrate due to the availability of easy-to-use APIs. Also, it provides prevention from frauds, banking, and technical infrastructure, etc. that is needed for on-line payment systems operation. A large number of eCommerce solutions are using Stripe. Currently Stripe powers the payment processing for some of the well-known brands including Lyft, Pinterest, Blue Apron, Under Armour, etc.

Working Mechanism of Stripe in React Native Apps

Let us understand how Stripe works in React Native apps with a pictorial representation.
  • A payment is initiated in the frontend of a React Native app. Details like card number, expiry date, CVV, etc. are sent to Stripe.
  • In case of valid details, a token is sent by the Stripe server to the app.
  • After this token is received on the app, payment information along with token information has to be sent to your backend server. Your backend server will communicate with the server of Stripe along with the token and payment details.
  • After successful completion of payment, Stripe sends the transaction response to the backend server.
  • Then the backend server sends the payment success response to the app.

Stripe and React Native development

Stripe can be implemented in the frontend of the React Native apps in two ways as mentioned below:
  1. Integrating the Stripe SDK for Android or iOS
  2. Using a 3rd party library like Tipsi-stripe
Both of these methods have their share of pros and cons. The Tipsi-stripe library can be easily implemented and works smoothly. But as of now, Stripe has not ‘publicly’ approved the React Native library from Tipsi. But preferring Stripe’s SDK’s is considered a smarter choice when one is looking for maximum compliance in a production environment.

How to implement Stripe?

Note: Here we have considered the Tipsi-stripe library for integration of Stripe. Also, version 0.60 of React Native was used. Also, we considered a Firebase server for the backend part.

Step 1: Creation of Stripe Developer account and getting the API keys

For creating the account, visit Stripe.com. Note that the services provided by Stripe are limited to certain countries. After account creation and registration, you will land in the Stripe Dashboard. Then go to Developer Tab > API keys for accessing the keys. Ensure that for viewing the ‘Test Data,’ you ON the toggle. All the development tasks must be carried out with ‘Test Data’.
‘Publishable key’ is used to connect the react native app with the Strive Native SDK or Tipsi-stripe library. This key is used for generating a token. ‘Secret key’ is used in the backend for the actual payment processing, where your server makes a connection with the Stripe server using this secret key. After testing the process, you may toggle to ‘Live keys.’

Step 2: Development of a React Native app for integrating Stripe

For developing a basic app, ensure that you are equipped with all the pre-requisites pertaining to the React Native’s official documentation. Now create a blank app and run it in a simulator or device. The default start screen will appear on the simulator or device. You may use the user interface of the Tipsi-stripe library because it supports all kinds of payment options viz. Google Pay, Apple Pay, etc.

Step 3: Integration of the Tipsi-stripe library for the generation of token

Install Tipsi-stripe package for integrating Stripe functionality into your react native app. Now, set up your Podfile for the integration of appropriate pods in iOS apps and then run pod install. Then set up the Xcode project, link the Tipsi-stripe package against your Xcode project, this will install all dependencies related to CocoaPods. Import the library in your app for the generation of the token. Now initialize it with the Stripe credentials which you will get from Stripe Dashboard. The Publishable key is used for generating token only. Now replace the Publishable key with your own key.
To generate the token, the ‘paymentRequestWithCardForm’ method can be used from the library. This method will open the card details Stripe form. User will receive a token from the Stripe after entering the card details in the above form.

Step 4: Creation of Firebase function or any other backend server

For completing the payment, we can create a Firebase cloud function (or any other backend server) and execute it using REST calls from your app. This function will interact with the Stripe server and successfully complete the payment. The sub-steps involved in this process are as follows:
  • Create a Firebase project and cloud functions.
  • In the app Install Firebase tools.
  • Connect your React Native development environment to the Firebase console.
  • Developing a Firebase function for making payment requests. This function accepts request object from the app, then sends the request of payment to the Stripe server and returns the response from Stripe to the application.
  • Testing the Firebase Function internally using firebase serve, as external API calls are allowed by Firebase only for paid accounts.
  • Deploying Firebase Function to live server.

Step 5: Connection of the app with the deployed live Firebase server and completion of the payment

The final step involves making an HTTP call to the Firebase function and completing the payment request using the generated token. In this way, payment processing happens in the React Native apps using the Stripe gateway.

Concluding Lines:

In this blog, we learned that there are two important sections in the Stripe payments- frontend for the tokenization process and backend for the payment requesting and completion. The Tipsi-stripe package is used for the frontend part and any server can be used for the backend part. We have gone through the significant steps involved in this process which will be very helpful to React Native developers and every React Native app development company aiming to design top-notch apps with a sleek payment processing feature.
We hope this blog was useful to you! Please share your thoughts in the comments section. For any other details, you may mail us at sales.enquiry@biz4solutions.com!