chartmogul

package module
v3.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 19, 2023 License: MIT Imports: 10 Imported by: 2

README

Official ChartMogul API Go Client

chartmogul-go provides convenient Golang bindings for ChartMogul's API.

Build Status


Installation | Configuration | Usage | Development | Contributing | License



Go Reference Go Report Card

Installation

This library requires Go 1.11 or above.

go get github.com/chartmogul/chartmogul-go/v3

Configuration

[Deprecation] - account_token/secret_key combo is deprecated. Please use API key for both fields. Version 3.x will introduce a breaking change in authentication configuration. For more details, please visit: https://dev.chartmogul.com

First create the API struct by passing your API key, available from the administration section of your ChartMogul account.

import cm "github.com/chartmogul/chartmogul-go/v3"

api := cm.API{
    ApiKey: os.Getenv("CHARTMOGUL_API_KEY"),
}

// Try authentication
ok, err := api.Ping()
if err != nil {
    fmt.Printf("This didn't work out: %v", err)
}

This struct has all the methods you can use to interact with ChartMogul.

HTTP 2

ChartMogul's current stable version of nginx is incompatible with HTTP 2 implementation of Go as of 1.7.3. For this reason the application must run with the following (or otherwise prohibit HTTP 2):

export GODEBUG=http2client=0

Usage

Rate Limits

The library retries on HTTP 429 (rate limit reached), so that you don't have to manually handle rate limiting. See: ChartMogul: Rate Limits & BackOff constants. Exponential back-off algorithm is used. It also automatically retries on network errors, eg. when the server can't be reached.

The API calls will retry automatically and block (several minutes), therefore it's still advisable to only use reasonable parallelism. In case it keeps failing after maximum retry period, it will return the HTTP 429 error.

Note: the Ping doesn't retry.

Import API

Available methods in Import API:

Data Sources
api.CreateDataSource("name")
api.ListDataSources()
api.RetrieveDataSource("uuid")
api.DeleteDataSource("uuid")
Customers
api.CreateCustomer(&cm.NewCustomer{})
api.RetrieveCustomer("customerUUID")
api.SearchCustomers(&cm.SearchCustomersParams{})
api.ListCustomers(&cm.ListCustomersParams{})
api.UpdateCustomer(&cm.NewCustomer{}, "customerUUID")
api.MergeCustomers(&cm.MergeCustomersParams{})
api.ConnectSubscriptions("customerUUID", []cm.Subscription{})
api.ListCustomersContact(&cm.ListContactsParams{}, "customerUUID")
api.CreateCustomersContact(&cm.NewContact{}, "customerUUID")
Contacts
api.CreateContact(&cm.NewContact{})
api.RetrieveContact("customerUUID")
api.ListContacts(&cm.ListContactsParams{})
api.UpdateContact(&cm.UpdateContact{}, "contact")
api.DeleteContact("customerUUID")
api.MergeContacts("intoContactUUID", "fromContactUUID")
Plans
api.CreatePlan(&cm.Plan{Name: "name", ExternalID: "external_id"}, "dataSourceUUID")
api.RetrievePlan("planUUID")
api.ListPlans(&cm.ListPlansParams{Cursor: cm.Cursor{Page: "1", PerPage: "10"}})
api.UpdatePlan(&cm.Plan{}, "planUUID")
api.DeletePlan("planUUID")
Plan Groups
api.CreatePlanGroup(&cm.PlanGroup{Name: "name", Plans: []*string{&planOne.UUID, &planTwo.UUID}})
api.RetrievePlanGroup("planGroupUUID")
api.ListPlanGroups(&cm.ListPlansParams{Cursor: cm.Cursor{Page: "1", PerPage: "10"}})
api.UpdatePlanGroup(&cm.PlanGroup{}, "planGroupUUID")
api.DeletePlanGroup("planGroupUUID")
api.ListPlanGroupPlans(&cm.ListPlansParams{Cursor: cm.Cursor{Page: "1", PerPage: "10"}},  "planGroupUUID")
Invoices
api.CreateInvoices([]*cm.Invoice{*cm.Invoice{}}, "customerUUID")
api.ListInvoices(&cm.Cursor{}, "customerUUID")
api.ListAllInvoices(&cm.ListAllInvoicesParams{})
api.RetrieveInvoice("invoiceUUID")
api.DeleteInvoice("invoiceUUID")
Transactions
api.CreateTransaction(&cm.Transaction{}, "invoiceUUID")
Subscriptions
api.CancelSubscription("subscriptionUUID", &cm.CancelSubscriptionParams{CancelledAt: "2005-01-01T01:02:03.000Z"})
api.CancelSubscription("subscriptionUUID", &cm.CancelSubscriptionParams{CancellationDates: []string{"2005-01-01T01:02:03.000Z", "2006-10-21T11:21:13.000Z"}})
api.ListSubscriptions(&cm.Cursor{}, "customerUUID")
Customer Attributes
api.RetrieveCustomersAttributes("customerUUID")
Tags
api.AddTagsToCustomer("customerUUID", []string{})
api.AddTagsToCustomersWithEmail("email@customer.com", []string{})
Custom Attributes
api.AddCustomAttributesToCustomer("customerUUID", []*cm.CustomAttribute{})
Subscription Events
api.ListSubscriptionEvents(filters *FilterSubscriptionEvents, cursor *MetaCursor)
api.CreateSubscriptionEvent(newSubscriptionEvent *SubscriptionEvent)
api.UpdateSubscriptionEvent(subscriptionEvent *SubscriptionEvent)
api.DeleteSubscriptionEvent(deleteParams *DeleteSubscriptionEvent)

Metrics API

Available methods in Metrics API:

api.MetricsRetrieveAll(&MetricsFilter{})
api.MetricsRetrieveMRR(&MetricsFilter{})
api.MetricsRetrieveARR(&MetricsFilter{})
api.MetricsRetrieveARPA(&MetricsFilter{})
api.MetricsRetrieveASP(&MetricsFilter{})
api.MetricsRetrieveCustomerCount(&MetricsFilter{})
api.MetricsRetrieveCustomerChurnRate(&MetricsFilter{})
api.MetricsRetrieveMRRChurnRate(&MetricsFilter{})
api.MetricsRetrieveLTV(&MetricsFilter{})

api.MetricsListCustomerSubscriptions(&Cursor{}, "customerUUID")
api.MetricsListCustomerActivities(&Cursor{}, "customerUUID")

api.MetricsListActivities(&cm.MetricsListActivitiesParams{StartDate: "2016-09-16", AnchorCursor: cm.AnchorCursor{PerPage: 5, StartAfter: "b45b1d3f-3823-424f-ab47-5a1d0c00a7f6"}})

api.MetricsCreateActivitiesExport(&cm.CreateMetricsActivitiesExportParam{StartDate: "2016-09-16",Type: "contraction"})
api.MetricsRetrieveActivitiesExport("activitiesExportUUID")

Account

Availiable methods:

api.RetrieveAccount()

Errors

The library returns parsed errors inside the structs as from the REST API, which is handy eg. when you upload multiple invoices - to know, which one had issues.

type Errors map[string]string

Non-2xx statuses and network problems will also be returned as a value error for standard binary ok/problem handling:

_, err := api.ImportListPlans(nil)
if err != nil {
    // ...
}

Such errors are HTTPError wrapped in errors with stack.

type HTTPError interface {
	StatusCode() int
	Status() string
	Response() string
}
// If you want to check specific HTTP status:
switch e := errors.Cause(err).(type) {
case cm.HTTPError:
    if e.StatusCode() == 422 {
        // special reaction
    }
}

If there are network/TLS issues it will be RequestErrors interface. This has the method Errors() []error.

For fine-grain reaction you can use the parsed errors from API in the primary return structures, when there's an Errors or Error field. You can use hepler methods to spare code on checking map contents:

  • Errors.IsAlreadyExists()
  • Errors.IsInvoiceAndTransactionAlreadyExist()

Development

To work on the library:

  • Fork it
  • Create your feature branch (git checkout -b my-new-feature)
  • Install dependencies: go install
  • Fix bugs or add features. Make sure the changes pass the Go coding standards.
  • Push to the branch (git push origin my-new-feature)
  • Create a new Pull Request
  • github.com/davecgh/go-spew/spew for debugging data (reference documentation output done using this library).
  • add pre-commit hook go test ./... (in .git/hooks/pre-commit) to have a working state always.

Testing

  • Use net/http/httptest for mocking HTTP server directly, see file generic_test.go for examples.
  • For integration_tests against real API use github.com/dnaeon/go-vcr library. Be careful to remove your API credentials from fixtures before committing! If Import API App changes, re-record the affected integration tests (by deleting fixtures).

Contributing

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

License

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

The MIT License (MIT)

Copyright (c) 2017 ChartMogul Ltd.

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.

Documentation

Overview

Package chartmogul is a simple Go API library for Chartmogul public API.

HTTP 2 ChartMogul's current stable version of nginx is incompatible with HTTP 2 implementation of Go. For this reason the application must run with the following (or otherwise prohibit HTTP 2): export GODEBUG=http2client=0

Uses the library gorequest, which allows simple struct->query, body->struct, struct->body.

Index

Constants

