Class: PaypalServerSdk::Item

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

Overview

The details for the items to be purchased.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(name:, unit_amount:, quantity:, tax: SKIP, description: SKIP, sku: SKIP, url: SKIP, category: SKIP, image_url: SKIP, upc: SKIP) ⇒ Item

Returns a new instance of Item.



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

def initialize(name:, unit_amount:, quantity:, tax: SKIP, description: SKIP,
               sku: SKIP, url: SKIP, category: SKIP, image_url: SKIP,
               upc: SKIP)
  @name = name
  @unit_amount = unit_amount
  @tax = tax unless tax == SKIP
  @quantity = quantity
  @description = description unless description == SKIP
  @sku = sku unless sku == SKIP
  @url = url unless url == SKIP
  @category = category unless category == SKIP
  @image_url = image_url unless image_url == SKIP
  @upc = upc unless upc == SKIP
end

Instance Attribute Details

#categoryItemCategory

The item category type.

Returns:



45
46
47
# File 'lib/paypal_server_sdk/models/item.rb', line 45

def category
  @category
end

#descriptionString

The detailed item description.

Returns:

  • (String)


32
33
34
# File 'lib/paypal_server_sdk/models/item.rb', line 32

def description
  @description
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)


50
51
52
# File 'lib/paypal_server_sdk/models/item.rb', line 50

def image_url
  @image_url
end

#nameString

The item name or title.

Returns:

  • (String)


14
15
16
# File 'lib/paypal_server_sdk/models/item.rb', line 14

def name
  @name
end

#quantityString

The item quantity. Must be a whole number.

Returns:

  • (String)


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

def quantity
  @quantity
end

#skuString

The stock keeping unit (SKU) for the item.

Returns:

  • (String)


36
37
38
# File 'lib/paypal_server_sdk/models/item.rb', line 36

def sku
  @sku
end

#taxMoney

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

Returns:



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

def tax
  @tax
end

#unit_amountMoney

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

Returns:



19
20
21
# File 'lib/paypal_server_sdk/models/item.rb', line 19

def unit_amount
  @unit_amount
end

#upcUniversalProductCode

The Universal Product Code of the item.



54
55
56
# File 'lib/paypal_server_sdk/models/item.rb', line 54

def upc
  @upc
end

#urlString

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

Returns:

  • (String)


41
42
43
# File 'lib/paypal_server_sdk/models/item.rb', line 41

def url
  @url
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/paypal_server_sdk/models/item.rb', line 106

def self.from_hash(hash)
  return nil unless hash

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

  # Create object from extracted values.
  Item.new(name: name,
           unit_amount: unit_amount,
           quantity: quantity,
           tax: tax,
           description: description,
           sku: sku,
           url: url,
           category: category,
           image_url: image_url,
           upc: upc)
end

.namesObject

A mapping from model property names to API property names.



57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/paypal_server_sdk/models/item.rb', line 57

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

.nullablesObject

An array for nullable fields



86
87
88
# File 'lib/paypal_server_sdk/models/item.rb', line 86

def self.nullables
  []
end

.optionalsObject

An array for optional fields



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/paypal_server_sdk/models/item.rb', line 73

def self.optionals
  %w[
    tax
    description
    sku
    url
    category
    image_url
    upc
  ]
end