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

#to_hash, #to_json

Constructor Details

#initialize(name:, quantity:, description: SKIP, sku: SKIP, url: SKIP, image_url: SKIP, upc: 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.



121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/paypal_server_sdk/models/line_item.rb', line 121

def initialize(name:, quantity:, description: SKIP, sku: SKIP, url: SKIP,
               image_url: SKIP, upc: 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
  @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

#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)


59
60
61
# File 'lib/paypal_server_sdk/models/line_item.rb', line 59

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:



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

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:



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

def tax
  @tax
end

#total_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 total_amount
  @total_amount
end

#unit_amountMoney

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

Returns:



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

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)


78
79
80
# File 'lib/paypal_server_sdk/models/line_item.rb', line 78

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.



141
142
143
144
145
146
147
148
149
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
# File 'lib/paypal_server_sdk/models/line_item.rb', line 141

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']
  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,
               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.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/paypal_server_sdk/models/line_item.rb', line 81

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['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



117
118
119
# File 'lib/paypal_server_sdk/models/line_item.rb', line 117

def self.nullables
  []
end

.optionalsObject

An array for optional fields



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/paypal_server_sdk/models/line_item.rb', line 100

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