Categorygithub.com/maxio-com/ab-golang-sdk
modulepackage
1.0.1-alpha.1
Repository: https://github.com/maxio-com/ab-golang-sdk.git
Documentation: pkg.go.dev

# README

Getting Started with Maxio Advanced Billing

Introduction

Introduction

API Integration

Maxio Advanced Billing (formerly Chargify API) can be integrated with many environments and programming languages via our REST API. Some of our users have contributed their API wrappers in various programming languages. Check out the API Code Overview doc for an introduction to the wrappers and available code samples.

Testing Guide

Maxio Advanced Billing has compiled a testing guide that covers a list of important factors to consider while in the testing phase. Here's a high-level overiew of what's covered in our testing guide:

  • Test credit card basics
  • Test site limits
  • Live mode versus test mode

We strongly suggest reading over the testing guide, as well as the entire set of application-based documentation to aid in your discovery of the product.

Engage Support

We always enjoy (and appreciate) hearing about larger integrations ahead of time. If you’re planning on importing a large amount of data into Maxio via our API, we suggest sending a “heads up” to “[email protected]” so we can coordinate with you to ensure your import process goes smoothly.

Our API, while considered stable, is continually being improved and polished. Please feel free to contact support if you experience issues when integrating with the Maxio Advanced Billing API.

If you have any additional questions regarding our documentation please don't hesitate in reaching out.

Support Access

Access to our Technical Specialist team for API support is currently limited to purchasers of our larger Maxio support plans.

But don’t worry! There are quite a few options to help you get the answers you need:

API Overview

The Chargify API allows you to interact with our system programmatically from your own application. Using the API you interact with Resources such as:

  • Products
  • Subscriptions
  • Customers
  • etc.

The API attempts to conform to the RESTful design principles. You interact with the resources exposed via the API by accessing resource collection and element URIs using the HTTP verbs (GET, POST, PUT, and DELETE). Chargify accepts and returns both JSON and XML data via the API.

You’ll likely need access to a web developer or programmer (if you’re not one) to get the most use out of the API.

Available Formats: JSON and XML

JSON is the primary and recommended format for use with the Chargify API. XML is also provided as a backwards compatible option for Merchants who require it.

Authentication

Authentication is implemented as HTTP Basic Authentication over TLS >= 1.2 (HTTPS), as described in API Authentication

URL

The URL for API requests includes the subdomain of the Site you are working with:

https://<subdomain>.chargify.com/<resource URI>

Response Data

Response data is sent as either XML or JSON, depending on the type of data requested (HTTP Content-Type header) or the type specified as being accepted (HTTP Accept header).

GETs for individual statements & invoices may also be requested as PDF using application/pdf or appending .pdf to the resource URI.

Response codes are sent via the normal HTTP Response Code, and are documented separately for each resource.

For boolean fields, please note that a value of null may be considered as false. However, this is not true across all cases. Please excercise good judgement here, or contact support with any questions.

For example:

  • null can define that there's no data available for that attribute

Pagination

When an endpoint returns a list of items, it will be paginated. Usually, 20 items will be returned by default, and you may request up to a maximum of 200 at a time. Pagination is done with query string parameters, for example: ?page=5&per_page=200

Response Time Zones

API responses from Chargify are sent with the timezone of current Chargify site.

Alternately, webhooks sent from Chargify globally utilize EST as the timezone for all content in the body of the payload.

Request Data

POST and PUT request data may be formatted as either XML (application/xml) or JSON (application/json). For best results, you should set your HTTP Content-Type request header accordingly, although you may also specify your format by appending .xml or .json extensions on to the resource URI.

Note that Chargify does not accept PUT or POST data sent as query params or form encoded data – data must be sent as either XML or JSON. If you fail to set your Content-Type to either application/xml or application/json, your request may fail due to triggering of forgery protection mechanisms.

About Decimal Numbers

In order to prevent losing precision, we serialize decimal numbers as strings instead of as JSON numbers.

We recommend parsing these strings into their decimal equivalent using a decimal number library in your programming language (i.e. BigDecimal in Ruby) instead of relying on floating point values or arithmetic.

About Amount Fields

Fields holding amount values are given as a string representing a decimal whole currency amount.

For example, "1.23" in currency "USD" would equate to $1.23.

