Skip to main content

Profiles & Order Fraud (Flutter)

The SimplrProfiles class provides anonymous user profile management and real-time order fraud scoring for Flutter apps.

Setup

import 'package:simplr_fraud/simplr_fraud.dart';

final profiles = SimplrProfiles(
config: SimplrProfilesConfig(apiKey: 'pk_live_xxxxx'),
);

Identify a User

Call identify() when a user signs up or logs in. This creates an anonymous profile and links the current device.

final result = await profiles.identify(
'user-abc-123',
profileType: 'customer', // 'customer', 'cashier', 'employee'
);

print(result.isNew); // true if first time
print(result.deviceLinked); // true if device was attached
print(result.riskScore); // current risk score

Device fingerprints are automatically collected via DeviceInfoCollector.

Submit an Order

final result = await profiles.submitOrder(OrderInput(
externalOrderId: 'ORD-2026-001',
externalId: 'user-abc-123',
amountCents: 15999,
currency: 'ZAR',
orderType: 'online',
paymentMethod: 'card',
locationLatitude: -33.92,
locationLongitude: 18.42,
));

// Use the risk assessment
print(result.riskScore); // 0-100
print(result.riskLevel); // 'low', 'medium', 'high', 'critical'
print(result.flags); // ['high_velocity', ...]
print(result.flaggedForReview); // true if score >= 50

if (result.riskLevel == 'critical') {
blockOrder();
} else if (result.riskLevel == 'high') {
holdForReview();
} else {
approveOrder();
}

Get Profile Risk

final risk = await profiles.getProfileRisk('user-abc-123');

print(risk.riskScore);
print(risk.signals); // Map<String, double>
print(risk.totalOrders);
print(risk.deviceCount);

Report Fraud / Mark Legitimate

// Flag a profile for investigation
await profiles.reportOutcome('user-abc-123', 'fraud');

// Clear a profile after investigation
await profiles.reportOutcome('user-abc-123', 'legitimate');

POS Integration Example

For a Flutter-based POS app:

final profiles = SimplrProfiles(
config: SimplrProfilesConfig(apiKey: 'pk_live_xxxxx'),
);

// Register cashier at shift start
await profiles.identify('cashier-jane', profileType: 'cashier');

// Process an order
Future<void> processOrder(double amount, String? customerLoyaltyId) async {
final result = await profiles.submitOrder(OrderInput(
externalOrderId: 'POS-${DateTime.now().millisecondsSinceEpoch}',
externalId: customerLoyaltyId, // null if unknown customer
amountCents: (amount * 100).toInt(),
orderType: 'in_store',
paymentMethod: 'card',
edgeDeviceId: 'pos-terminal-42',
cashierExternalId: 'cashier-jane',
));

if (result.riskLevel == 'high' || result.riskLevel == 'critical') {
// Show alert to store manager
showManagerAlert(result);
}
}

Cleanup

Dispose of the HTTP client when done:

profiles.dispose();