WayaQuick — Flutter merchant app SDK
Headless Dart client that works with Riverpod, Bloc, GetX or setState.
- Flutter · Dart
dependencies:
waya_pay_core:
path: ../packages/waya_pay_core # or the published version once availablewaya_pay_core is a headless Dart/Flutter client for the WayaPay merchant API. No UI, no state-management opinion — plain Futures that throw typed exceptions, so it drops into any app regardless of whether it uses Riverpod, Bloc, GetX, or plain setState.
#Requirements
Flutter 3.24 or later, Dart 3.9 or later.
#Install
dependencies:
waya_pay_core:
path: ../packages/waya_pay_core # or the published version once available#Initialize
Call this once, before runApp():
import 'package:waya_pay_core/waya_pay_core.dart';
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await WayaPaySdk.initialize(
environment: Environment.staging, // or Environment.prod
clientId: 'YOUR_APP_NAME', // identifies the calling app to the backend
);
runApp(const MyApp());
}From anywhere in your app, WayaPaySdk.instance.auth, .wallet, .invoices, .paymentLinks, .virtualAccounts, .disputes, .customers, and .kyc are ready to use. Calling WayaPaySdk.instance before initialize() finishes throws WayaPaySdkNotInitializedException — check WayaPaySdk.isInitialized first if you need to guard against that.
#Authenticate
final session = await WayaPaySdk.instance.auth.login(
identifier: 'merchant@example.com', // email, phone, or Business ID — same field, backend infers which
password: 'secret',
);New accounts are a three-step flow — signup() does not start a session:
final challenge = await WayaPaySdk.instance.auth.signup(SignupRequest(
firstName: 'Ada', surname: 'Obi', email: 'ada@example.com',
organizationName: 'Obi Foods', password: 'secret', phoneNumber: '08012345678',
));
await WayaPaySdk.instance.auth.verifyOtp(identifier: challenge.email!, otpCode: '123456');
final session = await WayaPaySdk.instance.auth.login(identifier: 'ada@example.com', password: 'secret');If the account has 2FA, login() throws WayaPayLoginOtpRequiredException on the first attempt (credentials were fine, but an OTP is required) — call auth.resendLoginOtp(identifier: ...) if the merchant needs a new code, then call login() again with otpCode set.
Once logged in, the session is implicit — no method anywhere takes a merchantId. Call auth.logout() to clear it (this clears local token storage; the backend invalidates tokens on their own natural expiry).
Password reset, for a merchant who's locked out:
await WayaPaySdk.instance.auth.forgotPassword(phoneNumber: '08012345678', businessId: businessId);
await WayaPaySdk.instance.auth.resetPassword(
identifier: email, businessId: businessId, otpCode: 123456, newPassword: 'new-secret',
);#Handle errors
Every failure — a bad request, an expired session, no connectivity, a backend outage — comes back as one of a small, fixed set of typed exceptions. Structure your error handling as one switch:
try {
await WayaPaySdk.instance.wallet.withdraw(request);
} on WayaPayValidationException catch (e) {
// e.message — show it next to the form. e.code if the backend sent one.
} on WayaPaySessionExpiredException {
// route to login — token refresh already failed
} on WayaPayNetworkException {
// no connectivity / timeout — show "check your connection" + retry
} on WayaPayServerException catch (e) {
// 5xx — show a generic error. e.statusCode for diagnostics.
} on WayaPayException catch (e) {
// catch-all — e.message is always populated
}Register onSessionExpired once at startup instead of catching WayaPaySessionExpiredException everywhere just to redirect:
await WayaPaySdk.initialize(
environment: Environment.staging,
clientId: 'MY_APP',
onSessionExpired: () async {
navigatorKey.currentState?.pushNamedAndRemoveUntil('/login', (_) => false);
},
);This fires only when a refresh attempt is genuinely rejected by the backend. A dropped connection during a refresh attempt surfaces as WayaPayNetworkException on that one call instead — it does not sign the merchant out, since a network blip isn't the same thing as an invalid session.
#Wallet
final balance = await sdk.wallet.balance(); // .balance, .totalWithdrawn
final page = await sdk.wallet.transactions(page: 0, size: 20);
await sdk.wallet.withdraw(WithdrawalRequest(
accountName: 'Ada Obi', accountNumber: '0123456789',
bankCode: '058', bankName: 'GTBank',
amount: '50000', transactionPin: '1234', // the merchant's WayaPay PIN, not their login password
));
final history = await sdk.wallet.withdrawalHistory(); // plain List, no reliable backend total#Getting paid — three ways, one wallet
All three land in the same wallet balance; which to use depends on the moment.
Invoices — itemized, for a specific job. They need a payment link first (the backend ties every invoice to one):
final link = await sdk.paymentLinks.create(CreatePaymentLinkRequest(
paymentLinkName: 'Website deposit', description: 'Design deposit',
successMessage: 'Thank you!', redirectLink: 'https://obi-foods.example.com',
payableAmount: '45000', paymentLinkType: PaymentLinkType.oneTime, otherDetailsJSON: '{}',
));
final invoice = await sdk.invoices.create(CreateInvoiceRequest(
businessSlogan: 'Great food', invoiceDate: '2026-07-30', paymentDueDate: '2026-08-15',
paymentLinkId: link.paymentLinkId!,
itemsList: [const InvoiceItem(description: 'Catering', unitPrice: 45000, quantity: 1)],
accountNumber: '0123456789', bankName: 'GTBank',
email: 'ada@wayapay.ng', name: 'Obi Foods', phoneNumber: '08012345678',
));Payment links — generic and reusable, share link.customerPaymentLink anywhere (WhatsApp, SMS).
Virtual accounts — a dedicated account number for recurring/top-up-style collection:
await sdk.virtualAccounts.createStaticAccount(); // provisions asynchronously
final wallets = await sdk.virtualAccounts.wallets(); // fetch the account once readyThere's no webhook for "payment received" — poll invoices.getByNumber, paymentLinks.list, or wallet.balance to detect it, or rely on push notifications your own backend already sends.
#Customers
Used as a buyer/recipient picker when creating invoices and payment links.
final customer = await sdk.customers.create(const CreateCustomerRequest(
firstName: 'Ada', lastName: 'Obi',
email: 'ada@example.com', phoneNumber: '+2348012345678',
));
final page = await sdk.customers.list(search: 'ada');
await sdk.customers.setAvoidance(customer.customerId!, true); // block this customer from future paymentsemail and phoneNumber are required here even though the backend's own schema marks them optional — omitting either throws an unhandled server error instead of a clean validation message, so the SDK requires both up front to make that mistake impossible.
#Disputes
await sdk.disputes.create(CreateDisputeRequest(
disputeType: 'CHARGEBACK', // one of CHARGEBACK, AUTHCOMPLAINT, FRAUD, OTHERS
reasonForDisputeInDetails: 'I did not authorize this.',
disputeAmount: 25000, transactionCharge: 0, transactionDate: '2026-07-30',
));
final myDisputes = await sdk.disputes.list();#Business KYC — the "can this merchant transact?" gate
Nothing money-related works until this is approved. Gate your app's navigation on kyc.status().approvalStatus == ApprovalStatus.approved, not just on being logged in.
The real flow is three steps — business details, then directors/shareholders, then certificates — plus a separate BVN verification. Each step can be saved as a draft repeatedly and submitted independently:
final status = await sdk.kyc.status();
// status.approvalStatus, plus status.businessStepStatus / .directorStepStatus / .certificatesStepStatus
if (status.approvalStatus?.requiresAttention ?? true) {
final industries = await sdk.kyc.industries(); // lookup list for businessIndustry
final logo = await sdk.kyc.uploadDocument(bytes: logoBytes, fileName: 'logo.png');
await sdk.kyc.saveBusinessStep(BusinessStepRequest(
businessName: 'Obi Foods',
businessType: KycBusinessType.registered,
businessRegistrationType: KycRegistrationType.incorporatedCompany,
businessLogoUrl: logo.url,
), submit: true);
await sdk.kyc.saveDirectorStep([
const DirectorInput(firstName: 'Ada', lastName: 'Obi', ninNumber: 12345678901, bvnNumber: 22152763963),
], submit: true);
final certUrl = await sdk.kyc.uploadDocument(bytes: certBytes, fileName: 'cac.jpg');
await sdk.kyc.saveCertificatesStep(CertificatesStepRequest(
incorporationCertificateUrl: certUrl.url, tin: '123456789',
), submit: true);
await sdk.kyc.finalSubmit();
// ...poll status() until approvalStatus is approved or rejected
}submit: true marks that individual step as submitted for review instead of leaving it a draft — mirrors a real form's per-step "Save" vs "Submit". finalSubmit() only makes sense once all three steps are complete, and moves the overall record from draft/submitted to pending review.
BVN verification is a separate two-call flow:
final otpTarget = await sdk.kyc.verifyBvn('22152763963'); // sends an OTP, may return a masked phone
await sdk.kyc.verifyBvnOtp(otp: '123456', phoneNumber: otpTarget['phoneNumber'] as String? ?? '08012345678');A simpler, legacy single-call draft/submit pair (kyc.saveDraft() / kyc.submit()) still exists for integrations that don't need the step-by-step UX, but it doesn't drive the per-step statuses above — prefer the three step methods for anything matching a real onboarding experience.
#Pagination
The backend uses three different pagination shapes across its endpoints; every list method in this SDK normalizes to the same PagedResult<T> (items, page, pageSize, total, hasMore) regardless of which shape is underneath — you never need to special-case an endpoint.
#Session expiry, offline, and retries
Token refresh is fully transparent: a 401 on an authenticated call triggers one refresh attempt (shared across concurrent requests if several calls 401 at once) and a silent retry. You only ever see WayaPaySessionExpiredException if the refresh token itself was rejected.
#Logging
Request/response traffic prints via package:logger in debug builds only — it's structurally impossible for it to fire in a release build, regardless of configuration. Headers are never logged (every authenticated request carries a bearer token). Password/OTP/API-secret-key body fields are redacted (***) at any nesting depth in both request and response bodies.
await WayaPaySdk.initialize(
environment: Environment.staging,
clientId: 'MY_APP',
enableLogging: kDebugMode, // this is already the default — pass false for quiet debug builds too
);#Testing code that uses this SDK
The domain clients (WayaPayAuth, WayaPayWallet, etc.) aren't singletons and don't depend on WayaPaySdk — construct them directly in a test with a fake TokenStorage and a client wired to http_mock_adapter.
#Configuration reference
await WayaPaySdk.initialize(
environment: Environment.staging, // or Environment.prod — required
clientId: 'MY_APP', // required, identifies the calling app
clientType: 'CORPORATE', // default
tokenStorage: MyTokenStorage(), // optional, defaults to SecureTokenStorage (flutter_secure_storage)
onSessionExpired: () async { ... }, // optional
enableLogging: kDebugMode, // optional
connectTimeout: Duration(seconds: 30), // optional
receiveTimeout: Duration(seconds: 30), // optional
sendTimeout: Duration(seconds: 30), // optional
);#Good to know
A few places where the backend's documented contract diverges from what actually happens, worth knowing before you hit them yourself:
disputeType only accepts four real values: CHARGEBACK, AUTHCOMPLAINT, FRAUD, OTHERS — anything else is rejected.
Virtual accounts come in more than one shape. A MAIN wallet has a real bank accountNumber; a COLLECTION wallet only has a walletNumber instead. Use whichever field is present rather than assuming accountNumber is always populated.