Class: PaypalServerSdk::PurchaseUnitRequest

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

Overview

The purchase unit request. Includes required information for the payment contract.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(amount:, reference_id: SKIP, payee: SKIP, payment_instruction: SKIP, description: SKIP, custom_id: SKIP, invoice_id: SKIP, soft_descriptor: SKIP, items: SKIP, shipping: SKIP, supplementary_data: SKIP) ⇒ PurchaseUnitRequest

Returns a new instance of PurchaseUnitRequest.



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/paypal_server_sdk/models/purchase_unit_request.rb', line 133

def initialize(amount:, reference_id: SKIP, payee: SKIP,
               payment_instruction: SKIP, description: SKIP,
               custom_id: SKIP, invoice_id: SKIP, soft_descriptor: SKIP,
               items: SKIP, shipping: SKIP, supplementary_data: SKIP)
  @reference_id = reference_id unless reference_id == SKIP
  @amount = amount
  @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
  @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
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.<br/>If you specify ‘amount.breakdown`, the amount equals `item_total` plus `tax_total` plus `shipping` plus `handling` plus `insurance` minus `shipping_discount` minus discount.<br/>The amount must be a positive number. For listed of supported currencies and decimal precision, see the PayPal REST APIs <a href=“/docs/integration/direct/rest/currency-codes/”>Currency Codes</a>.

Returns:



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

def amount
  @amount
end

#custom_idString

The API caller-provided external ID. Used to reconcile client transactions with PayPal transactions. Appears in transaction and settlement reports but is not visible to the payer.

Returns:

  • (String)


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

def custom_id
  @custom_id
end

#descriptionString

The purchase description. The maximum length of the character is dependent on the type of characters used. The character length is specified assuming a US ASCII character. Depending on type of character; (e.g. accented character, Japanese characters) the number of characters that that can be specified as input might not equal the permissible max length.

Returns:

  • (String)


48
49
50
# File 'lib/paypal_server_sdk/models/purchase_unit_request.rb', line 48

def description
  @description
end

#invoice_idString

The API caller-provided external invoice number for this order. Appears in both the payer’s transaction history and the emails that the payer receives.

Returns:

  • (String)


60
61
62
# File 'lib/paypal_server_sdk/models/purchase_unit_request.rb', line 60

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_request.rb', line 83

def items
  @items
end

#payeePayee

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_request.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_request.rb', line 40

def payment_instruction
  @payment_instruction
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`.

Returns:

  • (String)


18
19
20
# File 'lib/paypal_server_sdk/models/purchase_unit_request.rb', line 18

def reference_id
  @reference_id
end

#shippingShippingDetails

The shipping details.

Returns:



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

def shipping
  @shipping
end

#soft_descriptorString

The soft descriptor is the dynamic text used to construct the statement descriptor that appears on a payer’s card statement.
If an Order is paid using the “PayPal Wallet”, the statement descriptor will appear in following format on the payer’s card statement: <var>PAYPAL_prefix</var>+(space)+<var>merchant_descriptor</var>+(spa ce)+ <var>soft_descriptor</var><blockquote><strong>Note:</strong> The merchant descriptor is the descriptor of the merchant’s payment receiving preferences which can be seen by logging into the merchant account www.sandbox.paypal.com/businessprofile/settings/info/edit</blockqu ote>The PAYPAL prefix uses 8 characters. Only the first 22 characters will be displayed in the statement.
For example, if:<ul><li>The PayPal prefix toggle is PAYPAL *.</li><li>The merchant descriptor in the profile is Janes Gift.</li><li>The soft descriptor is 800-123-1234.</li></ul>Then, the statement descriptor on the card is PAYPAL * Janes Gift 80.

Returns:

  • (String)


79
80
81
# File 'lib/paypal_server_sdk/models/purchase_unit_request.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_request.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.



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
187
188
189
190
191
# File 'lib/paypal_server_sdk/models/purchase_unit_request.rb', line 151

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount = AmountWithBreakdown.from_hash(hash['amount']) if hash['amount']
  reference_id = hash.key?('reference_id') ? hash['reference_id'] : SKIP
  payee = Payee.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
  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 = ShippingDetails.from_hash(hash['shipping']) if hash['shipping']
  supplementary_data = SupplementaryData.from_hash(hash['supplementary_data']) if
    hash['supplementary_data']

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

.namesObject

A mapping from model property names to API property names.



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# File 'lib/paypal_server_sdk/models/purchase_unit_request.rb', line 96

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['soft_descriptor'] = 'soft_descriptor'
  @_hash['items'] = 'items'
  @_hash['shipping'] = 'shipping'
  @_hash['supplementary_data'] = 'supplementary_data'
  @_hash
end

.nullablesObject

An array for nullable fields



129
130
131
# File 'lib/paypal_server_sdk/models/purchase_unit_request.rb', line 129

def self.nullables
  []
end

.optionalsObject

An array for optional fields



113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/paypal_server_sdk/models/purchase_unit_request.rb', line 113

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