View Source
const (

	// AttrTypeString is one of the possible data types for custom attributes.
	AttrTypeString = "String"
	// AttrTypeInteger is one of the possible data types for custom attributes.
	AttrTypeInteger = "Integer"
	// AttrTypeTimestamp is one of the possible data types for custom attributes.
	AttrTypeTimestamp = "Timestamp"
	// AttrTypeBoolean is one of the possible data types for custom attributes.
	AttrTypeBoolean = "Boolean"
)
View Source
const (
	// ErrKeyExternalID is key in Errors map indicating there's a problem with External ID of the resource.
	ErrKeyExternalID = "external_id"
	// ErrKeyTransactionExternalID is key in Errors map indicating there's a problem with External ID of the transaction.
	ErrKeyTransactionExternalID = "transactions.external_id"
	// ErrKeyLineItemsExternalID indicates problem with one/any of line items' external IDs
	ErrKeyLineItemsExternalID = "line_items.external_id"
	// ErrKeyName - data source name
	ErrKeyName = "name"
	// ErrValCustomerExternalIDExists = can't import new customer with the same external ID
	ErrValCustomerExternalIDExists = "The external ID for this customer already exists in our system."
	// ErrValLineItemExternalIDExists = can't import invoice, b'c line item external ID exists
	ErrValLineItemExternalIDExists = "The external ID for this line item already exists in our system."
	// ErrValExternalIDExists = can't save Transaction, because it exists already.
	ErrValExternalIDExists = "has already been taken"
	// ErrValInvoiceExternalIDExists = invoice already exists
	ErrValInvoiceExternalIDExists = "The external ID for this invoice already exists in our system."
	// ErrValPlanExternalIDExists = plan already exists
	ErrValPlanExternalIDExists = "A plan with this identifier already exists in our system."
	// ErrValHasAlreadyBeenTaken = data source name taken
	ErrValHasAlreadyBeenTaken = "Has already been taken."
)

Variables

View Source
var Version = "v3"

Version of the package

Functions

func SetURL

func SetURL(specialURL string)

SetURL changes target URL for the module globally.

func Setup

func Setup(timeoutConf time.Duration)

Setup configures global timeout for the library.

Types

type API

type API struct {
	ApiKey string
	Client *http.Client
}

API is the handle for communicating with Chartmogul.

func (API) AddCustomAttributesToCustomer

func (api API) AddCustomAttributesToCustomer(customerUUID string, customAttributes []*CustomAttribute) (*CustomAttributes, error)

AddCustomAttributesToCustomer adds custom attributes to specific customer.

See https://dev.chartmogul.com/v1.0/reference#customer-attributes

func (API) AddCustomAttributesWithEmail

func (api API) AddCustomAttributesWithEmail(email string, customAttributes []*CustomAttribute) (*Customers, error)

AddCustomAttributesWithEmail adds custom attributes to customers with specific email.

See https://dev.chartmogul.com/v1.0/reference#customer-attributes

func (API) AddTagsToCustomer

func (api API) AddTagsToCustomer(customerUUID string, tags []string) (*TagsResult, error)

AddTagsToCustomer gives customer new tags.

See https://dev.chartmogul.com/v1.0/reference#tags

func (API) AddTagsToCustomersWithEmail

func (api API) AddTagsToCustomersWithEmail(email string, tags []string) (*Customers, error)

AddTagsToCustomersWithEmail gives new tags to (multiple) customers identified by e-mail only.

See https://dev.chartmogul.com/v1.0/reference#tags

func (API) CancelSubscription

func (api API) CancelSubscription(subscriptionUUID string, cancelSubscriptionParams *CancelSubscriptionParams) (*Subscription, error)

CancelSubscription creates an Import API Data Source in ChartMogul.

See https://dev.chartmogul.com/v1.0/reference#subscriptions

func (API) ConnectSubscriptions

func (api API) ConnectSubscriptions(customerUUID string, subscriptions []Subscription) error

ConnectSubscriptions connects two subscription objects

See https://dev.chartmogul.com/reference#connect-subscriptions

func (API) CreateContact added in v3.1.0

func (api API) CreateContact(newContact *NewContact) (*Contact, error)

CreateContact loads the contact to Chartmogul

See https://dev.chartmogul.com/reference/create-a-contact-contacts

func (API) CreateCustomer

func (api API) CreateCustomer(newCustomer *NewCustomer) (*Customer, error)

CreateCustomer loads the customer to Chartmogul. New endpoint - with attributes.

See https://dev.chartmogul.com/v1.0/reference#customers

func (API) CreateCustomersContact added in v3.1.0

func (api API) CreateCustomersContact(newContact *NewContact, customerUUID string) (*Contact, error)

CreateCustomersContacts

See https://dev.chartmogul.com/reference/create-a-contact

func (API) CreateDataSource

func (api API) CreateDataSource(name string) (*DataSource, error)

CreateDataSource creates an API Data Source in ChartMogul.

See https://dev.chartmogul.com/v1.0/reference#data-sources

func (API) CreateDataSourceWithSystem

func (api API) CreateDataSourceWithSystem(dataSource *DataSource) (*DataSource, error)

CreateDataSourceWithSystem creates an API Data Source in ChartMogul. * Allows other parameters than just the name.

See https://dev.chartmogul.com/v1.0/reference#data-sources

func (API) CreateInvoices

func (api API) CreateInvoices(invoices []*Invoice, customerUUID string) (*Invoices, error)

CreateInvoices loads an invoice to a customer in Chartmogul. Customer must have a valid UUID! (use return value of API)

See https://dev.chartmogul.com/v1.0/reference#invoices

func (API) CreatePlan

func (api API) CreatePlan(plan *Plan) (result *Plan, err error)

CreatePlan creates plan under given Data Source.

See https://dev.chartmogul.com/v1.0/reference#plans

func (API) CreatePlanGroup

func (api API) CreatePlanGroup(planGroup *PlanGroup) (result *PlanGroup, err error)

CreatePlanGroup creates plan group with given name and plans.

See https://dev.chartmogul.com/v1.0/reference#plan_groups

func (API) CreateSubscriptionEvent added in v3.1.0

func (api API) CreateSubscriptionEvent(newSubscriptionEvent *SubscriptionEvent) (*SubscriptionEvent, error)

func (API) CreateTransaction

func (api API) CreateTransaction(transaction *Transaction, invoiceUUID string) (*Transaction, error)

CreateTransaction loads an transaction to a customer in Chartmogul. Customer must have a valid UUID! (use return value of API)

See https://dev.chartmogul.com/v1.0/reference#transactions

func (API) DeleteContact added in v3.1.0

func (api API) DeleteContact(contactUUID string) error

DeleteContact deletes one contact by UUID.

See https://dev.chartmogul.com/reference/delete-a-contact

func (API) DeleteCustomer

func (api API) DeleteCustomer(customerUUID string) error

DeleteCustomer deletes one customer by UUID.

See https://dev.chartmogul.com/v1.0/reference#customers

func (API) DeleteCustomerInvoices

func (api API) DeleteCustomerInvoices(dataSourceUUID, customerUUID string) error

DeleteCustomerInvoices deletes all customer's invoices by UUID for given data source UUID.

See https://dev.chartmogul.com/v1.0/reference#customers

func (API) DeleteCustomerInvoicesV2

func (api API) DeleteCustomerInvoicesV2(dataSourceUUID, customerUUID string, deleteCustomerInvoicesParams *DeleteCustomerInvoicesParams) error

DeleteCustomerInvoicesV2 deletes all customer's invoices by UUID & ExternalID for given data source UUID.

See https://dev.chartmogul.com/v1.0/reference#customers

func (API) DeleteDataSource

func (api API) DeleteDataSource(uuid string) error

DeleteDataSource deletes the data source identified by its UUID.

See https://dev.chartmogul.com/v1.0/reference#data-sources

func (API) DeleteInvoice

func (api API) DeleteInvoice(invoiceUUID string) error

DeleteInvoice deletes one invoice by UUID.

See https://dev.chartmogul.com/v1.0/reference#invoices

func (API) DeletePlan

func (api API) DeletePlan(planUUID string) error

DeletePlan deletes one plan by UUID.

See https://dev.chartmogul.com/v1.0/reference#plans

func (API) DeletePlanGroup

func (api API) DeletePlanGroup(planGroupUUID string) error

DeletePlanGroup deletes one plan group by UUID.

See https://dev.chartmogul.com/v1.0/reference#plan_groups

func (API) DeleteSubscriptionEvent added in v3.1.0

func (api API) DeleteSubscriptionEvent(deleteParams *DeleteSubscriptionEvent) error

func (API) EmptyDataSource

func (api API) EmptyDataSource(dataSourceUUID string) error

EmptyDataSource deletes all the data in the data source, but keeps the UUID.

func (API) ListAllInvoices

func (api API) ListAllInvoices(listAllInvoicesParams *ListAllInvoicesParams) (*Invoices, error)

ListAllInvoices lists all imported invoices. Use parameters to narrow down the search/for paging. listAllInvoicesParams can be nil, in which case default values on API are used.

See https://dev.chartmogul.com/v1.0/reference#invoices

func (API) ListContacts added in v3.1.0

func (api API) ListContacts(listContactsParams *ListContactsParams) (*Contacts, error)

