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
Prerequisites
- Create a Stripe account here
- Turn ON test mode
- Go to
Developers
->API Keys
. Copy theSecret Key
andPublishable Key
. - Populate these values in
assets/.env
file forSTRIPE_SECRET_KEY
andSTRIPE_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.
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/serviceshipping 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.