jtmuller5 / strike

A pure dart SDK wrapper for the Strike API

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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.

Support

Buy Me A Coffee

Keep My Lights On

❤️ Sponsor on GitHub

Roadmap

  • Find user profiles by handle
  • Find user profiles by ID
  • Issue basic invoice
  • Issue invoice to specific receiver
  • Find invoice by ID
  • Issue quote for invoice
  • Cancel unpaid invoice
  • Get currency exchange rates
  • Open Strike App from Invoice (mobile)
  • Open Strike App from Quote (mobile)
  • Open Strike App from Invoice (web)
  • Open Strike App from Quote (web)
  • Get webhook events
  • Find webhook events by ID
  • Get webhook subscriptions
  • Create new webhook subscriptions
  • Find webhook subscription by ID
  • Update webhook subscription
  • Delete webhook subscription

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.

  1. Add flutter_dotenv to your pubspec.yaml
  2. Add *.env to your project's .gitignore file
  3. Create a .env file in the root of your project and add the following contents
STRIKE_API_KEY=<YOUR_API_KEY>
  1. 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:

  1. User opens the link
  2. User see's the invoice's description and amount
  3. User presses "Pay"
  4. 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).

Invoice to Quote

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'));
  },
),

At the moment, the Strike browser extension cannot be opened by using launchUrl(). Instead, you will need to use the Link widget from the url_launcher package.

Link(
    target: LinkTarget.blank,
    uri: Uri.parse('lightning:<LNINVOICE>'),
    builder: (context, onTap) {
      return ElevatedButton(
        onPressed: onTap,
        child: const Text('Send'),
      );
    },
  );

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.

Relevant Issues

About

A pure dart SDK wrapper for the Strike API

License:MIT License


Languages

Language:Dart 59.1%Language:C++ 23.0%Language:CMake 10.8%Language:HTML 5.3%Language:C 1.0%Language:Swift 0.5%Language:Kotlin 0.2%Language:Objective-C 0.1%