sabpaisa 1.0.1 copy "sabpaisa: ^1.0.1" to clipboard
sabpaisa: ^1.0.1 copied to clipboard

Official Flutter/Dart SDK for SabPaisa Payment Gateway 2.0 — payments, refunds, transaction enquiry, webhook verification.

SabPaisa Flutter SDK #

Official Flutter/Dart SDK for SabPaisa Payment Gateway 2.0.

Features #

  • Payment session creation with checkout URL
  • In-app browser redirect (redirectToCheckout)
  • Return URL signature verification
  • Transaction enquiry
  • Refund creation, status, and listing
  • Retry with exponential backoff on transient failures
  • Idempotency key support for safe retries

Installation #

Add to your pubspec.yaml:

dependencies:
  sabpaisa: ^1.0.0

Then run:

flutter pub get

Quick Start #

import 'package:sabpaisa/sabpaisa.dart';

final sabpaisa = SabPaisaClient(SabPaisaConfig(
  apiKey: 'sp_your_api_key',
  merchantId: 'YOUR_MERCHANT_ID',
  secretKey: 'sec_your_secret_key',
  clientCode: 'YOUR_CLIENT_CODE',
  env: Environment.staging, // or Environment.production
));

Usage #

Create a Payment #

final payment = await sabpaisa.payments.createSession(
  const CreatePaymentRequest(
    merchantTxnId: 'ORDER_123',
    amount: 50000, // Rs 500.00 in paise
    customerName: 'John Doe',
    customerEmail: 'john@example.com',
    customerMobile: '9876543210',
    // returnUrl is optional for in-app checkout — SDK provides a default.
    // Provide one if you handle the redirect yourself:
    // returnUrl: 'https://yoursite.com/callback',
  ),
);

print(payment.checkoutUrl); // Ready-to-use URL with clientSecret
print(payment.paymentId);

Redirect to Checkout (Flutter) #

Opens the checkout page in an in-app browser (Chrome Custom Tabs on Android, SFSafariViewController on iOS). No returnUrl needed:

await sabpaisa.payments.redirectToCheckout(
  const CreatePaymentRequest(
    merchantTxnId: 'ORDER_123',
    amount: 50000,
    customerName: 'John Doe',
    customerEmail: 'john@example.com',
    customerMobile: '9876543210',
  ),
);

Or get the URL and handle redirection yourself:

final url = sabpaisa.payments.getCheckoutUrl(payment);

Verify Return URL Callback #

After checkout, SabPaisa redirects to your returnUrl with signed query parameters:

final isValid = sabpaisa.payments.verifyReturnUrl(
  ReturnUrlParams.fromJson(callbackQueryParams),
);

if (isValid) {
  // Signature is authentic — safe to process
}

Transaction Enquiry #

final txn = await sabpaisa.transactions.enquiry(
  merchantTxnId: 'ORDER_123',
);

print(txn.data.status);       // SUCCESS, FAILED, PENDING
print(txn.data.amount);       // Amount in paise
print(txn.data.paymentMode);  // UPI, CARD, etc.

Refunds #

Create a refund:

final refund = await sabpaisa.refunds.create(
  const CreateRefundRequest(
    txnId: 'SP_TXN_456',
    amount: 25000, // Partial refund: Rs 250.00
    reason: 'Customer request',
  ),
  options: const RequestOptions(idempotencyKey: 'refund_ORDER_123_1'),
);

print(refund.data.refundId);

Check refund status:

final status = await sabpaisa.refunds.getStatus('REFUND_ID');
print(status.data.status); // PENDING, COMPLETED, FAILED

List refunds:

final list = await sabpaisa.refunds.list(
  const RefundListParams(page: 0, size: 20),
);

for (final r in list.data.refunds) {
  print('${r.refundId}: ${r.status}');
}

Configuration #

Parameter Required Description
apiKey Yes API key from SabPaisa dashboard
merchantId Yes Merchant ID for authentication
secretKey Yes HMAC secret for checksums
clientCode Yes Client code for API requests
env Yes Environment.staging or Environment.production
baseUrl No Custom URL override (takes precedence over env)

Error Handling #

The SDK provides typed errors for different failure scenarios:

try {
  await sabpaisa.payments.createSession(params);
} on ValidationError catch (e) {
  // Client-side validation failed
  print('${e.field}: ${e.message}');
} on ApiError catch (e) {
  // API returned an error
  print('${e.message} (HTTP ${e.statusCode})');
  print('Retryable: ${e.retryable}'); // true for 5xx, 429
} on SabPaisaError catch (e) {
  // Network error, timeout, etc.
  print('${e.code}: ${e.message}');
}

Amounts #

All amounts are in paise (1 INR = 100 paise):

Display Paise value
Rs 1.00 100
Rs 500.00 50000
Rs 1,999.00 199900

License #

MIT

0
likes
160
points
180
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Official Flutter/Dart SDK for SabPaisa Payment Gateway 2.0 — payments, refunds, transaction enquiry, webhook verification.

Homepage
Repository (GitHub)
View/report issues

Topics

#payments #fintech #payment-gateway #sabpaisa

License

MIT (license)

Dependencies

crypto, http, url_launcher, uuid

More

Packages that depend on sabpaisa