Class: PaymentRecipes::PayPal::REST::Authorization

Inherits:
Object
  • Object
show all
Includes:
Utils::Converters, Utils::Equality
Defined in:
lib/payment_recipes/paypal/rest/authorization.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Equality

#==

Methods included from Utils::Converters

#convert_to_money, #convert_to_string, #convert_to_symbol, #convert_to_time

Constructor Details

#initialize(paypal_authorization, payment: nil, expanded: false) ⇒ Authorization

Returns a new instance of Authorization.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 26

def initialize(paypal_authorization, payment: nil, expanded: false)
  unless paypal_authorization.is_a?(::PayPal::SDK::REST::DataTypes::Authorization)
    raise Exception, "#{ self.class.name } must be initialized with a PayPal Authorization" 
  end

  if payment
    unless payment.is_a?(::PaymentRecipes::PayPal::REST::Payment)
      raise Exception, "Parameter payment must be a PaymentRecipes::PayPal::Payment"
    end

    @payment = payment
    @payment_id = payment.id
  end

  extract_and_store(paypal_authorization)
  @expanded = expanded
end

Instance Attribute Details

#create_timeObject (readonly)

Returns the value of attribute create_time.



12
13
14
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 12

def create_time
  @create_time
end

#currencyObject (readonly)

Returns the value of attribute currency.



6
7
8
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 6

def currency
  @currency
end

#expandedObject (readonly)

Returns the value of attribute expanded.



20
21
22
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 20

def expanded
  @expanded
end

#idObject (readonly)

Returns the value of attribute id.



5
6
7
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 5

def id
  @id
end

#paymentObject (readonly)

Returns the value of attribute payment.



8
9
10
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 8

def payment
  @payment
end

#payment_idObject (readonly)

Returns the value of attribute payment_id.



9
10
11
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 9

def payment_id
  @payment_id
end

#payment_modeObject (readonly)

Returns the value of attribute payment_mode.



16
17
18
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 16

def payment_mode
  @payment_mode
end

#protection_eligibilityObject (readonly)

Returns the value of attribute protection_eligibility.



17
18
19
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 17

def protection_eligibility
  @protection_eligibility
end

#protection_eligibility_typeObject (readonly)

Returns the value of attribute protection_eligibility_type.



18
19
20
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 18

def protection_eligibility_type
  @protection_eligibility_type
end

#raw_authorizationObject (readonly)

Returns the value of attribute raw_authorization.



21
22
23
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 21

def raw_authorization
  @raw_authorization
end

#stateObject (readonly)

Returns the value of attribute state.



11
12
13
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 11

def state
  @state
end

#subtotalObject (readonly)

Returns the value of attribute subtotal.



10
11
12
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 10

def subtotal
  @subtotal
end

#totalObject (readonly)

Returns the value of attribute total.



7
8
9
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 7

def total
  @total
end

#update_timeObject (readonly)

Returns the value of attribute update_time.



13
14
15
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 13

def update_time
  @update_time
end

#valid_untilObject (readonly)

Returns the value of attribute valid_until.



14
15
16
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 14

def valid_until
  @valid_until
end

Class Method Details

.find(id) ⇒ Object



131
132
133
134
135
136
137
138
139
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 131

def find(id)
  paypal_authorization = find_raw(id)

  if paypal_authorization
    new(paypal_authorization, payment: nil, expanded: true)
  else
    nil
  end
end

.find_raw(id) ⇒ Object



141
142
143
144
145
146
147
148
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 141

def find_raw(id)
  begin
    ::PayPal::SDK::REST::Authorization.find(id)

  rescue ::PayPal::SDK::Core::Exceptions::ResourceNotFound
    nil
  end
end

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 98

def authorized?
  @state == :authorized
end

#can_be_captured?Boolean

Returns:

  • (Boolean)


118
119
120
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 118

def can_be_captured?
  authorized? || partially_captured?
end

#captureObject



86
87
88
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 86

def capture
  captures.first
end

#captured?Boolean

Returns:

  • (Boolean)


106
107
108
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 106

def captured?
  @state == :captured
end

#capturesObject



82
83
84
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 82

def captures
  payment.captures
end

#expired?Boolean

Returns:

  • (Boolean)


110
111
112
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 110

def expired?
  @state == :expired
end

#inspectObject



90
91
92
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 90

def inspect
  to_str
end

#partially_captured?Boolean

Returns:

  • (Boolean)


102
103
104
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 102

def partially_captured?
  @state == :partially_captured
end

#pending?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 94

def pending?
  @state == :pending
end

#reload!Object



44
45
46
47
48
49
50
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 44

def reload!
  paypal_authorization = self.class.find_raw(@id)
  extract_and_store(paypal_authorization)
  @expanded = true

  self
end

#reload_payment!Object



52
53
54
55
56
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 52

def reload_payment!
  @payment = ::PaymentRecipes::PayPal::REST::Payment.find(@payment_id) 

  @payment
end

#to_sObject



122
123
124
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 122

def to_s
  to_str
end

#to_strObject



126
127
128
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 126

def to_str
  "<#{ self.class.name } total=#{ @total.format } state=#{ @state } id=#{ @id }>"
end

#voided?Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/payment_recipes/paypal/rest/authorization.rb', line 114

def voided?
  @state == :voided
end