ListContacts lists all Contacts

See https://dev.chartmogul.com/reference/list-all-contacts

func (API) ListCustomers

func (api API) ListCustomers(listCustomersParams *ListCustomersParams) (*Customers, error)

ListCustomers lists all Customers for cutomer of given UUID.

See https://dev.chartmogul.com/v1.0/reference#customers

func (API) ListCustomersContacts added in v3.1.0

func (api API) ListCustomersContacts(listContactsParams *ListContactsParams, customerUUID string) (*Contacts, error)

ListCustomersContacts

See https://dev.chartmogul.com/reference/list-customers-contacts

func (API) ListDataSources

func (api API) ListDataSources() (*DataSources, error)

ListDataSources lists all available Data Sources (no paging).

See https://dev.chartmogul.com/v1.0/reference#data-sources

func (API) ListDataSourcesWithFilters

func (api API) ListDataSourcesWithFilters(listDataSourcesParams *ListDataSourcesParams) (*DataSources, error)

ListDataSourcesWithFilters lists all available Data Sources (no paging). * Allows filtering.

See https://dev.chartmogul.com/v1.0/reference#data-sources

func (API) ListInvoices

func (api API) ListInvoices(cursor *Cursor, customerUUID string) (*Invoices, error)

ListInvoices lists all imported invoices for a customer.

See https://dev.chartmogul.com/v1.0/reference#invoices

func (API) ListPlanGroupPlans

func (api API) ListPlanGroupPlans(cursor *Cursor, planGroupUUID string) (*PlanGroupPlans, error)

ListPlanGroupPlans returns list of plans in with a plan group given the plan group uuid.

See https://dev.chartmogul.com/v1.0/reference#plan_groups

func (API) ListPlanGroups

func (api API) ListPlanGroups(cursor *Cursor) (*PlanGroups, error)

ListPlanGroups returns list of plan groups.

See https://dev.chartmogul.com/v1.0/reference#plan_groups

func (API) ListPlans

func (api API) ListPlans(listPlansParams *ListPlansParams) (*Plans, error)

ListPlans returns list of plans.

See https://dev.chartmogul.com/v1.0/reference#plans

func (API) ListSubscriptionEvents added in v3.1.0

func (api API) ListSubscriptionEvents(filters *FilterSubscriptionEvents, cursor *MetaCursor) (*SubscriptionEvents, error)

func (API) ListSubscriptions

func (api API) ListSubscriptions(cursor *Cursor, customerUUID string) (*Subscriptions, error)

ListSubscriptions lists all subscriptions for cutomer of given UUID.

See https://dev.chartmogul.com/v1.0/reference#subscriptions

func (API) MergeContacts added in v3.1.0

func (api API) MergeContacts(intoContactUUID string, fromContactUUID string) (*Contact, error)

MergeContact merges two contacts.

See https://dev.chartmogul.com/reference/merge-contacts

func (API) MergeCustomers

func (api API) MergeCustomers(mergeCustomersParams *MergeCustomersParams) error

MergeCustomers merges two cutomers.

See https://dev.chartmogul.com/v1.0/reference#customers

func (API) MetricsCreateActivitiesExport

func (api API) MetricsCreateActivitiesExport(CreateMetricsActivitiesExportParam *CreateMetricsActivitiesExportParam) (*MetricsActivitiesExport, error)

MetricsCreateActivitiesExport requests creation of an activities export in Chartmogul.

See https://dev.chartmogul.com/v1.0/reference#activities_export

func (API) MetricsListActivities

func (api API) MetricsListActivities(listActivitiesParams *MetricsListActivitiesParams) (*MetricsActivities, error)

MetricsListActivities lists all activities for an account

func (API) MetricsListCustomerActivities

func (api API) MetricsListCustomerActivities(cursor *Cursor, customerUUID string) (*MetricsCustomerActivities, error)

MetricsListCustomerActivities lists all activities for cutomer of a given UUID.

See https://dev.chartmogul.com/v1.0/reference#list-customer-activities

func (API) MetricsListCustomerSubscriptions

func (api API) MetricsListCustomerSubscriptions(cursor *Cursor, customerUUID string) (*MetricsCustomerSubscriptions, error)

MetricsListCustomerSubscriptions lists all subscriptions for cutomer of a given UUID.

See https://dev.chartmogul.com/v1.0/reference#list-customer-subscriptions

func (API) MetricsRetrieveARPA

func (api API) MetricsRetrieveARPA(metricsFilter *MetricsFilter) (*ARPAResult, error)

MetricsRetrieveARPA retrieves the ARPA metrics, for the specified time period.

See https://dev.chartmogul.com/v1.0/reference#retrieve-arpa

func (API) MetricsRetrieveARR

func (api API) MetricsRetrieveARR(metricsFilter *MetricsFilter) (*ARRResult, error)

MetricsRetrieveARR retrieves the ARR metrics, for the specified time period.

See https://dev.chartmogul.com/v1.0/reference#retrieve-arr

func (API) MetricsRetrieveASP

func (api API) MetricsRetrieveASP(metricsFilter *MetricsFilter) (*ASPResult, error)

MetricsRetrieveASP retrieves the ASP metrics, for the specified time period.

See https://dev.chartmogul.com/v1.0/reference#retrieve-asp

func (API) MetricsRetrieveActivitiesExport

func (api API) MetricsRetrieveActivitiesExport(activitiesExportUUID string) (*MetricsActivitiesExport, error)

MetricsRetrieveActivitiesExport returns one activities export as in API.

See https://dev.chartmogul.com/v1.0/reference#activities_export

func (API) MetricsRetrieveAll

func (api API) MetricsRetrieveAll(metricsFilter *MetricsFilter) (*MetricsResult, error)

MetricsRetrieveAll retrieves all key metrics, for the specified time period.

See https://dev.chartmogul.com/v1.0/reference#retrieve-all-key-metrics

func (API) MetricsRetrieveCustomerChurnRate

func (api API) MetricsRetrieveCustomerChurnRate(metricsFilter *MetricsFilter) (*CustomerChurnRateResult, error)

MetricsRetrieveCustomerChurnRate retrieves customer churn rate, for the specified time period.

See https://dev.chartmogul.com/v1.0/reference#retrieve-customer-churn-rate

func (API) MetricsRetrieveCustomerCount

func (api API) MetricsRetrieveCustomerCount(metricsFilter *MetricsFilter) (*CustomerCountResult, error)

MetricsRetrieveCustomerCount retrieves customer count, for the specified time period.

See https://dev.chartmogul.com/v1.0/reference#retrieve-customer-count

func (API) MetricsRetrieveLTV

func (api API) MetricsRetrieveLTV(metricsFilter *MetricsFilter) (*LTVResult, error)

MetricsRetrieveLTV retrieves LTV metrics, for the specified time period.

See https://dev.chartmogul.com/v1.0/reference#retrieve-ltv

func (API) MetricsRetrieveMRR

func (api API) MetricsRetrieveMRR(metricsFilter *MetricsFilter) (*MRRResult, error)

MetricsRetrieveMRR retrieves the MRR metrics, for the specified time period.

See https://dev.chartmogul.com/v1.0/reference#retrieve-mrr

func (API) MetricsRetrieveMRRChurnRate

func (api API) MetricsRetrieveMRRChurnRate(metricsFilter *MetricsFilter) (*MRRChurnRateResult, error)

MetricsRetrieveMRRChurnRate retrieves all key metrics, for the specified time period.

See https://dev.chartmogul.com/v1.0/reference#retrieve-mrr-churn-rate

func (API) Ping

func (api API) Ping() (bool, error)

Ping is the authentication test endpoint. Doesn't retry on 429.

See https://dev.chartmogul.com/v1.0/docs/authentication

func (API) PurgeDataSource

func (api API) PurgeDataSource(dataSourceUUID string) error

PurgeDataSource deletes all the data except the data source itself and the customers

See https://dev.chartmogul.com/v1.0/reference#data-sources

func (API) RemoveCustomAttributes

func (api API) RemoveCustomAttributes(customerUUID string, customAttributes []string) (*CustomAttributes, error)

RemoveCustomAttributes removes a list of custom attributes from a specific customer.

See https://dev.chartmogul.com/v1.0/reference#customer-attributes

func (API) RemoveTagsFromCustomer

func (api API) RemoveTagsFromCustomer(customerUUID string, tags []string) (*TagsResult, error)

RemoveTagsFromCustomer deletes passed tags from customer of given UUID.

See https://dev.chartmogul.com/v1.0/reference#tags

func (API) RetrieveAccount

func (api API) RetrieveAccount() (*Account, error)

RetrieveAccount returns details of current account.

func (API) RetrieveContact added in v3.1.0

func (api API) RetrieveContact(contactUUID string) (*Contact, error)

RetrieveContact returns one contact as in API.

See https://dev.chartmogul.com/reference/retrieve-a-contact

func (API) RetrieveCustomer

func (api API) RetrieveCustomer(customerUUID string) (*Customer, error)

RetrieveCustomer returns one customer as in API.

See https://dev.chartmogul.com/v1.0/reference#customers

func (API) RetrieveCustomersAttributes

func (api API) RetrieveCustomersAttributes(customerUUID string) (*Attributes, error)

