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.

example/example.dart

import 'package:sabpaisa/sabpaisa.dart';

void main() async {
  // 1. Initialize the client
  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, // Use Environment.production for live
  ));

  // 2. Create a payment session (returnUrl is optional for in-app checkout)
  try {
    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 — SDK uses a default for in-app checkout.
        // Provide one if you handle the redirect yourself:
        // returnUrl: 'https://yoursite.com/callback',
      ),
    );

    print('Checkout URL: ${payment.checkoutUrl}');
    print('Payment ID: ${payment.paymentId}');

    // In a Flutter app, use redirectToCheckout() to open in-app browser
    // (no returnUrl needed):
    // await sabpaisa.payments.redirectToCheckout(params);
  } on ValidationError catch (e) {
    print('Validation: ${e.field} — ${e.message}');
  } on ApiError catch (e) {
    print('API error: ${e.message} (HTTP ${e.statusCode})');
  }

  // 3. Verify return URL callback
  final isValid = sabpaisa.payments.verifyReturnUrl(
    const ReturnUrlParams(
      transactionId: 'SP_TXN_456',
      merchantTxnId: 'ORDER_123',
      status: 'SUCCESS',
      amount: '50000',
      paidAmount: '50000',
      paymentMode: 'UPI',
      timestamp: '1700000000',
      signature: 'abc123...',
    ),
  );
  print('Signature valid: $isValid');

  // 4. Transaction enquiry
  try {
    final txn = await sabpaisa.transactions.enquiry(
      merchantTxnId: 'ORDER_123',
    );
    print('Transaction status: ${txn.data.status}');
  } on ApiError catch (e) {
    print('Enquiry failed: ${e.message}');
  }

  // 5. Create a refund
  try {
    final refund = await sabpaisa.refunds.create(
      const CreateRefundRequest(
        txnId: 'SP_TXN_456',
        amount: 25000, // Rs 250.00 partial refund
        reason: 'Customer request',
      ),
      options: const RequestOptions(idempotencyKey: 'refund_ORDER_123_1'),
    );
    print('Refund ID: ${refund.data.refundId}');
  } on ApiError catch (e) {
    print('Refund failed: ${e.message}');
  }
}
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