Not all fields will be rounded to the smallest currency denomination. Intermediate results, such as those that derive from line-level tax calculations, may hold precision up to 8 decimal places. However, the top-level totals we provide (e.g. total_amount) will be rounded to the smallest currency denomination.

It is up to API consumers to parse the string into a decimal number representation and do any rounding necessary for your application.

Debugging

If you’re having difficulty executing a request via our API, try the simplest thing and attempt your request via the curl command-line tool, as shown in the below example. Add the --verbose flag to your request to receive even more debugging information.

Another handy tool is Beeceptor. You can use this to intercept your request to see exactly what is being sent.

If you are unable to connect at all, check that you are using TLS 1.2 or better.

If you see a "Could not resolve host" error, double check that the url is correct, including your subdomain. For example: mysite.chargify.com. This error means your DNS server could not find an IP address for the domain you are trying to connect to.

Backwards Compatibility

We consider the following changes to be backwards compatible and may make them without advance notice:

  • Adding new API endpoints, or adding new attributes in the responses of existing endpoints
  • Adding new optional parameters to be sent to existing API endpoints
  • Adding new fields to exported data
  • Changing the type or length of any of the ID attributes
    • For example, most IDs are currently integers, but you should not assume that this will always be the case.

In addition, you should not depend on the order of attributes within the API response as this may change.

Chargify does not provide notifications for additions that are clearly defined as backwards compatible.

Examples

The following examples use the curl command-line tool to execute API requests.

Subscription Listing

Request

curl -u <api_key>:x -H Accept:application/json -H Content-Type:application/json https://acme.chargify.com/subscriptions.json

API Access Limitations

There are a few scenarios that may end up in causing an API request to be blocked even with correct credentials. Please note: All relevant API requests will be blocked if any of the below conditions are true. These limitations also apply to Chargify Direct.

Those scenarios are as follows:

  • Your Chargify subscription is canceled.
  • Your Chargify trial has reached an end.
  • The site you're making a request for is in the process of "clearing site data"
    • Note: any API request for another site that is in a good state will NOT be blocked
  • The site you're making a request for has been deleted.
    • Note: any API request for another site that is in a good state will NOT be blocked

Read more about your Chargify subscription here

What happens when an API request is blocked

The request will fail with a 422 http status code. The response will also include a message explaining the reason for the request being blocked. For example:

  • If your Chargify subscription is canceled:
{
  "errors" => [
    [0] "Your Chargify account has been canceled. Please contact [email protected] to reactivate."
  ]
}
  • If your Chargify trial has reached and end and you attempted to make an API request, the response body will look like:
{
  "errors" => [
    [0] "Your trial has ended, please contact sales."
  ]
}
{
  "errors" => [
    [0] "Site data clearing is in progress. Please try later."
  ]
}
  • If the site you're making a request for has been deleted:
{
  "errors" => [
    [0] "This site has been deleted."
  ]
}

Secure Applications

Please note that it is NOT possible to make API requests directly from the customer's browser or device. Doing so would expose your API key on the client side, and anyone who has that key has full access to all of your Chargify data.

Instead you will need to take care to tokenize sensitive information by using Chargify.js or a similar JavaScript library provided by your gateway, and then post the token and other information to your own server, from which you can make the API call to Chargify.

Troubleshooting

If you attempt to make a Chargify API request directly from the customer's browser, you may see an error such as:

Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

or

Origin 'https://example.com' is therefore not allowed access.` `The response had HTTP status code 404.

This is an error message indicating that Cross-Origin Resource Sharing (CORS) is not enabled on the Chargify server.

Relationship Invoicing

API Compatibility for Relationship Invoicing

This section describes the API for the new, Relationship Invoicing style of invoices introduced in January 2018.

If you are an existing customer from prior to January 2018 or have not otherwise explicitly opted into this new style of invoices, you are probably looking for the legacy "Invoices" section that describes invoice-billing legacy-style invoices.

These new invoices provide a single representation of all of your Chargify billing, whether you collect automatically or via remittance.

About Decimal Numbers

In order to prevent losing precision, we serialize decimal numbers as strings instead of as JSON numbers.

We recommend parsing these strings into their decimal equivalent using a decimal number library in your programming language (i.e. BigDecimal in Ruby) instead of relying on floating point values or arithmetic.

