stripe_js 2.0.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 81

stripe_js

Experimental package:js bindings for Stripe

Example

<form action="/charge" method="post" id="payment-form">
    <div class="form-row">
        <label for="card-element">
            Credit or debit card
        </label>
        <div id="card-element">
            <!-- a Stripe Element will be inserted here. -->
        </div>

        <!-- Used to display form errors -->
        <div id="card-errors" role="alert"></div>
    </div>

    <button>Submit Payment</button>
</form>
import 'dart:js';
import 'package:js/js.dart';
import 'package:stripe_js/stripe_js.dart';
import 'dart:html';

main() {
// Create a Stripe client
  var stripe = Stripe('STRIPE_TOKEN');

// Create an instance of Elements
  var elements = stripe.elements();

// Custom styling can be passed to options when creating an Element.
// (Note that this demo uses a wider set of styles than the guide below.)
  var style = {
    "base": {
      "color": '#32325d',
      "lineHeight": '18px',
      "fontFamily": '"Helvetica Neue", Helvetica, sans-serif',
      "fontSmoothing": 'antialiased',
      "fontSize": '16px',
      '::placeholder': {"color": '#aab7c4'}
    },
    "invalid": {"color": '#fa755a', "iconColor": '#fa755a'}
  };

// Create an instance of the card Element
  var card = elements.create('card', new ElementsOptions(classes: style));

// Add an instance of the card Element into the `card-element` <div>
  card.mount('#card-element');

// Handle real-time validation errors from the card Element.
  card.on(
    'change',
    allowInterop(([event]) {
      var displayError = document.getElementById('card-errors');
      if (event.error != null) {
        displayError.text = event.error.message;
      } else {
        displayError.text = '';
      }
    }),
  );

// Handle form submission
  var form = document.getElementById('payment-form');
  form.addEventListener(
    'submit',
    allowInterop((event) {
      event.preventDefault();
      stripe.createToken(card).then(
        allowInterop((result) {
          if (result.error != null) {
            // Inform the user if there was an error
            var errorElement = document.getElementById('card-errors');
            errorElement.text = result.error.message;
          } else {
            // Send the token to your server
            print("got token: ${result.token.id}");
          }
        }),
      );
    }),
  );
}

Generating the library

dart_js_facade_gen lib/src/stripe.d.ts > lib/stripe_js.dart
dart_js_facade_gen lib/src/promise.d.ts > lib/src/promise.dart

Changelog

2.0.0

BREAKING: Make compatible with Dart 2. Dart 1 users should user version ^1.0.0

0.0.1

  • Initial version, created by Stagehand

example/main.dart

import 'dart:js';
import 'package:js/js.dart';
import 'package:stripe_js/stripe_js.dart';
import 'dart:html';

main() {
// Create a Stripe client
  var stripe = Stripe('STRIPE_TOKEN');

// Create an instance of Elements
  var elements = stripe.elements();

// Custom styling can be passed to options when creating an Element.
// (Note that this demo uses a wider set of styles than the guide below.)
  var style = {
    "base": {
      "color": '#32325d',
      "lineHeight": '18px',
      "fontFamily": '"Helvetica Neue", Helvetica, sans-serif',
      "fontSmoothing": 'antialiased',
      "fontSize": '16px',
      '::placeholder': {"color": '#aab7c4'}
    },
    "invalid": {"color": '#fa755a', "iconColor": '#fa755a'}
  };

// Create an instance of the card Element
  var card = elements.create('card', new ElementsOptions(classes: style));

// Add an instance of the card Element into the `card-element` <div>
  card.mount('#card-element');

// Handle real-time validation errors from the card Element.
  card.on(
    'change',
    allowInterop(([event]) {
      var displayError = document.getElementById('card-errors');
      if (event.error != null) {
        displayError.text = event.error.message;
      } else {
        displayError.text = '';
      }
    }),
  );

// Handle form submission
  var form = document.getElementById('payment-form');
  form.addEventListener(
    'submit',
    allowInterop((event) {
      event.preventDefault();
      stripe.createToken(card).then(
        allowInterop((result) {
          if (result.error != null) {
            // Inform the user if there was an error
            var errorElement = document.getElementById('card-errors');
            errorElement.text = result.error.message;
          } else {
            // Send the token to your server
            print("got token: ${result.token.id}");
          }
        }),
      );
    }),
  );
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  stripe_js: ^2.0.0

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:stripe_js/stripe_js.dart';
  
Version Uploaded Documentation Archive
2.0.0 Nov 16, 2018 Go to the documentation of stripe_js 2.0.0 Download stripe_js 2.0.0 archive
1.0.0 Feb 5, 2018 Go to the documentation of stripe_js 1.0.0 Download stripe_js 1.0.0 archive
0.0.1 Feb 2, 2018 Go to the documentation of stripe_js 0.0.1 Download stripe_js 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
77
Health:
Code health derived from static analysis. [more]
89
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
80
Overall:
Weighted score of the above. [more]
81
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7

Platforms

Detected platforms: web, other

Primary library: package:stripe_js/stripe_js.dart with components: js.

Health issues and suggestions

Document public APIs (-9.85 points)

258 out of 262 API elements (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

Fix lib/stripe_js.dart. (-1 points)

Analysis of lib/stripe_js.dart reported 2 hints:

line 26 col 16: Name types using UpperCamelCase.

line 481 col 14: Name types using UpperCamelCase.

Format lib/src/promise.dart.

Run dartfmt to format lib/src/promise.dart.

Maintenance suggestions

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=1.20.1 <3.0.0
js ^0.6.1 0.6.1+1
Dev dependencies
test ^1.0.0