Class: PaypalServerSdk::LineItem

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/paypal_server_sdk/models/line_item.rb

Overview

The line items for this purchase. If your merchant account has been configured for Level 3 processing this field will be passed to the processor on your behalf.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(name:, quantity:, description: SKIP, sku: SKIP, url: SKIP, image_url: SKIP, upc: SKIP, billing_plan: SKIP, unit_amount: SKIP, tax: SKIP, commodity_code: SKIP, discount_amount: SKIP, total_amount: SKIP, unit_of_measure: SKIP) ⇒ LineItem

Returns a new instance of LineItem.



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'lib/paypal_server_sdk/models/line_item.rb', line 128

def initialize(name:, quantity:, description: SKIP, sku: SKIP, url: SKIP,
               image_url: SKIP, upc: SKIP, billing_plan: SKIP,
               unit_amount: SKIP, tax: SKIP, commodity_code: SKIP,
               discount_amount: SKIP, total_amount: SKIP,
               unit_of_measure: SKIP)
  @name = name
  @quantity = quantity
  @description = description unless description == SKIP
  @sku = sku unless sku == SKIP
  @url = url unless url == SKIP
  @image_url = image_url unless image_url == SKIP
  @upc = upc unless upc == SKIP
  @billing_plan = billing_plan unless billing_plan == SKIP
  @unit_amount = unit_amount unless unit_amount == SKIP
  @tax = tax unless tax == SKIP
  @commodity_code = commodity_code unless commodity_code == SKIP
  @discount_amount = discount_amount unless discount_amount == SKIP
  @total_amount = total_amount unless total_amount == SKIP
  @unit_of_measure = unit_of_measure unless unit_of_measure == SKIP
end

Instance Attribute Details

#billing_planOrderBillingPlan

Metadata for merchant-managed recurring billing plans. Valid only during the saved payment method token or billing agreement creation.

Returns:



47
48
49
# File 'lib/paypal_server_sdk/models/line_item.rb', line 47

def billing_plan
  @billing_plan
end

#commodity_codeString

Code used to classify items purchased and track the total amount spent across various categories of products and services. Different corporate purchasing organizations may use different standards, but the United Nations Standard Products and Services Code (UNSPSC) is frequently used.

Returns:

  • (String)


64
65
66
# File 'lib/paypal_server_sdk/models/line_item.rb', line 64

def commodity_code
  @commodity_code
end

#descriptionString

The detailed item description.

Returns:

  • (String)


24
25
26
# File 'lib/paypal_server_sdk/models/line_item.rb', line 24

def description
  @description
end

#discount_amountMoney

The currency and amount for a financial transaction, such as a balance or payment due.

Returns:



69
70
71
# File 'lib/paypal_server_sdk/models/line_item.rb', line 69

def discount_amount
  @discount_amount
end

#image_urlString

The URL of the item’s image. File type and size restrictions apply. An image that violates these restrictions will not be honored.

Returns:

  • (String)


38
39
40
# File 'lib/paypal_server_sdk/models/line_item.rb', line 38

def image_url
  @image_url
end

#nameString

The item name or title.

Returns:

  • (String)


16
17
18
# File 'lib/paypal_server_sdk/models/line_item.rb', line 16

def name
  @name
end

#quantityString

The item quantity. Must be a whole number.

Returns:

  • (String)


20
21
22
# File 'lib/paypal_server_sdk/models/line_item.rb', line 20

def quantity
  @quantity
end

#skuString

The stock keeping unit (SKU) for the item.

Returns:

  • (String)


28
29
30
# File 'lib/paypal_server_sdk/models/line_item.rb', line 28

def sku
  @sku
end

#taxMoney

The currency and amount for a financial transaction, such as a balance or payment due.

Returns:



57
58
59
# File 'lib/paypal_server_sdk/models/line_item.rb', line 57

def tax
  @tax
end

#total_amountMoney

The currency and amount for a financial transaction, such as a balance or payment due.

Returns:



74
75
76
# File 'lib/paypal_server_sdk/models/line_item.rb', line 74

def total_amount
  @total_amount
end

#unit_amountMoney

The currency and amount for a financial transaction, such as a balance or payment due.

Returns:



52
53
54
# File 'lib/paypal_server_sdk/models/line_item.rb', line 52

def unit_amount
  @unit_amount
end

#unit_of_measureString

Unit of measure is a standard used to express the magnitude of a quantity in international trade. Most commonly used (but not limited to) examples are: Acre (ACR), Ampere (AMP), Centigram (CGM), Centimetre (CMT), Cubic inch (INQ), Cubic metre (MTQ), Fluid ounce (OZA), Foot (FOT), Hour (HUR), Item (ITM), Kilogram (KGM), Kilometre (KMT), Kilowatt (KWT), Liquid gallon (GLL), Liter (LTR), Pounds (LBS), Square foot (FTK).