RetrieveCustomersAttributes returns attributes for given customer UUID.

See https://dev.chartmogul.com/v1.0/reference#customer-attributes

func (API) RetrieveDataSource

func (api API) RetrieveDataSource(dataSourceUUID string) (*DataSource, error)

RetrieveDataSource returns one Data Source by UUID.

See https://dev.chartmogul.com/v1.0/reference#data-sources

func (API) RetrieveInvoice

func (api API) RetrieveInvoice(invoiceUUID string) (*Invoice, error)

RetrieveInvoice returns one Invoice by UUID.

See https://dev.chartmogul.com/v1.0/reference#invoices

func (API) RetrievePlan

func (api API) RetrievePlan(planUUID string) (*Plan, error)

RetrievePlan returns one plan by UUID.

See https://dev.chartmogul.com/v1.0/reference#plans

func (API) RetrievePlanGroup

func (api API) RetrievePlanGroup(planGroupUUID string) (*PlanGroup, error)

RetrievePlanGroup returns one plan group by UUID.

See https://dev.chartmogul.com/v1.0/reference#plan_groups

func (API) SearchCustomers

func (api API) SearchCustomers(searchCustomersParams *SearchCustomersParams) (*Customers, error)

SearchCustomers lists all Customers for cutomer of given UUID.

See https://dev.chartmogul.com/v1.0/reference#customers

func (*API) SetClient

func (api *API) SetClient(newClient *http.Client)

SetClient changes the client - for VCR integration tests.

func (API) UpdateContact added in v3.1.0

func (api API) UpdateContact(input *UpdateContact, contactUUID string) (*Contact, error)

UpdateContact updates one contact in API.

See https://dev.chartmogul.com/reference/retrieve-a-contact

func (API) UpdateCustomAttributesOfCustomer

func (api API) UpdateCustomAttributesOfCustomer(customerUUID string, customAttributes map[string]interface{}) (*CustomAttributes, error)

UpdateCustomAttributesOfCustomer updates custom attributes of a specific customer.

See https://dev.chartmogul.com/v1.0/reference#customer-attributes

func (API) UpdateCustomer

func (api API) UpdateCustomer(customer *Customer, customerUUID string) (*Customer, error)

UpdateCustomer updates one customer in API.

See https://dev.chartmogul.com/v1.0/reference#customers

func (API) UpdateCustomerV2

func (api API) UpdateCustomerV2(input *UpdateCustomer, customerUUID string) (*Customer, error)

UpdateCustomerV2 updates one customer in API.

See https://dev.chartmogul.com/v1.0/reference#update-a-customer

func (API) UpdatePlan

func (api API) UpdatePlan(plan *Plan, planUUID string) (*Plan, error)

UpdatePlan returns list of plans.

See https://dev.chartmogul.com/v1.0/reference#plans

func (API) UpdatePlanGroup

func (api API) UpdatePlanGroup(planGroup *PlanGroup, planGroupUUID string) (*PlanGroup, error)

UpdatePlanGroup updates a name or plans.

See https://dev.chartmogul.com/v1.0/reference#plan_groups

func (API) UpdateSubscriptionEvent added in v3.1.0

func (api API) UpdateSubscriptionEvent(subscriptionEvent *SubscriptionEvent) (*SubscriptionEvent, error)

type ARPAMetrics

type ARPAMetrics struct {
	Date             string  `json:"date"`
	ARPA             float64 `json:"arpa"`
	PercentageChange float64 `json:"percentage-change"`
}

ARPAMetrics represents results of Metrics API.

type ARPAResult

type ARPAResult struct {
	Entries []*ARPAMetrics `json:"entries,omitempty"`
	Summary *Summary       `json:"summary"`
}

ARPAResult represents results of Metrics API.

type ARRMetrics

type ARRMetrics struct {
	Date             string  `json:"date"`
	ARR              float64 `json:"arr"`
	PercentageChange float64 `json:"percentage-change"`
}

ARRMetrics represents results of Metrics API.

type ARRResult

type ARRResult struct {
	Entries []*ARRMetrics `json:"entries,omitempty"`
	Summary *Summary      `json:"summary"`
}

ARRResult represents results of Metrics API.

type ASPMetrics

type ASPMetrics struct {
	Date             string  `json:"date"`
	ASP              float64 `json:"asp"`
	PercentageChange float64 `json:"percentage-change"`
}

ASPMetrics represents results of Metrics API.

type ASPResult

type ASPResult struct {
	Entries []*ASPMetrics `json:"entries,omitempty"`
	Summary *Summary      `json:"summary"`
}

ASPResult represents results of Metrics API.

type Account

type Account struct {
	Name        string `json:"name"`
	Currency    string `json:"currency"`
	TimeZone    string `json:"time_zone"`
	WeekStartOn string `json:"week_start_on"`
}

Account details in ChartMogul

type Address

type Address struct {
	AddressZIP string `json:"address_zip,omitempty"`
	City       string `json:"city,omitempty"`
	State      string `json:"state,omitempty"`
	Country    string `json:"country,omitempty"`
}

Address is subdocument of Customer.

type AllMetrics

type AllMetrics struct {
	Date                              string  `json:"date"`
	CustomerChurnRate                 float64 `json:"customer-churn-rate"`
	MrrChurnRate                      float64 `json:"mrr-churn-rate"`
	Ltv                               float64 `json:"ltv"`
	Customers                         uint32  `json:"customers"`
	Asp                               float64 `json:"asp"`
	Arpa                              float64 `json:"arpa"`
	Arr                               float64 `json:"arr"`
	Mrr                               float64 `json:"mrr"`
	CustomerChurnRatePercentageChange float64 `json:"customer-churn-rate-percentage-change"`
	MrrChurnRatePercentageChange      float64 `json:"mrr-churn-rate-percentage-change"`
	LtvPercentageChange               float64 `json:"ltv-percentage-change"`
	CustomersPercentageChange         float64 `json:"customers-percentage-change"`
	AspPercentageChange               float64 `json:"asp-percentage-change"`
	ArpaPercentageChange              float64 `json:"arpa-percentage-change"`
	ArrPercentageChange               float64 `json:"arr-percentage-change"`
	MrrPercentageChange               float64 `json:"mrr-percentage-change"`
}

AllMetrics represents results of Metrics API.

type AllSummary added in v3.1.0

type AllSummary struct {
	CurrentCustomerChurnRate          float64 `json:"current-customer-churn-rate"`
	PreviousCustomerChurnRate         float64 `json:"previous-customer-churn-rate"`
	CustomerChurnRatePercentageChange float64 `json:"customer-churn-rate-percentage-change"`
	CurrentMrrChurnRate               float64 `json:"current-mrr-churn-rate"`
	PreviousMrrChurnRate              float64 `json:"previous-mrr-churn-rate"`
	MrrChurnRatePercentageChange      float64 `json:"mrr-churn-rate-percentage-change"`
	CurrentLtv                        float64 `json:"current-ltv"`
	PreviousLtv                       float64 `json:"previous-ltv"`
	LtvPercentageChange               float64 `json:"ltv-percentage-change"`
	CurrentCustomers                  uint32  `json:"current-customers"`
	PreviousCustomers                 uint32  `json:"previous-customers"`
	CustomersPercentageChange         float64 `json:"customers-percentage-change"`
	CurrentAsp                        float64 `json:"current-asp"`
	PreviousAsp                       float64 `json:"previous-asp"`
	AspPercentageChange               float64 `json:"asp-percentage-change"`
	CurrentArpa                       float64 `json:"current-arpa"`
	PreviousArpa                      float64 `json:"previous-arpa"`
	ArpaPercentageChange              float64 `json:"arpa-percentage-change"`
	CurrentArr                        float64 `json:"current-arr"`
	PreviousArr                       float64 `json:"previous-arr"`
	ArrPercentageChange               float64 `json:"arr-percentage-change"`
	CurrentMrr                        float64 `json:"current-mrr"`
	PreviousMrr                       float64 `json:"previous-mrr"`
	MrrPercentageChange               float64 `json:"mrr-percentage-change"`
}

Summary represents results of Metrics API.

type AnchorCursor

type AnchorCursor struct {
	PerPage uint32 `json:"per-page,omitempty"`
	//StartAfter is used to get the next set of Entries and its value should be the UUID of last Entry from previous response.
	StartAfter string `json:"start-after,omitempty"`
}

AnchorCursor contains query parameters for anchor based pagination used for some APIs in ChartMogul.

type AttributeWithSource

type AttributeWithSource struct {
	Value  interface{} `json:"value"`
	Source string      `json:"source"`
}

AttributeWithSource covers the special case when you need to update customer's attribute and chage the source which shows in the ChartMogul UI.

type Attributes

type Attributes struct {
	Tags     []string               `json:"tags,omitempty"`
	Stripe   map[string]interface{} `json:"stripe,omitempty"`
	Clearbit map[string]interface{} `json:"clearbit,omitempty"`
	Custom   map[string]interface{} `json:"custom,omitempty"`
}

Attributes is subdocument of Customer.

type CancelSubscriptionParams

type CancelSubscriptionParams struct {
	CancelledAt       string    `json:"cancelled_at,omitempty"`
	CancellationDates *[]string `json:"cancellation_dates,omitempty"`
}

