Class: PaypalServerSdk::PurchaseUnit

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

Overview

The purchase unit details. Used to capture required information for the payment contract.

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(reference_id: SKIP, amount: SKIP, payee: SKIP, payment_instruction: SKIP, description: SKIP, custom_id: SKIP, invoice_id: SKIP, id: SKIP, soft_descriptor: SKIP, items: SKIP, shipping: SKIP, supplementary_data: SKIP, payments: SKIP, most_recent_errors: SKIP) ⇒ PurchaseUnit

Returns a new instance of PurchaseUnit.



150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 150

def initialize(reference_id: SKIP, amount: SKIP, payee: SKIP,
               payment_instruction: SKIP, description: SKIP,
               custom_id: SKIP, invoice_id: SKIP, id: SKIP,
               soft_descriptor: SKIP, items: SKIP, shipping: SKIP,
               supplementary_data: SKIP, payments: SKIP,
               most_recent_errors: SKIP)
  @reference_id = reference_id unless reference_id == SKIP
  @amount = amount unless amount == SKIP
  @payee = payee unless payee == SKIP
  @payment_instruction = payment_instruction unless payment_instruction == SKIP
  @description = description unless description == SKIP
  @custom_id = custom_id unless custom_id == SKIP
  @invoice_id = invoice_id unless invoice_id == SKIP
  @id = id unless id == SKIP
  @soft_descriptor = soft_descriptor unless soft_descriptor == SKIP
  @items = items unless items == SKIP
  @shipping = shipping unless shipping == SKIP
  @supplementary_data = supplementary_data unless supplementary_data == SKIP
  @payments = payments unless payments == SKIP
  @most_recent_errors = most_recent_errors unless most_recent_errors == SKIP
end

Instance Attribute Details

#amountAmountWithBreakdown

The total order amount with an optional breakdown that provides details, such as the total item amount, total tax amount, shipping, handling, insurance, and discounts, if any. If you specify ‘amount.breakdown`, the amount equals `item_total` plus `tax_total` plus `shipping` plus `handling` plus `insurance` minus `shipping_discount` minus discount. The amount must be a positive number. For listed of supported currencies and decimal precision, see the PayPal REST APIs Currency Codes.

Returns:



29
30
31
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 29

def amount
  @amount
end

#custom_idString

The API caller-provided external ID. Used to reconcile API caller-initiated transactions with PayPal transactions. Appears in transaction and settlement reports.

Returns:

  • (String)


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

def custom_id
  @custom_id
end

#descriptionString

The purchase description.

Returns:

  • (String)


44
45
46
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 44

def description
  @description
end

#idString

The PayPal-generated ID for the purchase unit. This ID appears in both the payer’s transaction history and the emails that the payer receives. In addition, this ID is available in transaction and settlement reports that merchants and API callers can use to reconcile transactions. This ID is only available when an order is saved by calling v2/checkout/orders/id/save.

Returns:

  • (String)


63
64
65
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 63

def id
  @id
end

#invoice_idString

The API caller-provided external invoice ID for this order.

Returns:

  • (String)


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

def invoice_id
  @invoice_id
end

#itemsArray[Item]

An array of items that the customer purchases from the merchant.

Returns:



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

def items
  @items
end

#most_recent_errorsArray[Object]

The error reason code and description that are the reason for the most recent order decline.

Returns:

  • (Array[Object])


103
104
105
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 103

def most_recent_errors
  @most_recent_errors
end

#payeePayeeBase

The merchant who receives the funds and fulfills the order. The merchant is also known as the payee.

Returns:



34
35
36
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 34

def payee
  @payee
end

#payment_instructionPaymentInstruction

Any additional payment instructions to be consider during payment processing. This processing instruction is applicable for Capturing an order or Authorizing an Order.

Returns:



40
41
42
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 40

def payment_instruction
  @payment_instruction
end

#paymentsPaymentCollection

The collection of payments, or transactions, for a purchase unit in an order. For example, authorized payments, captured payments, and refunds.

Returns:



98
99
100
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 98

def payments
  @payments
end

#reference_idString

The API caller-provided external ID for the purchase unit. Required for multiple purchase units when you must update the order through ‘PATCH`. If you omit this value and the order contains only one purchase unit, PayPal sets this value to `default`. Note: If there are multiple purchase units, reference_id is required for each purchase unit.

Returns:

  • (String)


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

def reference_id
  @reference_id
end

#shippingShippingWithTrackingDetails

The order shipping details.



87
88
89
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 87

def shipping
  @shipping
end

#soft_descriptorString

The payment descriptor on account transactions on the customer’s credit card statement, that PayPal sends to processors. The maximum length of the soft descriptor information that you can pass in the API field is 22 characters, in the following format:22 - len(PAYPAL * (8)) - len(Descriptor in Payment Receiving Preferences of Merchant account + 1)The PAYPAL prefix uses 8 characters. The soft descriptor supports the following ASCII characters: Alphanumeric characters Dashes Asterisks Periods (.) Spaces For Wallet payments marketplace integrations: The merchant descriptor in the Payment Receiving Preferences must be the marketplace name. You can’t use the remaining space to show the customer service number. The remaining spaces can be a combination of seller name and country. For unbranded payments (Direct Card) marketplace integrations, use a combination of the seller name and phone number.

