Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

FundingSources

Paddy Foran edited this page Jun 3, 2013 · 1 revision

FundingSources represent different payment processors and APIs that the user has provided to pay for Subscriptions with.

The Funding Source Resource

Because FundingSource providers all have different requirements for authentication, each FundingSource provider has their own resource defined. These resources are all represented in responses under the funding_sources property, under their own property within the funding_sources property. The funding_sources property will be an object, with a property for each FundingSource provider.

FundingSources appear as follows:

{
  "stripe": [
    {
      // See the Stripe resource for the contents of this part
    }
  ]
}

Furthermore, all FundingSources share the same base properties, regardless of the extra properties they require.

Global Properties

{
  "id": uint64,
  "remote_id": string,
  "nickname": string,
  "last_used": datetime,
  "added": datetime,
  "user_id": uint64
}

Mutable Properties

Mutable properties are properties that can be modified through interactions with the API.

  • remote_id: a unique identifier that will identify the FundingSource in the provider's system.
  • nickname: an optional string the user can modify to supply a custom name for the funding source.

Immutable Properties

Immutable properties are properties that are created and modified only by the system; there is no way to modify them through the API.

  • id: A unique, immutable identifier for this Subscription.
  • last_used: the date and time the FundingSource was last used to send money, expressed as RFC 3339.
  • added: the date and time the FundingSource first appeared in the system, expressed as RFC 3339.
  • user_id: The ID of the User object this FundingSource belongs to.

The Stripe Resource

The Stripe Resource is found under the stripe property in the funding_sources object.

Extra Properties

The Stripe Resource has no properties except those defined in the Global Properties section.

Listing A User's Funding Sources

This request requires only authentication if it is run for the authenticating User's FundingSources. If it is run against another User's FundingSources, it requires administrative credentials.

Request Format

Endpoint

GET /users/{username}/funding_sources

Response Format

Header

This request sets the Last-Modified header to the highest last_used property of the FundingSources returned.

The Content-Type of this request will be funding_sources/encoding. For example, when returned in JSON encoding (the only option available in version 1), the Content-Type will be funding_sources/json.

Body

This request returns a FundingSources resource, containing a property for each FundingSource provider. Each FundingSource provider property's value is a list of that provider's FundingSource resources.

{
  "code": 200,
  "msg": "Successfully retrieved funding sources",
  "funding_sources": {
    "stripe": [
      {
        // See the Stripe Resource for the contents of this part
      }
    ]
  }
}

Errors

Status Code Field Explanation
400 ERROR_MISSING_PARAM username The username query parameter was not set.
403 ERROR_ACCESS_DENIED The authenticating user did not have access to the specified user's funding sources.
404 ERROR_NOT_FOUND user The specified user did not exist.
500 ACT_OF_GOD An unknown error occurred.

Creating New Funding Sources

This request requires only authentication if it is run for the authenticating User. If it is run for another User, it requires administrative credentials.

Request Format

Endpoint

POST /users/{username}/funding_sources

Request Headers

Because this request has a body, the Content-Type and Content-Length headers need to be set.

Request Body

The request body should be a FundingSource Resource container containing arrays of FundingSources according to the provider. Only the Mutable Properties of each FundingSource will be used; the rest will be ignored.

A sample request body:

{
  "funding_sources": {
    "stripe": [
      {
        "remote_id": "cus_1j8Opoq5n6k9UG",
        "nickname": "Stripe"
      }
    ]
  }
}

Response Format

Header

This request sets the Last-Modified header to the latest added property of the returned FundingSources.

The Content-Type of this request will be funding_sources/encoding. For example, when returned in JSON encoding (the only option available in version 1), the Content-Type will be funding_sources/json.

Body

This request returns a FundingSources resource, containing a property for each FundingSource provider. Each FundingSource provider property's value is a list of the FundingSource resources that were added for that provider.

{
  "code": 200,
  "msg": "Successfully created funding sources",
  "funding_sources": {
    "stripe": [
      {
        // See the Stripe Resource for the contents of this part
      }
    ]
  }
}

Errors

