This package is a pure Dart SDK wrapper for the Strike APIs (offical docs).
Strike APIs enable you to accept payments securely and integrate your app with Strike.
Roadmap
x
Find user profiles by handlex
Find user profiles by IDx
Issue basic invoicex
Issue invoice to specific receiverx
Find invoice by IDx
Issue quote for invoicex
Cancel unpaid invoicex
Get currency exchange rates
Getting started
In order to use the Strike API, you will need to request an API key.
Secure your API Key
You can use the flutter_dotenv package to keep your API key safely out of public repositories.
- Add flutter_dotenv to your pubspec.yaml
- Add *.env to your project's .gitignore file
- Create a .env file in the root of your project and add the following contents
STRIKE_API_KEY=<YOUR_API_KEY>
- Add the .env file to the assets section of your pubspec.yaml and run flutter pub get
assets:
- .env
Usage
Create your Strike instance.
Without flutter_dotenv:
Strike _strike = Strike(apiKey: '<YOUR_API_KEY>');
With flutter_dotenv:
await dotenv.load(fileName: '.env');
Strike _strike = Strike(apiKey:dotenv.env['STRIKE_API_KEY']!);
Issue an Invoice
The only thing required to issue an invoice is an InvoiceAmount (which includes the quantity and type of currency being requested). All other fields are optional.
Both of the following methods will return the generated Invoice.
Issue an Invoice for Yourself
await strike.issueInvoice(
handle: null,
correlationId: null,
description: null,
invoiceAmount: InvoiceAmount(
amount: 10,
currency: CurrencyType.USD,
),
);
When you issue an invoice without specifying a receiver, the invoice is created with your own personal Strike ID as both the "Issuer" and the "Receiver". In other words, when this invoice is paid, you receive the funds.
Issue an Invoice for Someone Else
await strike.issueInvoice(
handle: '<RECEIVER_HANDLE>',
correlationId: null,
description: "Nice work!",
invoiceAmount: InvoiceAmount(
amount: 1,
currency: CurrencyType.BTC,
),
);
Open an Invoice in Strike
The Strike mobile app accepts deep links of the following format: https://strike.me/pay/<INVOICE_ID>
Below is the workflow for using the link:
- User opens the link
- User see's the invoice's description and amount
- User presses "Pay"
- The Strike app generates a QR code for the invoice
This package depends on url_launcher. Each Invoice has an openStrikeApp() method that will open the appropriate deep link.
OutlinedButton(
child: const Text('Open Strike App'),
onPressed: () {
invoice?.openStrikeApp(); // launchUrl(Uri.parse('https://strike.me/pay/$invoiceId'));
},
),
If you'd rather have the Strike app handle the QR code generation, you can ignore the "Issue a Quote" section below.
Cancel an Unpaid Invoice
Invoice? cancelledInvoice = await strike.cancelUnpaidInvoice(invoiceId: invoice?.invoiceId);
This endpoint will respond with a 422 error code if the Invoice is already cancelled.
Issue a Quote
Once you have an Invoice, you can generate a quote for it (source).
strike.issueQuoteForInvoice(invoiceId: invoice.invoiceId)
Open a Quote in Strike
The URL scheme for lightning payments is "lightning:<LIGHTNING_INVOICE>"
All apps that can accept lightning payment requests can be opened with this URL scheme.
OutlinedButton(
child: const Text('Open Strike'),
onPressed: () {
quote.openStrikeApp(); // launchUrl(Uri.parse('lightning:$lnInvoice'));
},
),
Generate a QR Code for the Quote
Each Quote contains an "lnInvoice" field which is the encoded lightning invoice. Using the qr_flutter package you can easily turn that field into a QR Code your users can scan.
if(quote.lnInvoice != null) {
return QrImage(
data: quote.lnInvoice!,
version: QrVersions.auto,
size: 200.0,
);
}
Note that the generated QR code must be scanned from inside the Strike app. If you scan it outside of the app, it simply opens your note app with the QR contents.