Returns:

  • (String)


79
80
81
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 79

def soft_descriptor
  @soft_descriptor
end

#supplementary_dataSupplementaryData

Supplementary data about a payment. This object passes information that can be used to improve risk assessments and processing costs, for example, by providing Level 2 and Level 3 payment data.

Returns:



93
94
95
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 93

def supplementary_data
  @supplementary_data
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 173

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  reference_id = hash.key?('reference_id') ? hash['reference_id'] : SKIP
  amount = AmountWithBreakdown.from_hash(hash['amount']) if hash['amount']
  payee = PayeeBase.from_hash(hash['payee']) if hash['payee']
  payment_instruction = PaymentInstruction.from_hash(hash['payment_instruction']) if
    hash['payment_instruction']
  description = hash.key?('description') ? hash['description'] : SKIP
  custom_id = hash.key?('custom_id') ? hash['custom_id'] : SKIP
  invoice_id = hash.key?('invoice_id') ? hash['invoice_id'] : SKIP
  id = hash.key?('id') ? hash['id'] : SKIP
  soft_descriptor =
    hash.key?('soft_descriptor') ? hash['soft_descriptor'] : SKIP
  # Parameter is an array, so we need to iterate through it
  items = nil
  unless hash['items'].nil?
    items = []
    hash['items'].each do |structure|
      items << (Item.from_hash(structure) if structure)
    end
  end

  items = SKIP unless hash.key?('items')
  shipping = ShippingWithTrackingDetails.from_hash(hash['shipping']) if hash['shipping']
  supplementary_data = SupplementaryData.from_hash(hash['supplementary_data']) if
    hash['supplementary_data']
  payments = PaymentCollection.from_hash(hash['payments']) if hash['payments']
  most_recent_errors =
    hash.key?('most_recent_errors') ? hash['most_recent_errors'] : SKIP

  # Create object from extracted values.
  PurchaseUnit.new(reference_id: reference_id,
                   amount: amount,
                   payee: payee,
                   payment_instruction: payment_instruction,
                   description: description,
                   custom_id: custom_id,
                   invoice_id: invoice_id,
                   id: id,
                   soft_descriptor: soft_descriptor,
                   items: items,
                   shipping: shipping,
                   supplementary_data: supplementary_data,
                   payments: payments,
                   most_recent_errors: most_recent_errors)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['reference_id'] = 'reference_id'
  @_hash['amount'] = 'amount'
  @_hash['payee'] = 'payee'
  @_hash['payment_instruction'] = 'payment_instruction'
  @_hash['description'] = 'description'
  @_hash['custom_id'] = 'custom_id'
  @_hash['invoice_id'] = 'invoice_id'
  @_hash['id'] = 'id'
  @_hash['soft_descriptor'] = 'soft_descriptor'
  @_hash['items'] = 'items'
  @_hash['shipping'] = 'shipping'
  @_hash['supplementary_data'] = 'supplementary_data'
  @_hash['payments'] = 'payments'
  @_hash['most_recent_errors'] = 'most_recent_errors'
  @_hash
end

.nullablesObject

An array for nullable fields



146
147
148
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 146

def self.nullables
  []
end

.optionalsObject

An array for optional fields



126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 126

def self.optionals
  %w[
    reference_id
    amount
    payee
    payment_instruction
    description
    custom_id
    invoice_id
    id
    soft_descriptor
    items
    shipping
    supplementary_data
    payments
    most_recent_errors
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



234
235
236
237
238
239
240
241
242
243
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 234

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} reference_id: #{@reference_id.inspect}, amount: #{@amount.inspect}, payee:"\
  " #{@payee.inspect}, payment_instruction: #{@payment_instruction.inspect}, description:"\
  " #{@description.inspect}, custom_id: #{@custom_id.inspect}, invoice_id:"\
  " #{@invoice_id.inspect}, id: #{@id.inspect}, soft_descriptor: #{@soft_descriptor.inspect},"\
  " items: #{@items.inspect}, shipping: #{@shipping.inspect}, supplementary_data:"\
  " #{@supplementary_data.inspect}, payments: #{@payments.inspect}, most_recent_errors:"\
  " #{@most_recent_errors.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



223
224
225
226
227
228
229
230
231
# File 'lib/paypal_server_sdk/models/purchase_unit.rb', line 223

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} reference_id: #{@reference_id}, amount: #{@amount}, payee: #{@payee},"\
  " payment_instruction: #{@payment_instruction}, description: #{@description}, custom_id:"\
  " #{@custom_id}, invoice_id: #{@invoice_id}, id: #{@id}, soft_descriptor:"\
  " #{@soft_descriptor}, items: #{@items}, shipping: #{@shipping}, supplementary_data:"\
  " #{@supplementary_data}, payments: #{@payments}, most_recent_errors:"\
  " #{@most_recent_errors}>"
end