Skip to content

Latest commit

 

History

History
557 lines (385 loc) · 16 KB

subscriptions.md

File metadata and controls

557 lines (385 loc) · 16 KB

Subscriptions

subscriptions_api = client.subscriptions

Class Name

SubscriptionsApi

Methods

Create Subscription

Enrolls a customer in a subscription.

If you provide a card on file in the request, Square charges the card for the subscription. Otherwise, Square sends an invoice to the customer's email address. The subscription starts immediately, unless the request includes the optional start_date. Each individual subscription is associated with a particular location.

For more information, see Create a subscription.

def create_subscription(body:)

Parameters

Parameter Type Tags Description
body Create Subscription Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type Create Subscription Response Hash.

Example Usage

body = {
  :location_id => 'S8GWD5R9QB376',
  :customer_id => 'CHFGVKYY8RSV93M5KCYTG4PN0G',
  :idempotency_key => '8193148c-9586-11e6-99f9-28cfe92138cf',
  :plan_variation_id => '6JHXF3B2CW3YKHDV4XEM674H',
  :start_date => '2023-06-20',
  :card_id => 'ccof:qy5x8hHGYsgLrp4Q4GB',
  :timezone => 'America/Los_Angeles',
  :source => {
    :name => 'My Application'
  },
  :phases => [
    {
      :ordinal => 0,
      :order_template_id => 'U2NaowWxzXwpsZU697x7ZHOAnCNZY'
    }
  ]
}


result = subscriptions_api.create_subscription(body: body)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Bulk Swap Plan

Schedules a plan variation change for all active subscriptions under a given plan variation. For more information, see Swap Subscription Plan Variations.

def bulk_swap_plan(body:)

Parameters

Parameter Type Tags Description
body Bulk Swap Plan Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type Bulk Swap Plan Response Hash.

Example Usage

body = {
  :new_plan_variation_id => 'FQ7CDXXWSLUJRPM3GFJSJGZ7',
  :old_plan_variation_id => '6JHXF3B2CW3YKHDV4XEM674H',
  :location_id => 'S8GWD5R9QB376'
}


result = subscriptions_api.bulk_swap_plan(body: body)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Search Subscriptions

Searches for subscriptions.

Results are ordered chronologically by subscription creation date. If the request specifies more than one location ID, the endpoint orders the result by location ID, and then by creation date within each location. If no locations are given in the query, all locations are searched.

You can also optionally specify customer_ids to search by customer. If left unset, all customers associated with the specified locations are returned. If the request specifies customer IDs, the endpoint orders results first by location, within location by customer ID, and within customer by subscription creation date.

def search_subscriptions(body:)

Parameters

Parameter Type Tags Description
body Search Subscriptions Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type Search Subscriptions Response Hash.

Example Usage

body = {
  :query => {
    :filter => {
      :customer_ids => [
        'CHFGVKYY8RSV93M5KCYTG4PN0G'
      ],
      :location_ids => [
        'S8GWD5R9QB376'
      ],
      :source_names => [
        'My App'
      ]
    }
  }
}


result = subscriptions_api.search_subscriptions(body: body)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Retrieve Subscription

Retrieves a specific subscription.

def retrieve_subscription(subscription_id:,
                          include: nil)

Parameters

Parameter Type Tags Description
subscription_id String Template, Required The ID of the subscription to retrieve.
include String Query, Optional A query parameter to specify related information to be included in the response.

The supported query parameter values are:

- actions: to include scheduled actions on the targeted subscription.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type Retrieve Subscription Response Hash.

Example Usage

subscription_id = 'subscription_id0'


result = subscriptions_api.retrieve_subscription(subscription_id: subscription_id)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Update Subscription

Updates a subscription by modifying or clearing subscription field values. To clear a field, set its value to null.

def update_subscription(subscription_id:,
                        body:)

Parameters

Parameter Type Tags Description
subscription_id String Template, Required The ID of the subscription to update.
body Update Subscription Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type Update Subscription Response Hash.

Example Usage

subscription_id = 'subscription_id0'

body = {
  :subscription => {
    :canceled_date => 'canceled_date6',
    :card_id => '{NEW CARD ID}'
  }
}


result = subscriptions_api.update_subscription(
  subscription_id: subscription_id,
  body: body
)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Delete Subscription Action

Deletes a scheduled action for a subscription.