CancelSubscriptionParams represents arguments to be marshalled into JSON.

type Contact added in v3.1.0

type Contact struct {
	UUID string `json:"uuid,omitempty"`
	// Basic info
	CustomerExternalID string                 `json:"customer_external_id,omitempty"`
	CustomerUUID       string                 `json:"customer_uuid,omitempty"`
	DataSourceUUID     string                 `json:"data_source_uuid,omitempty"`
	FirstName          string                 `json:"first_name,omitempty"`
	LastName           string                 `json:"last_name,omitempty"`
	LinkedIn           string                 `json:"linked_in,omitempty"`
	Notes              string                 `json:"notes,omitempty"`
	Phone              string                 `json:"phone,omitempty"`
	Position           uint32                 `json:"position,omitempty"`
	Title              string                 `json:"title,omitempty"`
	Twitter            string                 `json:"twitter,omitempty"`
	Custom             map[string]interface{} `json:"custom,omitempty"`
}

Contact is the contact as represented in the API.

type Contacts added in v3.1.0

type Contacts struct {
	Entries []*Contact `json:"entries,omitempty"`
	Cursor  string     `json:"cursor,omitempty"`
	HasMore bool       `json:"has_more,omitempty"`
}

Contacts is result of listing contacts in API.

type CreateMetricsActivitiesExportParam

type CreateMetricsActivitiesExportParam struct {
	Type      string `json:"type,omitempty"`
	StartDate string `json:"start-date,omitempty"`
	EndDate   string `json:"end-date,omitempty"`
}

CreateMetricsActivitiesExportParam to create a MetricsActivitiesExport.

type Cursor

type Cursor struct {
	Page    uint32 `json:"page,omitempty"`
	PerPage uint32 `json:"per_page,omitempty"`
}

Cursor contains query parameters for paging in CM. Attributes for query must be string, because gorequest library cannot convert anything else.

type CustID

type CustID struct {
	DataSourceUUID string `json:"data_source_uuid,omitempty"`
	ExternalID     string `json:"external_id,omitempty"`
	CustomerUUID   string `json:"customer_uuid,omitempty"`
}

CustID - use either DataSourceUUID & ExternalID or CustomerUUID

type Custom added in v3.1.0

type Custom struct {
	Key   string `json:"key,omitempty"`
	Value string `json:"value,omitempty"`
}

type CustomAttribute

type CustomAttribute struct {
	Type   string      `json:"type"`
	Key    string      `json:"key"`
	Value  interface{} `json:"value"`
	Source string      `json:"source,omitempty"`
}

CustomAttribute = typed custom attribute.

type CustomAttributes

type CustomAttributes struct {
	Custom map[string]interface{} `json:"custom"`
}

CustomAttributes contains updated custom attributes.

type Customer

type Customer struct {
	ID uint32 `json:"id,omitempty"`
	// Basic info
	DataSourceUUID  string   `json:"data_source_uuid,omitempty"`
	DataSourceUUIDs []string `json:"data_source_uuids,omitempty"`
	UUID            string   `json:"uuid,omitempty"`
	ExternalID      string   `json:"external_id,omitempty"`
	ExternalIDs     []string `json:"external_ids,omitempty"`
	Name            string   `json:"name,omitempty"`
	Email           string   `json:"email,omitempty"`
	Status          string   `json:"status,omitempty"`
	CustomerSince   string   `json:"customer-since,omitempty"`

	Attributes *Attributes `json:"attributes,omitempty"`
	Address    *Address    `json:"address,omitempty"`

	// Other info
	Mrr               float64 `json:"mrr,omitempty"`
	Arr               float64 `json:"arr,omitempty"`
	BillingSystemURL  string  `json:"billing-system-url,omitempty"`
	ChartmogulURL     string  `json:"chartmogul-url,omitempty"`
	BillingSystemType string  `json:"billing-system-type,omitempty"`
	Currency          string  `json:"currency,omitempty"`
	CurrencySign      string  `json:"currency-sign,omitempty"`

	// For update
	Company            string `json:"company,omitempty"`
	Country            string `json:"country,omitempty"`
	State              string `json:"state,omitempty"`
	City               string `json:"city,omitempty"`
	Zip                string `json:"zip,omitempty"`
	LeadCreatedAt      string `json:"lead_created_at,omitempty"`
	FreeTrialStartedAt string `json:"free_trial_started_at,omitempty"`

	Errors Errors `json:"errors,omitempty"`
}

Customer is the customer as represented in the API.

type CustomerChurnRateMetrics

type CustomerChurnRateMetrics struct {
	Date              string  `json:"date"`
	CustomerChurnRate float64 `json:"customer-churn-rate"`
	PercentageChange  float64 `json:"percentage-change"`
}

CustomerChurnRateMetrics represents results of Metrics API.

type CustomerChurnRateResult

type CustomerChurnRateResult struct {
	Entries []*CustomerChurnRateMetrics `json:"entries,omitempty"`
	Summary *Summary                    `json:"summary"`
}

CustomerChurnRateResult represents results of Metrics API.

type CustomerCountMetrics

type CustomerCountMetrics struct {
	Date             string  `json:"date"`
	Customers        uint32  `json:"customers"`
	PercentageChange float64 `json:"percentage-change"`
}

CustomerCountMetrics represents results of Metrics API.

type CustomerCountResult

type CustomerCountResult struct {
	Entries []*CustomerCountMetrics `json:"entries,omitempty"`
	Summary *Summary                `json:"summary"`
}

CustomerCountResult represents results of Metrics API.

type Customers

type Customers struct {
	Entries     []*Customer `json:"entries,omitempty"`
	Page        uint32      `json:"page"`
	PerPage     uint32      `json:"per_page"`
	HasMore     bool        `json:"has_more,omitempty"`
	CurrentPage int32       `json:"current_page,omitempty"`
	TotalPages  int32       `json:"total_pages,omitempty"`
}

Customers is result of listing customers in API.

type DataSource

type DataSource struct {
	UUID      string `json:"uuid"`
	Name      string `json:"name"`
	CreatedAt string `json:"created_at"`
	Status    string `json:"status"`
	System    string `json:"system"`
	Errors    Errors `json:"errors,omitempty"`
}

DataSource represents API data source in ChartMogul. See https://dev.chartmogul.com/v1.0/reference#list-data-sources

type DataSources

type DataSources struct {
	DataSources []*DataSource `json:"data_sources"`
}

DataSources is the result of listing data sources, but doesn't contain any paging.

type DeleteCustomerInvoicesParams

type DeleteCustomerInvoicesParams struct {
	CustomerExternalID string
}

DeleteCustomerInvoicesParams - optional param for deleting all customer invoices.

type DeleteSubscriptionEvent added in v3.1.0

type DeleteSubscriptionEvent struct {
	ID             uint64 `json:"id,omitempty"`
	DataSourceUUID string `json:"data_source_uuid,omitempty"`
	ExternalID     string `json:"external_id,omitempty"`
}

type DeleteSubscriptionEventParams added in v3.1.0

type DeleteSubscriptionEventParams struct {
	Params *DeleteSubscriptionEvent `json:"subscription_event"`
}

type Errors

type Errors map[string]string

Errors contains error feedback from ChartMogul

func (Errors) Error

func (e Errors) Error() string

func (Errors) IsAlreadyExists

func (e Errors) IsAlreadyExists() (is bool)

IsAlreadyExists is helper that returns true, if there's only one error and it means the uploaded resource of the same external_id already exists.

func (Errors) IsInvoiceAndItsEntitiesAlreadyExist

func (e Errors) IsInvoiceAndItsEntitiesAlreadyExist() (is bool)

IsInvoiceAndItsEntitiesAlreadyExist returns true if: * invoice already exists AND * ANY other entities (line items, transactions) already exist AND * no other error

So, eg. if the invoice doesn't exist, but the transaction does, you have a different problem (duplicating txns) and this returns false.

func (Errors) IsInvoiceAndTransactionAlreadyExist

func (e Errors) IsInvoiceAndTransactionAlreadyExist() (is bool)

IsInvoiceAndTransactionAlreadyExist occurs when both invoice and tx exist already. Use `IsInvoiceAndItsEntitiesAlreadyExist` if you'd like to catch line items as well.

type FilterSubscriptionEvents added in v3.1.0

type FilterSubscriptionEvents struct {
	CustomerExternalID     string `json:"customer_external_id,omitempty"`
	DataSourceUUID         string `json:"data_source_uuid,omitempty"`
	EffectiveDate          string `json:"effective_date,omitempty"`
	EventDate              string `json:"event_date,omitempty"`
	EventType              string `json:"event_type,omitempty"`
	ExternalID             string `json:"external_id,omitempty"`
	PlanExternalID         string `json:"plan_external_id,omitempty"`
	SubscriptionExternalID string `json:"subscription_external_id,omitempty"`
}

type HTTPError

type HTTPError interface {
	StatusCode() int
	Status() string
	Response() string
}

HTTPError is wrapper to easily handle HTTP states.

type IApi