About Amount Fields

Fields holding amount values are given as a string representing a decimal whole currency amount.

For example, "1.23" in currency "USD" would equate to $1.23.

Not all fields will be rounded to the smallest currency denomination. Intermediate results, such as those that derive from line-level tax calculations, may hold precision up to 8 decimal places. However, the top-level totals we provide (e.g. total_amount) will be rounded to the smallest currency denomination.

It is up to API consumers to parse the string into a decimal number representation and do any rounding necessary for your application.

Relationship Invoicing Summary

Requirements

The SDK requires Go version 1.18 or above.

Installation

The following section explains how to use the advancedbilling library in a new project.

1. Install the Package

To use the package in your application, you can install the package from pkg.go.dev using the following command:

$ go get github.com/maxio-com/[email protected]

You can also view the package at: https://pkg.go.dev/github.com/maxio-com/[email protected]

Initialize the API Client

Note: Documentation for the client can be found here.

The following parameters are configurable for the API Client:

ParameterTypeDescription
subdomainstringThe subdomain for your Chargify site.
Default: "subdomain"
domainstringThe Chargify server domain.
Default: "chargify.com"
environmentEnvironmentThe API environment.
Default: Environment.PRODUCTION
httpConfigurationHttpConfigurationConfigurable http client options like timeout and retries.
basicAuthCredentialsBasicAuthCredentialsThe Credentials Setter for Basic Authentication

The API client can be initialized as follows:

client := advancedbilling.NewClient(
    advancedbilling.CreateConfiguration(
        advancedbilling.WithHttpConfiguration(
            advancedbilling.CreateHttpConfiguration(
                advancedbilling.WithTimeout(30),
            ),
        ),
        advancedbilling.WithEnvironment(advancedbilling.PRODUCTION),
        advancedbilling.WithBasicAuthCredentials(
            advancedbilling.NewBasicAuthCredentials(
                "BasicAuthUserName",
                "BasicAuthPassword",
            ),
        ),
    ),
)

Environments

The SDK can be configured to use a different environment for making API calls. Available environments are:

Fields

NameDescription
productionDefault Production server
environment2Production server

Authorization

This API uses the following authentication schemes.

List of APIs

Classes Documentation

# Packages

