Class: PaypalServerSdk::PlanRequest

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

Overview

The create plan 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(product_id:, name:, billing_cycles:, payment_preferences:, status: PlanRequestStatus::ACTIVE, description: SKIP, merchant_preferences: SKIP, taxes: SKIP, quantity_supported: false) ⇒ PlanRequest

Returns a new instance of PlanRequest.



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

def initialize(product_id:, name:, billing_cycles:, payment_preferences:,
               status: PlanRequestStatus::ACTIVE, description: SKIP,
               merchant_preferences: SKIP, taxes: SKIP,
               quantity_supported: false)
  @product_id = product_id
  @name = name
  @status = status unless status == SKIP
  @description = description unless description == SKIP
  @billing_cycles = billing_cycles
  @payment_preferences = payment_preferences
  @merchant_preferences = merchant_preferences unless merchant_preferences == SKIP
  @taxes = taxes unless taxes == SKIP
  @quantity_supported = quantity_supported unless quantity_supported == SKIP
end

Instance Attribute Details

#billing_cyclesArray[SubscriptionBillingCycle]

An array of billing cycles for trial billing and regular billing. A plan can have at most two trial cycles and only one regular cycle.

Returns:



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

def billing_cycles
  @billing_cycles
end

#descriptionString

The detailed description of the plan.

Returns:

  • (String)


27
28
29
# File 'lib/paypal_server_sdk/models/plan_request.rb', line 27

def description
  @description
end

#merchant_preferencesMerchantPreferences

The merchant preferences for a subscription.

Returns:



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

def merchant_preferences
  @merchant_preferences
end

#nameString

The plan name.

Returns:

  • (String)


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

def name
  @name
end

#payment_preferencesPaymentPreferences

The payment preferences for a subscription.

Returns:



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

def payment_preferences
  @payment_preferences
end

#product_idString

The ID of the product created through Catalog Products API.

Returns:

  • (String)


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

def product_id
  @product_id
end

#quantity_supportedTrueClass | FalseClass

Indicates whether you can subscribe to this plan by providing a quantity for the goods or service.

Returns:

  • (TrueClass | FalseClass)


49
50
51
# File 'lib/paypal_server_sdk/models/plan_request.rb', line 49

def quantity_supported
  @quantity_supported
end

#statusPlanRequestStatus

The initial state of the plan. Allowed input values are CREATED and ACTIVE.

Returns:



23
24
25
# File 'lib/paypal_server_sdk/models/plan_request.rb', line 23

def status
  @status
end

#taxesTaxes

The tax details.

Returns:



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

def taxes
  @taxes
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



98
99
100
101
102
103
104
105
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
133
# File 'lib/paypal_server_sdk/models/plan_request.rb', line 98

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  product_id = hash.key?('product_id') ? hash['product_id'] : nil
  name = hash.key?('name') ? hash['name'] : nil
  # Parameter is an array, so we need to iterate through it

  billing_cycles = nil
  unless hash['billing_cycles'].nil?
    billing_cycles = []
    hash['billing_cycles'].each do |structure|
      billing_cycles << (SubscriptionBillingCycle.from_hash(structure) if structure)
    end
  end

  billing_cycles = nil unless hash.key?('billing_cycles')
  payment_preferences = PaymentPreferences.from_hash(hash['payment_preferences']) if
    hash['payment_preferences']
  status = hash['status'] ||= PlanRequestStatus::ACTIVE
  description = hash.key?('description') ? hash['description'] : SKIP
  merchant_preferences = MerchantPreferences.from_hash(hash['merchant_preferences']) if
    hash['merchant_preferences']
  taxes = Taxes.from_hash(hash['taxes']) if hash['taxes']
  quantity_supported = hash['quantity_supported'] ||= false

  # Create object from extracted values.

  PlanRequest.new(product_id: product_id,
                  name: name,
                  billing_cycles: billing_cycles,
                  payment_preferences: payment_preferences,
                  status: status,
                  description: description,
                  merchant_preferences: merchant_preferences,
                  taxes: taxes,
                  quantity_supported: quantity_supported)
end

.namesObject

A mapping from model property names to API property names.



52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/paypal_server_sdk/models/plan_request.rb', line 52

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['product_id'] = 'product_id'
  @_hash['name'] = 'name'
  @_hash['status'] = 'status'
  @_hash['description'] = 'description'
  @_hash['billing_cycles'] = 'billing_cycles'
  @_hash['payment_preferences'] = 'payment_preferences'
  @_hash['merchant_preferences'] = 'merchant_preferences'
  @_hash['taxes'] = 'taxes'
  @_hash['quantity_supported'] = 'quantity_supported'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



67
68
69
70
71
72
73
74
75
# File 'lib/paypal_server_sdk/models/plan_request.rb', line 67

def self.optionals
  %w[
    status
    description
    merchant_preferences
    taxes
    quantity_supported
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



145
146
147
148
149
150
151
152
# File 'lib/paypal_server_sdk/models/plan_request.rb', line 145

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} product_id: #{@product_id.inspect}, name: #{@name.inspect}, status:"\
  " #{@status.inspect}, description: #{@description.inspect}, billing_cycles:"\
  " #{@billing_cycles.inspect}, payment_preferences: #{@payment_preferences.inspect},"\
  " merchant_preferences: #{@merchant_preferences.inspect}, taxes: #{@taxes.inspect},"\
  " quantity_supported: #{@quantity_supported.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



136
137
138
139
140
141
142
# File 'lib/paypal_server_sdk/models/plan_request.rb', line 136

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} product_id: #{@product_id}, name: #{@name}, status: #{@status},"\
  " description: #{@description}, billing_cycles: #{@billing_cycles}, payment_preferences:"\
  " #{@payment_preferences}, merchant_preferences: #{@merchant_preferences}, taxes: #{@taxes},"\
  " quantity_supported: #{@quantity_supported}>"
end