type IApi interface {
	Ping() (res bool, err error)
	// Data sources
	CreateDataSource(name string) (*DataSource, error)
	CreateDataSourceWithSystem(dataSource *DataSource) (*DataSource, error)
	RetrieveDataSource(dataSourceUUID string) (*DataSource, error)
	ListDataSources() (*DataSources, error)
	ListDataSourcesWithFilters(listDataSourcesParams *ListDataSourcesParams) (*DataSources, error)
	PurgeDataSource(dataSourceUUID string) error
	EmptyDataSource(dataSourceUUID string) error
	DeleteDataSource(dataSourceUUID string) error
	// Invoices
	CreateInvoices(invoices []*Invoice, customerUUID string) (*Invoices, error)
	ListInvoices(cursor *Cursor, customerUUID string) (*Invoices, error)
	ListAllInvoices(listAllInvoicesParams *ListAllInvoicesParams) (*Invoices, error)
	RetrieveInvoice(invoiceUUID string) (*Invoice, error)
	DeleteInvoice(invoiceUUID string) error
	// Plans
	CreatePlan(plan *Plan) (result *Plan, err error)
	RetrievePlan(planUUID string) (*Plan, error)
	ListPlans(listPlansParams *ListPlansParams) (*Plans, error)
	UpdatePlan(plan *Plan, planUUID string) (*Plan, error)
	DeletePlan(planUUID string) error
	// Plan Groups
	CreatePlanGroup(planGroup *PlanGroup) (result *PlanGroup, err error)
	RetrievePlanGroup(planGroupUUID string) (*PlanGroup, error)
	ListPlanGroups(cursor *Cursor) (*PlanGroups, error)
	UpdatePlanGroup(plan *PlanGroup, planGroupUUID string) (*PlanGroup, error)
	DeletePlanGroup(planGroupUUID string) error
	ListPlanGroupPlans(cursor *Cursor, planGroupUUID string) (*PlanGroupPlans, error)
	// Subscriptions
	CancelSubscription(subscriptionUUID string, cancelSubscriptionParams *CancelSubscriptionParams) (*Subscription, error)
	ListSubscriptions(cursor *Cursor, customerUUID string) (*Subscriptions, error)
	// Transactions
	CreateTransaction(transaction *Transaction, invoiceUUID string) (*Transaction, error)

	// Customers
	CreateCustomer(newCustomer *NewCustomer) (*Customer, error)
	RetrieveCustomer(customerUUID string) (*Customer, error)
	UpdateCustomer(Customer *Customer, customerUUID string) (*Customer, error)
	UpdateCustomerV2(Customer *UpdateCustomer, customerUUID string) (*Customer, error)
	ListCustomers(ListCustomersParams *ListCustomersParams) (*Customers, error)
	SearchCustomers(SearchCustomersParams *SearchCustomersParams) (*Customers, error)
	MergeCustomers(MergeCustomersParams *MergeCustomersParams) error
	DeleteCustomer(customerUUID string) error
	DeleteCustomerInvoices(dataSourceUUID, customerUUID string) error
	DeleteCustomerInvoicesV2(dataSourceUUID, customerUUID string, DeleteCustomerInvoicesParams *DeleteCustomerInvoicesParams) error
	ListCustomersContacts(ListContactsParams *ListContactsParams, customerUUID string) (*Contacts, error)
	CreateCustomersContact(newContact *NewContact, customerUUID string) (*Contact, error)

	// Contacts
	CreateContact(newContact *NewContact) (*Contact, error)
	RetrieveContact(contactUUID string) (*Contact, error)
	UpdateContact(Contact *UpdateContact, contactUUID string) (*Contact, error)
	ListContacts(ListContactsParams *ListContactsParams) (*Contacts, error)
	DeleteContact(contactUUID string) error
	MergeContacts(intoContactUUID string, fromContactUUID string) (*Contact, error)

	//  - Cusomer Attributes
	RetrieveCustomersAttributes(customerUUID string) (*Attributes, error)

	//  Tags
	AddTagsToCustomer(customerUUID string, tags []string) (*TagsResult, error)
	AddTagsToCustomersWithEmail(email string, tags []string) (*Customers, error)
	RemoveTagsFromCustomer(customerUUID string, tags []string) (*TagsResult, error)

	// Custom Attributes
	AddCustomAttributesToCustomer(customerUUID string, customAttributes []*CustomAttribute) (*CustomAttributes, error)
	AddCustomAttributesWithEmail(email string, customAttributes []*CustomAttribute) (*Customers, error)
	UpdateCustomAttributesOfCustomer(customerUUID string, customAttributes map[string]interface{}) (*CustomAttributes, error)
	RemoveCustomAttributes(customerUUID string, customAttributes []string) (*CustomAttributes, error)

	// Metrics
	MetricsRetrieveAll(metricsFilter *MetricsFilter) (*MetricsResult, error)
	MetricsRetrieveMRR(metricsFilter *MetricsFilter) (*MRRResult, error)
	MetricsRetrieveARR(metricsFilter *MetricsFilter) (*ARRResult, error)
	MetricsRetrieveARPA(metricsFilter *MetricsFilter) (*ARPAResult, error)
	MetricsRetrieveASP(metricsFilter *MetricsFilter) (*ASPResult, error)
	MetricsRetrieveCustomerCount(metricsFilter *MetricsFilter) (*CustomerCountResult, error)
	MetricsRetrieveCustomerChurnRate(metricsFilter *MetricsFilter) (*CustomerChurnRateResult, error)
	MetricsRetrieveMRRChurnRate(metricsFilter *MetricsFilter) (*MRRChurnRateResult, error)
	MetricsRetrieveLTV(metricsFilter *MetricsFilter) (*LTVResult, error)

	// Metrics - Subscriptions & Activities
	MetricsListCustomerSubscriptions(cursor *Cursor, customerUUID string) (*MetricsCustomerSubscriptions, error)
	MetricsListCustomerActivities(cursor *Cursor, customerUUID string) (*MetricsCustomerActivities, error)
	MetricsListActivities(MetricsListActivitiesParams *MetricsListActivitiesParams) (*MetricsActivities, error)
	MetricsCreateActivitiesExport(CreateMetricsActivitiesExportParam *CreateMetricsActivitiesExportParam) (*MetricsActivitiesExport, error)
	MetricsRetrieveActivitiesExport(activitiesExportUUID string) (*MetricsActivitiesExport, error)

	// Account
	RetrieveAccount() (*Account, error)

	// Subscription Events
	ListSubscriptionEvents(filters *FilterSubscriptionEvents, cursor *MetaCursor) (*SubscriptionEvents, error)
	CreateSubscriptionEvent(newSubscriptionEvent *SubscriptionEvent) (*SubscriptionEvent, error)
	UpdateSubscriptionEvent(subscriptionEvent *SubscriptionEvent) (*SubscriptionEvent, error)
	DeleteSubscriptionEvent(deleteParams *DeleteSubscriptionEvent) error
}

IApi defines the interface of the library. Necessary eg. for mocks in testing.

type Invoice

type Invoice struct {
	UUID               string         `json:"uuid,omitempty"`
	CustomerUUID       string         `json:"customer_uuid,omitempty"`
	CustomerExternalID string         `json:"customer_external_id,omitempty"`
	Currency           string         `json:"currency"`
	DataSourceUUID     string         `json:"data_source_uuid,omitempty"`
	Date               string         `json:"date"`
	DueDate            string         `json:"due_date,omitempty"`
	ExternalID         string         `json:"external_id"`
	LineItems          []*LineItem    `json:"line_items"`
	Transactions       []*Transaction `json:"transactions,omitempty"`
	Errors             *Errors        `json:"errors,omitempty"`
}

Invoice is the data for ChartMogul to auto-generate subscriptions.

type Invoices

type Invoices struct {
	CustomerUUID string     `json:"customer_uuid,omitempty"`
	CurrentPage  uint32     `json:"current_page,omitempty"`
	TotalPages   uint32     `json:"total_pages,omitempty"`
	Error        string     `json:"error,omitempty"`
	Invoices     []*Invoice `json:"invoices"`
}

Invoices is wrapper for bulk importing invoices In case of /v1/invoices endpoint, the customer_uuid is on individual invoices and here it's empty.

type LTVMetrics

type LTVMetrics struct {
	Date             string  `json:"date"`
	LTV              float64 `json:"ltv"`
	PercentageChange float64 `json:"percentage-change"`
}

LTVMetrics represents results of Metrics API.

type LTVResult

type LTVResult struct {
	Entries []*LTVMetrics `json:"entries,omitempty"`
	Summary *Summary      `json:"summary"`
}

LTVResult represents results of Metrics API.

type LineItem

type LineItem struct {
	UUID                      string `json:"uuid,omitempty"`
	AccountCode               string `json:"account_code,omitempty"`
	AmountInCents             int    `json:"amount_in_cents"`
	CancelledAt               string `json:"cancelled_at,omitempty"`
	Description               string `json:"description,omitempty"`
	DiscountAmountInCents     int    `json:"discount_amount_in_cents,omitempty"`
	DiscountCode              string `json:"discount_code,omitempty"`
	ExternalID                string `json:"external_id,omitempty"`
	PlanUUID                  string `json:"plan_uuid,omitempty"`
	Prorated                  bool   `json:"prorated,omitempty"`
	Quantity                  int    `json:"quantity,omitempty"`
	ServicePeriodEnd          string `json:"service_period_end,omitempty"`
	ServicePeriodStart        string `json:"service_period_start,omitempty"`
	SubscriptionExternalID    string `json:"subscription_external_id,omitempty"`
	SubscriptionSetExternalID string `json:"subscription_set_external_id,omitempty"`
	SubscriptionUUID          string `json:"subscription_uuid,omitempty"`
	TaxAmountInCents          int    `json:"tax_amount_in_cents,omitempty"`
	TransactionFeesInCents    int    `json:"transaction_fees_in_cents,omitempty"`
	TransactionFeesCurrency   string `json:"transaction_fees_currency,omitempty"`
	DiscountDescription       string `json:"discount_description,omitempty"`
	EventOrder                int    `json:"event_order,omitempty"`
	Type                      string `json:"type"`
}

