Skip to content
Unofficial ChartMogul API Dart Client
Dart
Branch: master
Clone or download

Latest commit

Fetching latest commit…
Cannot retrieve the latest commit at this time.

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
test
.gitignore
CHANGELOG.md
LICENSE.txt
README.md
analysis_options.yaml
build.yaml
pubspec.yaml

README.md

Unofficial ChartMogul API Dart Client

chartmogul-dart provides convenient Dart bindings for ChartMogul's API.


Table of Contents


Configuration

To get started, you need to instantiate a ChartMogul client using your credentials. Find them on the ChartMogul API Credentials page.

final ChartMogul chartmogul = ChartMogul(accountToken: 'YOUR_TOKEN', secretKey: 'YOUR_KEY');

You can use the ping service to test everything is working:

await chartmogul.ping.authenticateCredentials();
print('If you can see this, everything worked!');

If there are no exceptions then you're good to go.

Usage

Import API

Available methods in Import API:

Data Sources

chartMogul.dataSources.create('In-house billing');
chartMogul.dataSources.get('ds_5915ee5a-babd-406b-b8ce-d207133fb4cb');
chartMogul.dataSources.list();
chartMogul.dataSources.delete('ds_5915ee5a-babd-406b-b8ce-d207133fb4cb');

Customers

chartMogul.customers.create(
  externalId: 'cus_0001',
  name: 'Adam Smith',
  dataSourceUuid: 'ds_fef05d54-47b4-431b-aed2-eb6b9e545430',
  email: 'adam@smith.com',
  address: const Address(city: 'New York', country: 'US'),
  leadCreatedAt: DateTime.parse('2015-10-14T00:00:00Z'),
  freeTrialStartedAt: DateTime.now(),
  customAttributes: <CustomAttribute>[
    CustomAttribute(key: 'channel', value: 'Facebook', source: 'Integration'),
    CustomAttribute(key: 'age', value: 18),
  ],
  tags: <String>['important', 'Prio1'],
);

chartMogul.customers.update(
  uuid: 'cus_5915ee5a-babd-406b-b8ce-d207133fb4cb',
  address: const Address(
    city: 'San Francisco',
    country: 'US',
    state: 'CA',
  ),
  leadCreatedAt: DateTime.parse('2015-01-01 00:00:00'),
  freeTrialStartedAt: DateTime.parse('2015-06-13 15:45:13'),
  customerAttributes: CustomerAttributes(
    tags: <String>['high-value'],
    custom: <String, dynamic>{
      'CAC': 25,
      'channel': <String, dynamic>{
        'value': 'Twitter',
        'source': 'integration2',
      },
    },
  ),
);

chartMogul.customers.list(page: 2, perPage: 20);
chartMogul.customers.get('cus_5915ee5a-babd-406b-b8ce-d207133fb4cb');
chartMogul.customers.delete('cus_5915ee5a-babd-406b-b8ce-d207133fb4cb');

Plans

chartMogul.plans.create(
  externalId: 'plan_0001',
  name: 'Bronze Plan',
  dataSourceUuid: 'ds_fef05d54-47b4-431b-aed2-eb6b9e545430',
  intervalCount: 1,
  intervalUnit: 'month',
);

chartMogul.plans.update(
  uuid: 'pl_eed05d54-75b4-431b-adb2-eb6b9e543206',
  name: 'Bronze Monthly Plan',
  intervalCount: 1,
  intervalUnit: 'month',
);

chartMogul.plans.list(page: 2, perPage: 20);
chartMogul.plans.get('pl_eed05d54-75b4-431b-adb2-eb6b9e543206');
chartMogul.plans.delete('pl_eed05d54-75b4-431b-adb2-eb6b9e543206');

Invoices

final List<Invoice> invoices = <Invoice>[
  Invoice(
    externalId: 'INV0001',
    currency: 'USD',
    date: DateTime.parse('2015-11-01 00:00:00'),
    dueDate: DateTime.parse('2015-11-15 00:00:00'),
    lineItems: <LineItem>[
      LineItem(
        type: LineItemType.subscription,
        subscriptionExternalId: 'sub_0001',
        subscriptionSetExternalId: 'set_0001',
        planUuid: 'pl_eed05d54-75b4-431b-adb2-eb6b9e543206',
        servicePeriodStart: DateTime.parse('2015-11-01 00:00:00'),
        servicePeriodEnd: DateTime.parse('2015-12-01 00:00:00'),
        amountInCents: 5000,
        quantity: 1,
        discountCode: 'PSO86',
        discountAmountInCents: 1000,
        taxAmountInCents: 900,
        transactionFeesInCents: 200,
      ),
      const LineItem(
        type: LineItemType.one_time,
        description: 'Setup Fees',
        amountInCents: 2500,
        quantity: 1,
        discountCode: 'PSO86',
        discountAmountInCents: 500,
        taxAmountInCents: 450,
      )
    ],
    transactions: <Transaction>[
      Transaction(
        date: DateTime.parse('2015-11-05 00:14:23'),
        type: TransactionType.payment,
        result: TransactionResult.successful,
      )
    ],
  ),
];

chartMogul.invoices.import(
    customerUuid: 'cus_5915ee5a-babd-406b-b8ce-d207133fb4cb',
    invoices: invoices,
  );
chartMogul.invoices.list(page: 2, perPage: 20);
chartMogul.invoices.listForCustomer(
  customerUuid: 'cus_5915ee5a-babd-406b-b8ce-d207133fb4cb',
  page: 2,
  perPage: 20,
);
chartMogul.invoices.get('inv_ee325d54-7ab4-421b-cdb2-eb6b9e546034');
chartMogul.invoices.delete('inv_ee325d54-7ab4-421b-cdb2-eb6b9e546034');

Transactions

chartMogul.transactions.import(
  invoiceUuid: 'inv_ee325d54-7ab4-421b-cdb2-eb6b9e546034',
  date: DateTime.now(),
  type: TransactionType.payment,
  result: TransactionResult.successful,
);

Subscriptions

chartMogul.subscriptions.list(
  customerUuid: 'cus_f466e33d-ff2b-4a11-8f85-417eb02157a7',
  perPage: 2,
  page: 3,
);

chartMogul.subscriptions.cancel(
  uuid: 'sub_e6bc5407-e258-4de0-bb43-61faaf062035',
  cancelledAt: DateTime.now(),
);

chartMogul.subscriptions.cancel(
  uuid: 'sub_e6bc5407-e258-4de0-bb43-61faaf062035',
  cancellationDates: <DateTime>[
    DateTime.now(),
    DateTime.fromMillisecondsSinceEpoch(1576513420)
  ],
);

Development

To work on the library:

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Install dependencies: pub get
  • Fix bugs or add features, making sure the changes pass the linter (use dartanalyzer)
  • Write tests for your new features, using mockito for HTTP mocking
  • Run tests with pub run test
  • If all tests are passed, push to the branch (git push origin my-new-feature)
  • Create a new Pull Request

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/benbarbersmith/chartmogul-dart.

License

The library is available as open source under the terms of the MIT License.

The MIT License (MIT)

Copyright (c) 2019 Benjamin Barbersmith

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

You can’t perform that action at this time.