The nagad_payment_gateway package allows Flutter developers to integrate Nagad Online Payment into their applications. This package is ideal for merchants and service providers looking to enable digital payments using Nagad.
Before integrating, obtain your credentials from Nagad:
final merchantID = "YOUR_MERCHANT_ID"
final merchantPrivateKey = "YOUR_MERCHANT_PRIVATE_KEY"
final pgPublicKey = "NAGAD_PAYMENT_GATEWAY_PUBLIC_KEY"
Create an instance of Credentials and provide it to the Nagad Instance:
Nagad nagad = Nagad(
credentials: const Credentials(
merchantID: merchantID,
merchantPrivateKey: merchantPrivateKey,
pgPublicKey: merchantPrivateKey,
isSandbox: true)); // Set to false for production
Note: Make sure to replace the provided credentials with your Nagad Sandbox or production credentials.
You can provide additional details about your service to be displayed on the payment page.
Field Name | Max Length | Description |
---|---|---|
serviceName | 25 | Service Name Provided by Merchant |
serviceLogoURL | 1~1024 | Publicly accessible logo URL |
additionalFieldName EN | 20 | Additional Field Name to be shown in Payment Page for Locale EN |
additionalFieldName BN | 20 | Additional Field Name to be shown in Payment Page for Locale BN |
additionalFieldValue | 20 | Value of Additional Field in English |
Map<String, dynamic> additionalMerchantInfo = {
“serviceName” : “T Shirt”,
“serviceLogoURL” : “tinyurl.com/sampleLogoUrl”,
“additionalFieldNameEN” : “Color”,
“additionalFieldNameBN” : “রং”,
“additionalFieldValue” : “White”
};
nagad.setAdditionalMerchantInfo(additionalMerchantInfo);
N.B: additionalMerchantInfo must be in Map<String, dynamic> type. Additional Merchant Info can be anything and will be saved for further usage. However only these fields will be shown in the payment page.
To initiate a Regular Payment, use the pay
method.
NagadResponse nagadResponse = await nagad.regularPayment(
context,
amount: 10.25,
orderId: orderId,
);
amount
: The payment amount (Recommended asdouble
).orderId
: A unique identifier for each payment. You can use milliseconds since epoch for uniqueness.
DateTime now = DateTime.now();
String orderId = 'order${now.millisecondsSinceEpoch}';
NagadResponse class contains:
- merchantId
- orderId
- paymentRefId
- amount
- clientMobileNo
- merchantMobileNo
- orderDateTime
- issuerPaymentDateTime
- issuerPaymentRefNo
- additionalMerchantInfo
- status
- statusCode
- cancelIssuerDateTime
- cancelIssuerRefNo
- serviceType
Note: Always store the required details in your database for future reference and reconciliation.
To test payments in Sandbox Mode, ensure isSandbox: true
is set when initializing Nagad
. Use the test credentials provided by Nagad.
When moving to production:
- Change
isSandbox: false
. - Replace Sandbox credentials with production credentials.
- Ensure your merchant account is verified by Nagad.
Do not store merchant credentials directly in your Flutter application. Instead, use a secure backend server to handle payments securely and prevent exposure of sensitive data.
✅ Use a backend server to securely process payments and store credentials.
✅ Never store or expose your merchantPrivateKey
or other sensitive data in the frontend.
This package is licensed under the GNU General Public License (GPL) version 3.0.
© 2025 - Nagad Payment Gateway for Flutter