Class: PaymentRecipes::PayPal::REST::Payment

Inherits:
Object
  • Object
show all
Includes:
Utils::Converters, Utils::Equality
Defined in:
lib/payment_recipes/paypal/rest/payment.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_payment, expand: false) ⇒ Payment

Returns a new instance of Payment.


21
22
23
24
25
26
27
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 21

def initialize(paypal_payment, expand: false)
  unless paypal_payment.is_a?(::PayPal::SDK::REST::DataTypes::Payment)
    raise Exception, "#{ self.class.name } must be initialized with a PayPal Payment" 
  end

  extract_and_store(paypal_payment, expand: expand)
end

Instance Attribute Details

#authorizationsObject (readonly)

Returns the value of attribute authorizations


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

def authorizations
  @authorizations
end

#capturesObject (readonly)

Returns the value of attribute captures


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

def captures
  @captures
end

#create_timeObject (readonly)

Returns the value of attribute create_time


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

def create_time
  @create_time
end

#idObject (readonly)

Returns the value of attribute id


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

def id
  @id
end

#intentObject (readonly)

Returns the value of attribute intent


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

def intent
  @intent
end

#payerObject (readonly)

Returns the value of attribute payer


15
16
17
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 15

def payer
  @payer
end

#raw_paymentObject (readonly)

Returns the value of attribute raw_payment


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

def raw_payment
  @raw_payment
end

#refundsObject (readonly)

Returns the value of attribute refunds


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

def refunds
  @refunds
end

#salesObject (readonly)

Returns the value of attribute sales


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

def sales
  @sales
end

#stateObject (readonly)

Returns the value of attribute state


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

def state
  @state
end

#transactionsObject (readonly)

Returns the value of attribute transactions


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

def transactions
  @transactions
end

#update_timeObject (readonly)

Returns the value of attribute update_time


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

def update_time
  @update_time
end

Class Method Details

.find(id, expand: false) ⇒ Object


69
70
71
72
73
74
75
76
77
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 69

def find(id, expand: false)
  paypal_payment = find_raw(id)

  if paypal_payment
    new(paypal_payment, expand: expand)
  else
    nil
  end
end

.find_raw(id) ⇒ Object


79
80
81
82
83
84
85
86
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 79

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

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

.history(count:, page: 1, expand: false) ⇒ Object


88
89
90
91
92
93
94
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 88

def history(count:, page: 1, expand: false)
  paypal_payment_history = ::PayPal::SDK::REST::Payment.all(count: count, start_index: count * (page - 1))

  paypal_payment_history.payments.map do |paypal_payment|
    new(paypal_payment, expand: expand)
  end
end

Instance Method Details

#authorizationObject


44
45
46
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 44

def authorization
  @authorizations.first
end

#captureObject


48
49
50
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 48

def capture
  @captures.first
end

#inspectObject


56
57
58
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 56

def inspect
  to_str
end

#refundObject


52
53
54
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 52

def refund
  @refunds.first
end

#reload!Object


29
30
31
32
33
34
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 29

def reload!
  paypal_payment = self.class.find_raw(@id)
  extract_and_store(paypal_payment)

  self
end

#saleObject


40
41
42
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 40

def sale
  @sales.first
end

#to_sObject


60
61
62
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 60

def to_s
  to_str
end

#to_strObject


64
65
66
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 64

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

#transactionObject


36
37
38
# File 'lib/payment_recipes/paypal/rest/payment.rb', line 36

def transaction
  @transactions.first
end