def delete_subscription_action(subscription_id:,
                               action_id:)

Parameters

Parameter Type Tags Description
subscription_id String Template, Required The ID of the subscription the targeted action is to act upon.
action_id String Template, Required The ID of the targeted action to be deleted.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type Delete Subscription Action Response Hash.

Example Usage

subscription_id = 'subscription_id0'

action_id = 'action_id6'


result = subscriptions_api.delete_subscription_action(
  subscription_id: subscription_id,
  action_id: action_id
)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Change Billing Anchor Date

Changes the billing anchor date for a subscription.

def change_billing_anchor_date(subscription_id:,
                               body:)

Parameters

Parameter Type Tags Description
subscription_id String Template, Required The ID of the subscription to update the billing anchor date.
body Change Billing Anchor Date Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type Change Billing Anchor Date Response Hash.

Example Usage

subscription_id = 'subscription_id0'

body = {
  :monthly_billing_anchor_date => 1
}


result = subscriptions_api.change_billing_anchor_date(
  subscription_id: subscription_id,
  body: body
)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Cancel Subscription

Schedules a CANCEL action to cancel an active subscription. This sets the canceled_date field to the end of the active billing period. After this date, the subscription status changes from ACTIVE to CANCELED.

def cancel_subscription(subscription_id:)

Parameters

Parameter Type Tags Description
subscription_id String Template, Required The ID of the subscription to cancel.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type Cancel Subscription Response Hash.

Example Usage

subscription_id = 'subscription_id0'


result = subscriptions_api.cancel_subscription(subscription_id: subscription_id)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

List Subscription Events

Lists all events for a specific subscription.

def list_subscription_events(subscription_id:,
                             cursor: nil,
                             limit: nil)

Parameters

Parameter Type Tags Description
subscription_id String Template, Required The ID of the subscription to retrieve the events for.
cursor String Query, Optional When the total number of resulting subscription events exceeds the limit of a paged response,
specify the cursor returned from a preceding response here to fetch the next set of results.
If the cursor is unset, the response contains the last page of the results.

For more information, see Pagination.
limit Integer Query, Optional The upper limit on the number of subscription events to return
in a paged response.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type List Subscription Events Response Hash.

Example Usage

subscription_id = 'subscription_id0'


result = subscriptions_api.list_subscription_events(subscription_id: subscription_id)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Pause Subscription

Schedules a PAUSE action to pause an active subscription.

def pause_subscription(subscription_id:,
                       body:)

Parameters

Parameter Type Tags Description
subscription_id String Template, Required The ID of the subscription to pause.
body Pause Subscription Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type Pause Subscription Response Hash.

Example Usage

subscription_id = 'subscription_id0'

body = {}


result = subscriptions_api.pause_subscription(
  subscription_id: subscription_id,
  body: body
)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Resume Subscription

Schedules a RESUME action to resume a paused or a deactivated subscription.

def resume_subscription(subscription_id:,
                        body:)

Parameters

Parameter Type Tags Description
subscription_id String Template, Required The ID of the subscription to resume.
body Resume Subscription Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type Resume Subscription Response Hash.

Example Usage

subscription_id = 'subscription_id0'

body = {}


result = subscriptions_api.resume_subscription(
  subscription_id: subscription_id,
  body: body
)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end

Swap Plan

Schedules a SWAP_PLAN action to swap a subscription plan variation in an existing subscription. For more information, see Swap Subscription Plan Variations.

def swap_plan(subscription_id:,
              body:)

Parameters

Parameter Type Tags Description
subscription_id String Template, Required The ID of the subscription to swap the subscription plan for.
body Swap Plan Request Hash Body, Required An object containing the fields to POST for the request.

See the corresponding object definition for field details.

Response Type

This method returns a \ApiResponse instance. The data property in this instance returns the response data which is of type Swap Plan Response Hash.

Example Usage

subscription_id = 'subscription_id0'

body = {
  :new_plan_variation_id => 'FQ7CDXXWSLUJRPM3GFJSJGZ7',
  :phases => [
    {
      :ordinal => 0,
      :order_template_id => 'uhhnjH9osVv3shUADwaC0b3hNxQZY'
    }
  ]
}


result = subscriptions_api.swap_plan(
  subscription_id: subscription_id,
  body: body
)

if result.success?
  puts result.data
elsif result.error?
  warn result.errors
end