Package advancedbilling This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).
Package advancedbilling This file was automatically generated for Maxio by APIMATIC v3.0 ( https://www.apimatic.io ).

# Functions

CreateConfiguration creates a new Configuration with the provided options.
CreateConfigurationFromEnvironment creates a new Configuration with default settings.
CreateHttpConfiguration creates a new HttpConfiguration with the provided options.
CreateRetryConfiguration creates a new RetryConfiguration with the provided options.
DefaultConfiguration returns the default Configuration.
DefaultHttpConfiguration returns the default HttpConfiguration for HTTP requests.
DefaultRetryConfiguration returns the default RetryConfiguration for HTTP requests.
NewAdvanceInvoiceController creates a new instance of AdvanceInvoiceController.
NewAPIExportsController creates a new instance of APIExportsController.
NewBaseController creates a new instance of baseController.
NewBasicAuthCredentials creates a new instance of BasicAuthCredentials with provided parameters.
NewBillingPortalController creates a new instance of BillingPortalController.
NewClient is the constructor for creating a new client instance.
NewComponentsController creates a new instance of ComponentsController.
NewCouponsController creates a new instance of CouponsController.
NewCustomersController creates a new instance of CustomersController.
NewCustomFieldsController creates a new instance of CustomFieldsController.
NewEventsBasedBillingSegmentsController creates a new instance of EventsBasedBillingSegmentsController.
NewEventsController creates a new instance of EventsController.
NewInsightsController creates a new instance of InsightsController.
NewInvoicesController creates a new instance of InvoicesController.
NewOffersController creates a new instance of OffersController.
NewPaymentProfilesController creates a new instance of PaymentProfilesController.
NewProductFamiliesController creates a new instance of ProductFamiliesController.
NewProductPricePointsController creates a new instance of ProductPricePointsController.
NewProductsController creates a new instance of ProductsController.
NewProformaInvoicesController creates a new instance of ProformaInvoicesController.
NewReasonCodesController creates a new instance of ReasonCodesController.
NewReferralCodesController creates a new instance of ReferralCodesController.
NewSalesCommissionsController creates a new instance of SalesCommissionsController.
NewSitesController creates a new instance of SitesController.
NewSubscriptionComponentsController creates a new instance of SubscriptionComponentsController.
NewSubscriptionGroupInvoiceAccountController creates a new instance of SubscriptionGroupInvoiceAccountController.
NewSubscriptionGroupsController creates a new instance of SubscriptionGroupsController.
NewSubscriptionGroupStatusController creates a new instance of SubscriptionGroupStatusController.
NewSubscriptionInvoiceAccountController creates a new instance of SubscriptionInvoiceAccountController.
NewSubscriptionNotesController creates a new instance of SubscriptionNotesController.
NewSubscriptionProductsController creates a new instance of SubscriptionProductsController.
NewSubscriptionsController creates a new instance of SubscriptionsController.
NewSubscriptionStatusController creates a new instance of SubscriptionStatusController.
NewWebhooksController creates a new instance of WebhooksController.
WithBasicAuthCredentials is an option that sets the BasicAuthCredentials in the Configuration.
WithDomain is an option that sets the Domain in the Configuration.
WithEnvironment is an option that sets the Environment in the Configuration.
WithHttpConfiguration is an option that sets the HttpConfiguration in the Configuration.
WithSubdomain is an option that sets the Subdomain in the Configuration.

# Constants

No description provided by the author
No description provided by the author
No description provided by the author

# Variables

NewAndAuth creates a new AndAuth.
NewAuth creates a new Auth.
NewHttpConfiguration creates a new HttpConfiguration.
NewOrAuth creates a new OrAuth.
NewRetryConfiguration creates a new RetryConfiguration.
WithBackoffFactor sets the BackoffFactor.
WithHttpMethodsToRetry sets the HttpMethodsToRetry.
WithHttpStatusCodesToRetry sets the HttpStatusCodesToRetry.
WithMaximumRetryWaitTime sets the MaximumRetryWaitTime.
WithMaxRetryAttempts sets the MaxRetryAttempts.
WithRetryConfiguration sets the RetryConfiguration.
WithRetryInterval sets the RetryInterval.
WithRetryOnTimeout sets the RetryOnTimeout.
WithTimeout sets the Timeout.
WithTransport sets the Transport.

# Structs

AdvanceInvoiceController represents a controller struct.
APIExportsController represents a controller struct.
BasicAuthCredentials represents the credentials required for `BasicAuth` authentication.
BillingPortalController represents a controller struct.
ComponentsController represents a controller struct.
Configuration holds configuration settings.
CouponsController represents a controller struct.
CustomersController represents a controller struct.
CustomFieldsController represents a controller struct.
EventsBasedBillingSegmentsController represents a controller struct.
EventsController represents a controller struct.
InsightsController represents a controller struct.
InvoicesController represents a controller struct.
OffersController represents a controller struct.
PaymentProfilesController represents a controller struct.
ProductFamiliesController represents a controller struct.
ProductPricePointsController represents a controller struct.
ProductsController represents a controller struct.
ProformaInvoicesController represents a controller struct.
ReasonCodesController represents a controller struct.
ReferralCodesController represents a controller struct.
SalesCommissionsController represents a controller struct.
SitesController represents a controller struct.
SubscriptionComponentsController represents a controller struct.
SubscriptionGroupInvoiceAccountController represents a controller struct.
SubscriptionGroupsController represents a controller struct.
SubscriptionGroupStatusController represents a controller struct.
SubscriptionInvoiceAccountController represents a controller struct.
SubscriptionNotesController represents a controller struct.
SubscriptionProductsController represents a controller struct.
SubscriptionsController represents a controller struct.
SubscriptionStatusController represents a controller struct.
WebhooksController represents a controller struct.

# Interfaces

Client is an interface representing the main client for accessing configuration and controllers.

# Type aliases

ConfigurationOptions represents a function type that can be used to apply options to the Configuration struct.
Environment represents available environments.
HttpConfiguration holds the configuration options for the client.
HttpConfigurationOptions is a function type that modifies the HttpConfiguration.
RetryConfiguration holds the configuration options for the client.
RetryConfigurationOptions is a function type that modifies the RetryConfiguration.
Server represents available servers.