Returns:

  • (String)


83
84
85
# File 'lib/paypal_server_sdk/models/line_item.rb', line 83

def unit_of_measure
  @unit_of_measure
end

#upcUniversalProductCode

The Universal Product Code of the item.



42
43
44
# File 'lib/paypal_server_sdk/models/line_item.rb', line 42

def upc
  @upc
end

#urlString

The URL to the item being purchased. Visible to buyer and used in buyer experiences.

Returns:

  • (String)


33
34
35
# File 'lib/paypal_server_sdk/models/line_item.rb', line 33

def url
  @url
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/paypal_server_sdk/models/line_item.rb', line 150

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  quantity = hash.key?('quantity') ? hash['quantity'] : nil
  description = hash.key?('description') ? hash['description'] : SKIP
  sku = hash.key?('sku') ? hash['sku'] : SKIP
  url = hash.key?('url') ? hash['url'] : SKIP
  image_url = hash.key?('image_url') ? hash['image_url'] : SKIP
  upc = UniversalProductCode.from_hash(hash['upc']) if hash['upc']
  billing_plan = OrderBillingPlan.from_hash(hash['billing_plan']) if hash['billing_plan']
  unit_amount = Money.from_hash(hash['unit_amount']) if hash['unit_amount']
  tax = Money.from_hash(hash['tax']) if hash['tax']
  commodity_code =
    hash.key?('commodity_code') ? hash['commodity_code'] : SKIP
  discount_amount = Money.from_hash(hash['discount_amount']) if hash['discount_amount']
  total_amount = Money.from_hash(hash['total_amount']) if hash['total_amount']
  unit_of_measure =
    hash.key?('unit_of_measure') ? hash['unit_of_measure'] : SKIP

  # Create object from extracted values.
  LineItem.new(name: name,
               quantity: quantity,
               description: description,
               sku: sku,
               url: url,
               image_url: image_url,
               upc: upc,
               billing_plan: billing_plan,
               unit_amount: unit_amount,
               tax: tax,
               commodity_code: commodity_code,
               discount_amount: discount_amount,
               total_amount: total_amount,
               unit_of_measure: unit_of_measure)
end

.namesObject

A mapping from model property names to API property names.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/paypal_server_sdk/models/line_item.rb', line 86

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['quantity'] = 'quantity'
  @_hash['description'] = 'description'
  @_hash['sku'] = 'sku'
  @_hash['url'] = 'url'
  @_hash['image_url'] = 'image_url'
  @_hash['upc'] = 'upc'
  @_hash['billing_plan'] = 'billing_plan'
  @_hash['unit_amount'] = 'unit_amount'
  @_hash['tax'] = 'tax'
  @_hash['commodity_code'] = 'commodity_code'
  @_hash['discount_amount'] = 'discount_amount'
  @_hash['total_amount'] = 'total_amount'
  @_hash['unit_of_measure'] = 'unit_of_measure'
  @_hash
end

.nullablesObject

An array for nullable fields



124
125
126
# File 'lib/paypal_server_sdk/models/line_item.rb', line 124

def self.nullables
  []
end

.optionalsObject

An array for optional fields



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/paypal_server_sdk/models/line_item.rb', line 106

def self.optionals
  %w[
    description
    sku
    url
    image_url
    upc
    billing_plan
    unit_amount
    tax
    commodity_code
    discount_amount
    total_amount
    unit_of_measure
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



199
200
201
202
203
204
205
206
207
# File 'lib/paypal_server_sdk/models/line_item.rb', line 199

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name.inspect}, quantity: #{@quantity.inspect}, description:"\
  " #{@description.inspect}, sku: #{@sku.inspect}, url: #{@url.inspect}, image_url:"\
  " #{@image_url.inspect}, upc: #{@upc.inspect}, billing_plan: #{@billing_plan.inspect},"\
  " unit_amount: #{@unit_amount.inspect}, tax: #{@tax.inspect}, commodity_code:"\
  " #{@commodity_code.inspect}, discount_amount: #{@discount_amount.inspect}, total_amount:"\
  " #{@total_amount.inspect}, unit_of_measure: #{@unit_of_measure.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



189
190
191
192
193
194
195
196
# File 'lib/paypal_server_sdk/models/line_item.rb', line 189

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} name: #{@name}, quantity: #{@quantity}, description: #{@description}, sku:"\
  " #{@sku}, url: #{@url}, image_url: #{@image_url}, upc: #{@upc}, billing_plan:"\
  " #{@billing_plan}, unit_amount: #{@unit_amount}, tax: #{@tax}, commodity_code:"\
  " #{@commodity_code}, discount_amount: #{@discount_amount}, total_amount: #{@total_amount},"\
  " unit_of_measure: #{@unit_of_measure}>"
end