Class: PaypalServerSdk::SubscriptionApplicationContext

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

Overview

The application context, which customizes the payer experience during the subscription approval process with PayPal.

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(return_url:, cancel_url:, brand_name: SKIP, locale: SKIP, shipping_preference: ExperienceContextShippingPreference::GET_FROM_FILE, user_action: ApplicationContextUserAction::SUBSCRIBE_NOW, payment_method: SKIP) ⇒ SubscriptionApplicationContext

Returns a new instance of SubscriptionApplicationContext.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/paypal_server_sdk/models/subscription_application_context.rb', line 77

def initialize(
  return_url:, cancel_url:, brand_name: SKIP, locale: SKIP,
  shipping_preference: ExperienceContextShippingPreference::GET_FROM_FILE,
  user_action: ApplicationContextUserAction::SUBSCRIBE_NOW,
  payment_method: SKIP
)
  @brand_name = brand_name unless brand_name == SKIP
  @locale = locale unless locale == SKIP
  @shipping_preference = shipping_preference unless shipping_preference == SKIP
  @user_action = user_action unless user_action == SKIP
  @payment_method = payment_method unless payment_method == SKIP
  @return_url = return_url
  @cancel_url = cancel_url
end

Instance Attribute Details

#brand_nameString

The label that overrides the business name in the PayPal account on the PayPal site.

Returns:

  • (String)


16
17
18
# File 'lib/paypal_server_sdk/models/subscription_application_context.rb', line 16

def brand_name
  @brand_name
end

#cancel_urlString

The URL where the customer is redirected after the customer cancels the payment.

Returns:

  • (String)


46
47
48
# File 'lib/paypal_server_sdk/models/subscription_application_context.rb', line 46

def cancel_url
  @cancel_url
end

#localeString

The BCP 47-formatted locale of pages that the PayPal payment experience shows. PayPal supports a five-character code. For example, ‘da-DK`, `he-IL`, `id-ID`, `ja-JP`, `no-NO`, `pt-BR`, `ru-RU`, `sv-SE`, `th-TH`, `zh-CN`, `zh-HK`, or `zh-TW`.

Returns:

  • (String)


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

def locale
  @locale
end

#payment_methodPaymentMethod

The customer and merchant payment preferences.

Returns:



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

def payment_method
  @payment_method
end

#return_urlString

The URL where the customer is redirected after the customer approves the payment.

Returns:

  • (String)


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

def return_url
  @return_url
end

#shipping_preferenceExperienceContextShippingPreference

The location from which the shipping address is derived.



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

def shipping_preference
  @shipping_preference
end

#user_actionApplicationContextUserAction

Configures the label name to ‘Continue` or `Subscribe Now` for subscription consent experience.



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

def user_action
  @user_action
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/paypal_server_sdk/models/subscription_application_context.rb', line 93

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  return_url = hash.key?('return_url') ? hash['return_url'] : nil
  cancel_url = hash.key?('cancel_url') ? hash['cancel_url'] : nil
  brand_name = hash.key?('brand_name') ? hash['brand_name'] : SKIP
  locale = hash.key?('locale') ? hash['locale'] : SKIP
  shipping_preference =
    hash['shipping_preference'] ||= ExperienceContextShippingPreference::GET_FROM_FILE
  user_action =
    hash['user_action'] ||= ApplicationContextUserAction::SUBSCRIBE_NOW
  payment_method = PaymentMethod.from_hash(hash['payment_method']) if hash['payment_method']

  # Create object from extracted values.

  SubscriptionApplicationContext.new(return_url: return_url,
                                     cancel_url: cancel_url,
                                     brand_name: brand_name,
                                     locale: locale,
                                     shipping_preference: shipping_preference,
                                     user_action: user_action,
                                     payment_method: payment_method)
end

.namesObject

A mapping from model property names to API property names.



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/paypal_server_sdk/models/subscription_application_context.rb', line 49

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['brand_name'] = 'brand_name'
  @_hash['locale'] = 'locale'
  @_hash['shipping_preference'] = 'shipping_preference'
  @_hash['user_action'] = 'user_action'
  @_hash['payment_method'] = 'payment_method'
  @_hash['return_url'] = 'return_url'
  @_hash['cancel_url'] = 'cancel_url'
  @_hash
end

.nullablesObject

An array for nullable fields



73
74
75
# File 'lib/paypal_server_sdk/models/subscription_application_context.rb', line 73

def self.nullables
  []
end

.optionalsObject

An array for optional fields



62
63
64
65
66
67
68
69
70
# File 'lib/paypal_server_sdk/models/subscription_application_context.rb', line 62

def self.optionals
  %w[
    brand_name
    locale
    shipping_preference
    user_action
    payment_method
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



126
127
128
129
130
131
132
# File 'lib/paypal_server_sdk/models/subscription_application_context.rb', line 126

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} brand_name: #{@brand_name.inspect}, locale: #{@locale.inspect},"\
  " shipping_preference: #{@shipping_preference.inspect}, user_action:"\
  " #{@user_action.inspect}, payment_method: #{@payment_method.inspect}, return_url:"\
  " #{@return_url.inspect}, cancel_url: #{@cancel_url.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



118
119
120
121
122
123
# File 'lib/paypal_server_sdk/models/subscription_application_context.rb', line 118

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} brand_name: #{@brand_name}, locale: #{@locale}, shipping_preference:"\
  " #{@shipping_preference}, user_action: #{@user_action}, payment_method: #{@payment_method},"\
  " return_url: #{@return_url}, cancel_url: #{@cancel_url}>"
end