Status Code Field Explanation
400 ERROR_MISSING_PARAM username The username query parameter was not set.
403 ERROR_ACCESS_DENIED The authenticating user did not have access to the specified user's funding sources.
404 ERROR_NOT_FOUND user The specified user did not exist.
500 ACT_OF_GOD An unknown error occurred.

Retrieving A Funding Source

This request requires only authentication if it is run against a FundingSource owned by the authenticating User. If the request is run against a FundingSource owned by another User, the request requires administrative credentials.

Request Format

Endpoint

GET /users/{username}/funding_sources/{id}

Response Format

Header

The Content-Type of this request will be funding_sources/encoding. For example, when returned in JSON encoding (the only option available in version 1), the Content-Type will be funding_sources/json.

Body

This request returns a FundingSources resource, containing a property for each FundingSource provider. Each FundingSource provider property's value is a list of the FundingSource resources that were retrieved for that provider.

{
  "code": 200,
  "msg": "Successfully retrieved funding sources",
  "funding_sources": {
    "stripe": [
      {
        // See the Stripe Resource for the contents of this part
      }
    ]
  }
}

Errors

Status Code Field Explanation
400 ERROR_MISSING_PARAM username The username query parameter was not set.
403 ERROR_ACCESS_DENIED The authenticating user did not have access to the specified user's funding sources.
404 ERROR_NOT_FOUND user The specified user did not exist.
500 ACT_OF_GOD An unknown error occurred.

Updating A Funding Source

This request requires only authentication if it is run against a FundingSource owned by the authenticating User. If the request is run against a FundingSource owned by another User, the request requires administrative credentials.

Request Format

Endpoint

PUT /users/{username}/funding_sources/{id}

Request Headers

Because this request has a body, the Content-Type and Content-Length headers need to be set.

Request Body

The request body should be a specific provider object, e.g. a Stripe Resource. Only the Mutable Properties of the FundingSource will be used; the rest will be ignored. If more than one resource is provided, an error will be thrown.

A sample request body:

{
  "funding_sources": {
    "stripe": [
      {
        "nickname": "Stripe"
      }
    ]
  }
}

Response Format

Header

The Content-Type of this request will be funding_sources/encoding. For example, when returned in JSON encoding (the only option available in version 1), the Content-Type will be funding_sources/json.

Body

This request returns a FundingSources resource, containing a property for each FundingSource provider. Each FundingSource provider property's value is a list of the FundingSource resources that were updated for that provider.

{
  "code": 200,
  "msg": "Successfully updated funding sources",
  "funding_sources": {
    "stripe": [
      {
        // See the Stripe Resource for the contents of this part
      }
    ]
  }
}

Errors

Status Code Field Explanation
400 ERROR_MISSING_PARAM username The username query parameter was not set.
403 ERROR_ACCESS_DENIED The authenticating user did not have access to the specified user's funding sources.
404 ERROR_NOT_FOUND user The specified user did not exist.
500 ACT_OF_GOD An unknown error occurred.

Deleting A Funding Source

This request requires only authentication if it is run against a FundingSource owned by the authenticating User. If the request is run against a FundingSource owned by another User, the request requires administrative credentials.

Request Format

Endpoint

DELETE /users/{username}/funding_sources/{id}

Response Format

Header

The Content-Type of this request will be funding_sources/encoding. For example, when returned in JSON encoding (the only option available in version 1), the Content-Type will be funding_sources/json.

Body

This request returns a FundingSources resource, containing a property for each FundingSource provider. Each FundingSource provider property's value is a list of the FundingSource resources that were removed for that provider.

{
  "code": 200,
  "msg": "Successfully removed funding sources",
  "funding_sources": {
    "stripe": [
      {
        // See the Stripe Resource for the contents of this part
      }
    ]
  }
}

Errors

Status Code Field Explanation
400 ERROR_MISSING_PARAM username The username query parameter was not set.
403 ERROR_ACCESS_DENIED The authenticating user did not have access to the specified user's funding sources.
404 ERROR_NOT_FOUND user The specified user did not exist.
500 ACT_OF_GOD An unknown error occurred.