LineItem represents a singular items of the invoices

type ListAllInvoicesParams

type ListAllInvoicesParams struct {
	CustomerUUID   string `json:"customer_uuid,omitempty"`
	DataSourceUUID string `json:"data_source_uuid,omitempty"`
	ExternalID     string `json:"external_id,omitempty"`
	Cursor
}

ListAllInvoicesParams optional parameters for ListAllInvoices

type ListContactsParams added in v3.1.0

type ListContactsParams struct {
	CustomerUUID   string `json:"customer_uuid,omitempty"`
	DataSourceUUID string `json:"data_source_uuid,omitempty"`
	PaginationWithCursor
}

ListContactsParams = parameters for listing contacts in API.

type ListCustomersParams

type ListCustomersParams struct {
	DataSourceUUID string `json:"data_source_uuid,omitempty"`
	Status         string `json:"status,omitempty"`
	System         string `json:"system,omitempty"`
	ExternalID     string `json:"external_id,omitempty"`
	Cursor
}

ListCustomersParams = parameters for listing customers in API.

type ListDataSourcesParams

type ListDataSourcesParams struct {
	Name   string `json:"name,omitempty"`
	System string `json:"system,omitempty"`
}

ListDataSourcesParams are optional parameters for listing data sources.

type ListPlansParams

type ListPlansParams struct {
	DataSourceUUID string `json:"data_source_uuid"`
	ExternalID     string `json:"external_id,omitempty"`
	System         string `json:"system,omitempty"`
	Cursor
}

ListPlansParams = optional parameters for listing plans.

type MRRChurnRateMetrics

type MRRChurnRateMetrics struct {
	Date             string  `json:"date"`
	MRRChurnRate     float64 `json:"mrr-churn-rate"`
	PercentageChange float64 `json:"percentage-change"`
}

MRRChurnRateMetrics represents results of Metrics API.

type MRRChurnRateResult

type MRRChurnRateResult struct {
	Entries []*MRRChurnRateMetrics `json:"entries,omitempty"`
	Summary *Summary               `json:"summary"`
}

MRRChurnRateResult represents results of Metrics API.

type MRRMetrics

type MRRMetrics struct {
	Date             string  `json:"date"`
	MRR              float64 `json:"mrr"`
	MRRNewBusiness   float64 `json:"mrr-new-business"`
	MRRExpansion     float64 `json:"mrr-expansion"`
	MRRContraction   float64 `json:"mrr-contraction"`
	MRRChurn         float64 `json:"mrr-churn"`
	MRRReactivation  float64 `json:"mrr-reactivation"`
	PercentageChange float64 `json:"percentage-change"`
}

MRRMetrics represents results of Metrics API.

type MRRResult

type MRRResult struct {
	Entries []*MRRMetrics `json:"entries,omitempty"`
	Summary *Summary      `json:"summary"`
}

MRRResult represents results of Metrics API.

type MergeCustomersParams

type MergeCustomersParams struct {
	From CustID `json:"from"`
	Into CustID `json:"into"`
}

MergeCustomersParams - identify source and target for merging.

type MetaCursor added in v3.1.0

type MetaCursor struct {
	NextKey    uint64 `json:"next_key,omitempty"`
	PrevKey    uint64 `json:"prev_key,omitempty"`
	BeforeKey  string `json:"before_key,omitempty"`
	Page       uint64 `json:"page,omitempty"`
	TotalPages uint64 `json:"total_pages,omitempty"`
}

type MetricsActivities

type MetricsActivities struct {
	Entries []*MetricsActivity `json:"entries"`
	HasMore bool               `json:"has_more"`
	PerPage uint32             `json:"per_page"`
}

MetricsActivities is the result of listing activities in Metrics API.

type MetricsActivitiesExport

type MetricsActivitiesExport struct {
	ID        string `json:"id"`
	Status    string `json:"status"`
	FileURL   string `json:"file_url"`
	Params    Params `json:"params"`
	ExpiresAt string `json:"expires_at"`
	CreatedAt string `json:"created_at"`
}

MetricsActivitiesExport represents Metrics API activity export in ChartMogul.

type MetricsActivity

type MetricsActivity struct {
	Date                   string  `json:"date"`
	ActivityArr            float64 `json:"activity-arr"`
	ActivityMrr            float64 `json:"activity-mrr"`
	ActivityMrrMovement    float64 `json:"activity-mrr-movement"`
	Currency               string  `json:"currency"`
	Description            string  `json:"description"`
	Type                   string  `json:"type"`
	SubscriptionExternalID string  `json:"subscription-external-id"`
	PlanExternalID         string  `json:"plan-external-id"`
	CustomerName           string  `json:"customer-name"`
	CustomerUUID           string  `json:"customer-uuid"`
	CustomerExternalID     string  `json:"customer-external-id"`
	BillingConnectorUUID   string  `json:"billing-connector-uuid"`
	UUID                   string  `json:"uuid"`
}

MetricsActivity represents Metrics API activity in ChartMogul.

type MetricsCustomerActivities

type MetricsCustomerActivities struct {
	Entries []*MetricsCustomerActivity `json:"entries"`
	HasMore bool                       `json:"has_more"`
	PerPage uint32                     `json:"per_page"`
	Page    uint32                     `json:"page"`
}

MetricsCustomerActivities is the result of listing activities in Metrics API.

type MetricsCustomerActivity

type MetricsCustomerActivity struct {
	ID                  uint64  `json:"id"`
	Date                string  `json:"date"`
	ActivityArr         float64 `json:"activity-arr"`
	ActivityMrr         float64 `json:"activity-mrr"`
	ActivityMrrMovement float64 `json:"activity-mrr-movement"`
	Currency            string  `json:"currency"`
	CurrencySign        string  `json:"currency-sign"`
	Description         string  `json:"description"`
	Type                string  `json:"type"`
}

MetricsCustomerActivity represents Metrics API activity in ChartMogul.

type MetricsCustomerSubscription

type MetricsCustomerSubscription struct {
	ID                uint64  `json:"id"`
	ExternalID        string  `json:"external_id"`
	Plan              string  `json:"plan"`
	Quantity          uint32  `json:"quantity"`
	BillingCycleCount uint32  `json:"billing-cycle-count"`
	MRR               float64 `json:"mrr"`
	ARR               float64 `json:"arr"`
	Status            string  `json:"status"`
	BillingCycle      string  `json:"billing-cycle"`
	StartDate         string  `json:"start-date"`
	EndDate           string  `json:"end-date"`
	Currency          string  `json:"currency"`
	CurrencySign      string  `json:"currency-sign"`
}

MetricsCustomerSubscription represents Metrics API subscription in ChartMogul.

type MetricsCustomerSubscriptions

type MetricsCustomerSubscriptions struct {
	Entries []*MetricsCustomerSubscription `json:"entries"`
	HasMore bool                           `json:"has_more"`
	PerPage uint32                         `json:"per_page"`
	Page    uint32                         `json:"page"`
}

MetricsCustomerSubscriptions is the result of listing subscriptions in Metrics API.

type MetricsFilter

type MetricsFilter struct {
	StartDate string `json:"start-date,omitempty"`
	EndDate   string `json:"end-date,omitempty"`
	Interval  string `json:"interval,omitempty"`
	Geo       string `json:"geo,omitempty"`
	Plans     string `json:"plans,omitempty"`
}

MetricsFilter convenient object to hold all filtering parameters.

type MetricsListActivitiesParams

type MetricsListActivitiesParams struct {
	Type      string `json:"type,omitempty"`
	StartDate string `json:"start-date,omitempty"`
	EndDate   string `json:"end-date,omitempty"`
	Order     string `json:"order,omitempty"`
	AnchorCursor
}

type MetricsResult

type MetricsResult struct {
	Entries []*AllMetrics `json:"entries,omitempty"`
	Summary *AllSummary   `json:"summary"`
}

MetricsResult represents results of Metrics API.

type NestedParams

type NestedParams struct {
	ActivityType string `json:"activity_type,omitempty"`
	StartDate    string `json:"start_date,omitempty"`
	EndDate      string `json:"end_date,omitempty"`
}

NestedParams represents the params of the requested type of export.

type NewAttributes

type NewAttributes struct {
	Tags   []string           `json:"tags,omitempty"`
	Custom []*CustomAttribute `json:"custom,omitempty"`
}

NewAttributes is subdocument of NewCustomer.

type NewContact added in v3.1.0

