Pujolsluis / StripeBookStore

Simple e-commerce application, that allows a customer to purchase a book utilizing Stripe as our Payments infrastructure.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

StripeBookStore

Simple e-commerce application, that allows a customer to purchase a book utilizing Stripe as our Payments infrastructure. The solution consist of 2 main projects (Backend server and Mobile client apps for iOS and Android):

About Solution

The solution leverages Stripe’s .NET Library, which is used on the server side to handle creating payment intents for products selected in the client app; thus providing a client secret that allows our users to confirm their payments on the client once they have created and selected a valid card payment method. I used the Stripe Payments and PaymentMethod API's for the basic InMemory Data Flow.

You can also enable an optional flow using Products stored on your test Stripe account that makes use of the Products, and Prices API's to get the most up to date price for the product before the purchase is complete.

The Client Apps users are notified in realtime that a successful charge has been made by using a Webhook that listens to the "charge.succeeded" StripeEvent in conjunction with a SignalR Hub.

iOS Android

Stripe Book Store - Adobe XD Project

Setup Demo

  • Create .env file in root of StripeBookStore.API project, that contains your Stripe account Keys. (Secret Key, Publishable Key and Webhook Secret Key)
STRIPE_PUBLISHABLE_KEY=<replace-with-your-publishable-key>
STRIPE_SECRET_KEY=<replace-with-your-secret-key>
STRIPE_WEBHOOK_SECRET_KEY=<replace-with-your-secret-key>
  • Run Backend Server solution StripeBookStore.API
cd StripeBookStore.API
dotnet run

  • Listen and Forward Stripe Webhook events to our local server, in order for the payment confirmation to work. Make sure to install the Stripe CLI and link your Stripe account:
stripe listen --forward-to http://localhost:42424/api/PaymentIntents/webhook

The CLI will print a webhook secret key to the console. Set STRIPE_WEBHOOK_SECRET to this value in your .env file.

Platforms Supported

Platform Version
ASP .NET Core 3.1
Xamarin.Forms 5.0+
Xamarin.iOS iOS 11+
Xamarin.Android API 21+

Solution Structure

StripeBookStore Project Structure

Challenges

In order to complete the assignment, I had to learn all the fundamentals about Stripe how their payment infrastructure works. The initial challenge I faced was not having worked previously with the product but I was really pleased to have found alot of great documentation, guides and a extensive API reference I could leverage to get an understanding of the product and the common payment use cases it supports.

I decided to use Xamarin.Forms as my client app solution and found that Stripe does not have official up to date Xamarin Bindings for their iOS and Android Native SDK's, I could not leverage their prebuilt UI's unless I wanted to invest time on creating the Xamarin Bindings and create the abstractions to use it seamlessly from the Shared Xamarin.Forms project, I felt this was out of scope for this project and decided to use the .NET Stripe Library, build custom screens and implement the payment flow accordingly.

Extending the project into a more robust instance

The current state of the project is not production ready and is more of a POC than a MVP, I would recommend extending it with the following improvements:

  • Server:

    • Payments:
      • Add Endpoints to manage products, customers and payment methods with Stripe API's instead of In-Memory Data.
    • Data:
      • Design and Implement Data Layer - define database model, entities, and persist and sync data with Stripe.
      • Add Caching
    • Authentication:
      • Add Security to REST API
      • Create User Authentication Endpoints
  • Client Apps:

    • UI/UX Improvements:
      • Add Search & Filters for Books Catalog Page - Allow user to search and filter the list of books.
      • Add Product Details Page - Allow the user to get an extended description, specifications, view multiple images and reviews about the product before commiting to purchase.
      • Extend Payment Flow in Client Apps from "Select a book > Checkout > Add Payment Method > Purchase Item" instead the app should also have:
        • Cart Page - Allows the users to CRUD their own collection of products to purchase.
        • Add Shipping Method Page - Allows user to set a shipping Address and get shipping options to complete order.
        • Persist Payment Methods - Allow users to save their payment methods and reuse when needed.
        • Payment Method Validation with Stripe 3D Secure - For banks that require validation, project should handle it gracefully.
      • Issue Refunds - Alows user to issue refunds for orders he has placed under a certain period of time.
      • Send Email Receipts - Users receive an email receipt of their purchase.
      • Localization - App should be localized for all the markets it wishes to support.
      • Authentication Flow - Users should be able to register and sign in to the app before being able to purchase (User must have a stripe customer associated to support features other features of stripe like saving payment methods, shipping method, and associating transactions to the account).
      • Implement Analytics and Crash reporting - Leverage AppCenter to collect realtime crashes and user events data from our client apps.
      • Refactor Implementation of SignalR - Polish implementation of SignalR on client and server, to cover cases like sending charge notification to specific users.

Useful References for completing project

Dev Tools Used

Resources

Mobile App

  • Xamarin - build native apps for Android, iOS, and macOS using .NET code and platform-specific user interfaces
  • Xamarin.Essentials - provides cross-platform APIs for their mobile applications
  • Xamarin.Forms - an open-source UI framework to build Android, iOS, and Windows applications from a single shared codebase
  • Prism.DryIoC - Prism is a framework for building loosely coupled, maintainable, and testable XAML applications in Xamarin Forms, I'm using the DryIoC DI container for this project.
  • AsyncAwaitBestPractices - Extensions for System.Threading.Tasks.Task
  • Refit - Refit is a REST library for .NET that converts REST APIs into live interfaces
  • Sharpnado.MaterialFrame - A modern Xamarin.Forms Frame component supporting blur, acrylic, dark mode. Implemented with RealtimeBlurView on Android (custom blurview) and UIVisualEffectView on iOS.
  • Stripe.NET - The official Stripe .NET library, supporting .NET Standard 2.0+, .NET Core 2.0+, and .NET Framework 4.6.1+.

Backend

  • .NET Core - an open-source, general-purpose development platform maintained by Microsoft and the .NET community on GitHub
  • ASP.NET Core - supports creating RESTful services, also known as web APIs, using C#. GitHub
  • Polly + HttpClientFactory - the recommended approach for retries with exponential backoff is to take advantage of more advanced .NET libraries
  • Refit + HttpClientFactory - IHttpClientFactory can be used in combination with third-party libraries such as Refit
  • Stripe.NET - The official Stripe .NET library, supporting .NET Standard 2.0+, .NET Core 2.0+, and .NET Framework 4.6.1+.
  • ASP .NET Core SignalR is a library for ASP .NET developers that simplifies the process of adding real-time functionality to applications.

About

Simple e-commerce application, that allows a customer to purchase a book utilizing Stripe as our Payments infrastructure.


Languages

Language:C# 100.0%