Class: Stripe::Margin

Inherits:
APIResource show all
Extended by:
APIOperations::Create, APIOperations::List
Includes:
APIOperations::Save
Defined in:
lib/stripe/resources/margin.rb

Overview

A (partner) margin represents a specific discount distributed in partner reseller programs to business partners who resell products and services and earn a discount (margin) for doing so.

Defined Under Namespace

Classes: CreateParams, ListParams, RetrieveParams, UpdateParams

Constant Summary collapse

OBJECT_NAME =
"margin"

Constants inherited from StripeObject

StripeObject::RESERVED_FIELD_NAMES

Instance Attribute Summary collapse

Attributes inherited from APIResource

#save_with_parent

Attributes inherited from StripeObject

#last_response

Class Method Summary collapse

Methods included from APIOperations::Create

create

Methods included from APIOperations::List

list

Methods included from APIOperations::Save

included, #save

Methods inherited from APIResource

class_name, custom_method, #refresh, #request_stripe_object, resource_url, #resource_url, retrieve, save_nested_resource

Methods included from APIOperations::Request

included

Methods inherited from StripeObject

#==, #[], #[]=, additive_object_param, additive_object_param?, #as_json, construct_from, #deleted?, #dirty!, #each, #eql?, #hash, #initialize, #inspect, #keys, #marshal_dump, #marshal_load, protected_fields, #serialize_params, #to_hash, #to_json, #to_s, #update_attributes, #values

Constructor Details

This class inherits a constructor from Stripe::StripeObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Stripe::StripeObject

Instance Attribute Details

#activeObject (readonly)

Whether the margin can be applied to invoices, invoice items, or invoice line items. Defaults to ‘true`.



86
87
88
# File 'lib/stripe/resources/margin.rb', line 86

def active
  @active
end

#createdObject (readonly)

Time at which the object was created. Measured in seconds since the Unix epoch.



88
89
90
# File 'lib/stripe/resources/margin.rb', line 88

def created
  @created
end

#idObject (readonly)

Unique identifier for the object.



90
91
92
# File 'lib/stripe/resources/margin.rb', line 90

def id
  @id
end

#livemodeObject (readonly)

Has the value ‘true` if the object exists in live mode or the value `false` if the object exists in test mode.



92
93
94
# File 'lib/stripe/resources/margin.rb', line 92

def livemode
  @livemode
end

#metadataObject (readonly)

Set of [key-value pairs](stripe.com/docs/api/metadata) that you can attach to an object. This can be useful for storing additional information about the object in a structured format.



94
95
96
# File 'lib/stripe/resources/margin.rb', line 94

def 
  @metadata
end

#nameObject (readonly)

Name of the margin that’s displayed on, for example, invoices.



96
97
98
# File 'lib/stripe/resources/margin.rb', line 96

def name
  @name
end

#objectObject (readonly)

String representing the object’s type. Objects of the same type share the same value.



98
99
100
# File 'lib/stripe/resources/margin.rb', line 98

def object
  @object
end

#percent_offObject (readonly)

Percent that will be taken off the subtotal before tax (after all other discounts and promotions) of any invoice to which the margin is applied.



100
101
102
# File 'lib/stripe/resources/margin.rb', line 100

def percent_off
  @percent_off
end

#updatedObject (readonly)

Time at which the object was last updated. Measured in seconds since the Unix epoch.



102
103
104
# File 'lib/stripe/resources/margin.rb', line 102

def updated
  @updated
end

Class Method Details

.create(params = {}, opts = {}) ⇒ Object

Create a margin object to be used with invoices, invoice items, and invoice line items for a customer to represent a partner discount. A margin has a percent_off which is the percent that will be taken off the subtotal after all items and other discounts and promotions) of any invoices for a customer. Calculation of prorations do not include any partner margins applied on the original invoice item.



105
106
107
# File 'lib/stripe/resources/margin.rb', line 105

def self.create(params = {}, opts = {})
  request_stripe_object(method: :post, path: "/v1/billing/margins", params: params, opts: opts)
end

.list(params = {}, opts = {}) ⇒ Object

Retrieve a list of your margins.



110
111
112
# File 'lib/stripe/resources/margin.rb', line 110

def self.list(params = {}, opts = {})
  request_stripe_object(method: :get, path: "/v1/billing/margins", params: params, opts: opts)
end

.object_nameObject



13
14
15
# File 'lib/stripe/resources/margin.rb', line 13

def self.object_name
  "margin"
end

.update(id, params = {}, opts = {}) ⇒ Object

Update the specified margin object. Certain fields of the margin object are not editable.



115
116
117
118
119
120
121
122
# File 'lib/stripe/resources/margin.rb', line 115

def self.update(id, params = {}, opts = {})
  request_stripe_object(
    method: :post,
    path: format("/v1/billing/margins/%<id>s", { id: CGI.escape(id) }),
    params: params,
    opts: opts
  )
end