Skip to content

Payments

The PaymentService class handles the Stripe payment integration. It includes methods to create a customer, generate a payment intent, and initialize and present the payment sheet.

Display

Payment SheetOrder Confirmation

Prerequisites

  1. Create a Stripe account here
  2. Turn ON test mode Stripe Test mode
  3. Go to Developers -> API Keys. Copy the Secret Key and Publishable Key.
  4. Populate these values in assets/.env file for STRIPE_SECRET_KEY and STRIPE_PUBLISHABLE_KEY.

Steps

flutter_stripe library is used to handle payments. Steps in the documentation were followed here. It’s already included in the project.

await dotenv.load(fileName: "assets/.env");
Stripe.publishableKey = dotenv.get('STRIPE_PUBLISHABLE_KEY');

dotenv package is used to load environment variables from .env file.

http package is used to send requests to Stripe API, like createCustomer, createPaymentIntent, etc.

Regulatory requirements in India

For accepting international payments mandante sending following fields:

  • buyer's name
  • billing address
  • description of the product/service
  • shipping address if shipping is required

We supply these parameters to Stripe in _createStripeCustomer method and the customerID created is used to create a payment intent.

Note: If the buyer’s name, billing address, shipping address or description isn’t provided, the payment will fail.

More information on regulatory requirements in India can be found here and here.

Security

To ensure the security of payment processing, it is recommended to handle sensitive operations, such as creating payment intents, on the backend. This approach helps to protect your API keys and other sensitive information from being exposed.

In this project, the payment intent is created in the payment_service.dart file. However, for a more secure implementation, consider moving this logic to a backend service. This backend service can then communicate with the Stripe API and return the necessary information to your frontend application.

More information can be found here here.