Class: PaypalServerSdk::OrderRequest

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

Overview

The order request details.

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(intent:, purchase_units:, payer: SKIP, payment_source: SKIP, application_context: SKIP) ⇒ OrderRequest

Returns a new instance of OrderRequest.



64
65
66
67
68
69
70
71
# File 'lib/paypal_server_sdk/models/order_request.rb', line 64

def initialize(intent:, purchase_units:, payer: SKIP, payment_source: SKIP,
               application_context: SKIP)
  @intent = intent
  @payer = payer unless payer == SKIP
  @purchase_units = purchase_units
  @payment_source = payment_source unless payment_source == SKIP
  @application_context = application_context unless application_context == SKIP
end

Instance Attribute Details

#application_contextOrderApplicationContext

Customizes the payer experience during the approval process for the payment with PayPal. Note: Partners and Marketplaces might configure brand_name and shipping_preference during partner account setup, which overrides the request values.



37
38
39
# File 'lib/paypal_server_sdk/models/order_request.rb', line 37

def application_context
  @application_context
end

#intentCheckoutPaymentIntent

The intent to either capture payment immediately or authorize a payment for an order after order creation.



15
16
17
# File 'lib/paypal_server_sdk/models/order_request.rb', line 15

def intent
  @intent
end

#payerPayer

The intent to either capture payment immediately or authorize a payment for an order after order creation.

Returns:



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

def payer
  @payer
end

#payment_sourcePaymentSource

The payment source definition.

Returns:



30
31
32
# File 'lib/paypal_server_sdk/models/order_request.rb', line 30

def payment_source
  @payment_source
end

#purchase_unitsArray[PurchaseUnitRequest]

An array of purchase units. Each purchase unit establishes a contract between a payer and the payee. Each purchase unit represents either a full or partial order that the payer intends to purchase from the payee.

Returns:



26
27
28
# File 'lib/paypal_server_sdk/models/order_request.rb', line 26

def purchase_units
  @purchase_units
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/paypal_server_sdk/models/order_request.rb', line 74

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  intent = hash.key?('intent') ? hash['intent'] : nil
  # Parameter is an array, so we need to iterate through it
  purchase_units = nil
  unless hash['purchase_units'].nil?
    purchase_units = []
    hash['purchase_units'].each do |structure|
      purchase_units << (PurchaseUnitRequest.from_hash(structure) if structure)
    end
  end

  purchase_units = nil unless hash.key?('purchase_units')
  payer = Payer.from_hash(hash['payer']) if hash['payer']
  payment_source = PaymentSource.from_hash(hash['payment_source']) if hash['payment_source']
  application_context = OrderApplicationContext.from_hash(hash['application_context']) if
    hash['application_context']

  # Create object from extracted values.
  OrderRequest.new(intent: intent,
                   purchase_units: purchase_units,
                   payer: payer,
                   payment_source: payment_source,
                   application_context: application_context)
end

.namesObject

A mapping from model property names to API property names.



40
41
42
43
44
45
46
47
48
# File 'lib/paypal_server_sdk/models/order_request.rb', line 40

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['intent'] = 'intent'
  @_hash['payer'] = 'payer'
  @_hash['purchase_units'] = 'purchase_units'
  @_hash['payment_source'] = 'payment_source'
  @_hash['application_context'] = 'application_context'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



51
52
53
54
55
56
57
# File 'lib/paypal_server_sdk/models/order_request.rb', line 51

def self.optionals
  %w[
    payer
    payment_source
    application_context
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



110
111
112
113
114
115
# File 'lib/paypal_server_sdk/models/order_request.rb', line 110

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} intent: #{@intent.inspect}, payer: #{@payer.inspect}, purchase_units:"\
  " #{@purchase_units.inspect}, payment_source: #{@payment_source.inspect},"\
  " application_context: #{@application_context.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



103
104
105
106
107
# File 'lib/paypal_server_sdk/models/order_request.rb', line 103

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} intent: #{@intent}, payer: #{@payer}, purchase_units: #{@purchase_units},"\
  " payment_source: #{@payment_source}, application_context: #{@application_context}>"
end