type NewContact struct {
	// Obligatory
	CustomerUUID   string `json:"customer_uuid,omitempty"`
	DataSourceUUID string `json:"data_source_uuid,omitempty"`

	//Optional
	FirstName string   `json:"first_name,omitempty"`
	LastName  string   `json:"last_name,omitempty"`
	LinkedIn  string   `json:"linked_in,omitempty"`
	Notes     string   `json:"notes,omitempty"`
	Phone     string   `json:"phone,omitempty"`
	Position  uint32   `json:"position,omitempty"`
	Title     string   `json:"title,omitempty"`
	Twitter   string   `json:"twitter,omitempty"`
	Custom    []Custom `json:"custom,omitempty"`
}

NewContact allows creating contact on a new endpoint.

type NewCustomer

type NewCustomer struct {
	// Obligatory
	DataSourceUUID string `json:"data_source_uuid"`
	ExternalID     string `json:"external_id,omitempty"`
	Name           string `json:"name,omitempty"`

	//Optional
	Email      string         `json:"email,omitempty"`
	Attributes *NewAttributes `json:"attributes,omitempty"`
	// Address
	Company string `json:"company,omitempty"`
	Country string `json:"country,omitempty"`
	State   string `json:"state,omitempty"`
	City    string `json:"city,omitempty"`
	Zip     string `json:"zip,omitempty"`
	// Lead/Trial
	LeadCreatedAt      string `json:"lead_created_at,omitempty"`
	FreeTrialStartedAt string `json:"free_trial_started_at,omitempty"`
}

NewCustomer allows creating customer on a new endpoint.

type PaginationWithCursor added in v3.1.0

type PaginationWithCursor struct {
	PerPage uint32 `json:"per_page,omitempty"`
	// Cursor is a reference to get the next set of entries.
	Cursor string `json:"cursor,omitempty"`
}

PaginationWithCursor is the new standard for cursor with pagination.

type Params

type Params struct {
	Kind   string       `json:"kind"`
	Params NestedParams `json:"params,omitempty"`
}

Params provides information on the requested export.

type Ping

type Ping struct {
	Data string
}

Ping is simple struct for the authentication test endpoint.

type Plan

type Plan struct {
	UUID           string `json:"uuid,omitempty"`
	DataSourceUUID string `json:"data_source_uuid,omitempty"`
	ExternalID     string `json:"external_id,omitempty"`
	Name           string `json:"name,omitempty"`
	IntervalCount  uint32 `json:"interval_count,omitempty"`
	IntervalUnit   string `json:"interval_unit,omitempty"`
	Errors         Errors `json:"errors,omitempty"`
}

Plan represents ChartMogul categorization of subscriptions.

type PlanGroup

type PlanGroup struct {
	UUID       string    `json:"uuid,omitempty"`
	Name       string    `json:"name,omitempty"`
	Plans      []*string `json:"plans,omitempty"`
	PlansCount int       `json:"plans_count,omitempty"`
	Errors     Errors    `json:"errors,omitempty"`
}

PlanGroup represents groups of plans in ChartMogul

type PlanGroupPlans

type PlanGroupPlans struct {
	Plans       []*Plan `json:"plans"`
	TotalPages  uint32  `json:"total_pages"`
	CurrentPage uint32  `json:"current_page"`
}

PlanGroupPlans is result of listing: plans + paging for a plan group.

type PlanGroups

type PlanGroups struct {
	PlanGroups  []*PlanGroup `json:"plan_groups"`
	TotalPages  uint32       `json:"total_pages"`
	CurrentPage uint32       `json:"current_page"`
}

PlanGroups is result of listing: plan_groups + page.

type Plans

type Plans struct {
	Plans       []*Plan `json:"plans"`
	TotalPages  uint32  `json:"total_pages"`
	CurrentPage uint32  `json:"current_page"`
}

Plans is result of listing: plans + paging.

type RequestErrors

type RequestErrors interface {
	Errors() []error
}

RequestErrors wraps multiple request errors to normal 1 error struct.

type SearchCustomersParams

type SearchCustomersParams struct {
	Email string `json:"email,omitempty"`
	Cursor
}

SearchCustomersParams - just email now.

type Subscription

type Subscription struct {
	UUID                      string   `json:"uuid,omitempty"`
	ExternalID                string   `json:"external_id"`
	SubscriptionSetExternalID string   `json:"subscription_set_external_id,omitempty"`
	PlanUUID                  string   `json:"plan_uuid,omitempty"`
	CustomerUUID              string   `json:"customer_uuid,omitempty"`
	DataSourceUUID            string   `json:"data_source_uuid"`
	CancellationDates         []string `json:"cancellation_dates,omitempty"`
}

Subscription represents Import API subscription in ChartMogul.

type SubscriptionEvent added in v3.1.0

type SubscriptionEvent struct {
	ID                        uint64      `json:"id,omitempty"`
	DataSourceUUID            string      `json:"data_source_uuid,omitempty"`
	CustomerExternalID        string      `json:"customer_external_id,omitempty"`
	SubscriptionSetExternalID string      `json:"subscription_set_external_id,omitempty"`
	SubscriptionExternalID    string      `json:"subscription_external_id,omitempty"`
	PlanExternalID            string      `json:"plan_external_id,omitempty"`
	EventDate                 string      `json:"event_date,omitempty"`
	EffectiveDate             string      `json:"effective_date,omitempty"`
	EventType                 string      `json:"event_type,omitempty"`
	ExternalID                string      `json:"external_id,omitempty"`
	Errors                    interface{} `json:"errors,omitempty"`
	CreatedAt                 string      `json:"created_at,omitempty"`
	UpdatedAt                 string      `json:"updated_at,omitempty"`
	Quantity                  int32       `json:"quantity,omitempty"`
	Currency                  string      `json:"currency,omitempty"`
	AmountInCents             int32       `json:"amount_in_cents,omitempty"`
	TaxAmountInCents          int32       `json:"tax_amount_in_cents,omitempty"`
	RetractedEventId          string      `json:"retracted_event_id,omitempty"`
}

type SubscriptionEventParams added in v3.1.0

type SubscriptionEventParams struct {
	Params *SubscriptionEvent `json:"subscription_event"`
}

type SubscriptionEvents added in v3.1.0

type SubscriptionEvents struct {
	SubscriptionEvents []*SubscriptionEvent `json:"subscription_events"`
	Meta               MetaCursor           `json:"meta"`
}

type Subscriptions

type Subscriptions struct {
	Subscriptions []Subscription `json:"subscriptions"`
	CustomerUUID  string         `json:"customer_uuid,omitempty"`
	TotalPages    uint32         `json:"total_pages,omitempty"`
	CurrentPage   uint32         `json:"current_page,omitempty"`
}

Subscriptions is the result of listing subscriptions with paging.

type Summary

type Summary struct {
	Current          float64 `json:"current"`
	Previous         float64 `json:"previous"`
	PercentageChange float64 `json:"percentage-change"`
}

Summary represents results of Metrics API.

type TagsByEmail

type TagsByEmail struct {
	Email string   `json:"email"`
	Tags  []string `json:"tags"`
}

TagsByEmail = input for AddTagsToCustomersWithEmail

type TagsResult

type TagsResult struct {
	Tags []string `json:"tags"`
}

TagsResult is necessary for the the result of AddTags.

type Transaction

type Transaction struct {
	UUID          string `json:"uuid,omitempty"`
	Date          string `json:"date"`
	ExternalID    string `json:"external_id,omitempty"`
	Result        string `json:"result"`
	Type          string `json:"type"`
	AmountInCents *int   `json:"amount_in_cents,omitempty"`
	Errors        Errors `json:"errors,omitempty"`
}

Transaction is either payment/refund on an invoice, for its full value.

type UpdateContact added in v3.1.0

type UpdateContact struct {
	CustomerExternalID string   `json:"customer_external_id,omitempty"`
	DataSourceUUID     string   `json:"data_source_uuid,omitempty"`
	FirstName          string   `json:"first_name,omitempty"`
	LastName           string   `json:"last_name,omitempty"`
	LinkedIn           string   `json:"linked_in,omitempty"`
	Notes              string   `json:"notes,omitempty"`
	Phone              string   `json:"phone,omitempty"`
	Position           uint32   `json:"position,omitempty"`
	Title              string   `json:"title,omitempty"`
	Twitter            string   `json:"twitter,omitempty"`
	Custom             []Custom `json:"custom,omitempty"`
}

UpdateContact allows updating contact on the update endpoint.

type UpdateCustomer

type UpdateCustomer struct {
	Name               *string     `json:"name,omitempty"`
	Email              *string     `json:"email,omitempty"`
	Company            *string     `json:"company,omitempty"`
	Country            *string     `json:"country,omitempty"`
	State              *string     `json:"state,omitempty"`
	City               *string     `json:"city,omitempty"`
	Zip                *string     `json:"zip,omitempty"`
	LeadCreatedAt      *string     `json:"lead_created_at,omitempty"`
	FreeTrialStartedAt *string     `json:"free_trial_started_at,omitempty"`
	Attributes         *Attributes `json:"attributes,omitempty"`
}

UpdateCustomer allows updating customer on the update endpoint.

Directories

Path Synopsis
Package mock_v3 is a generated GoMock package.
Package mock_v3 is a generated GoMock package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL