Class: PaymentRecipes::PayPal::SOAP::Transaction

Inherits:
Object
  • Object
show all
Includes:
Utils::Converters, Utils::Equality
Defined in:
lib/payment_recipes/paypal/soap/transaction.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_transaction, id: nil) ⇒ Transaction

Returns a new instance of Transaction.


27
28
29
30
31
32
33
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 27

def initialize(paypal_transaction, id: nil)
  unless paypal_transaction.is_a?(::PayPal::SDK::Merchant::DataTypes::GetTransactionDetailsResponseType)
    raise Exception, "#{ self.class.name } must be initialized with a PayPal Transaction" 
  end

  extract_and_store(paypal_transaction)
end

Instance Attribute Details

#correlation_idObject (readonly)

Returns the value of attribute correlation_id


8
9
10
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 8

def correlation_id
  @correlation_id
end

#fee_amountObject (readonly)

Returns the value of attribute fee_amount


13
14
15
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 13

def fee_amount
  @fee_amount
end

#gross_amountObject (readonly)

Returns the value of attribute gross_amount


12
13
14
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 12

def gross_amount
  @gross_amount
end

#idObject (readonly)

Returns the value of attribute id


7
8
9
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 7

def id
  @id
end

#parent_transaction_idObject (readonly)

Returns the value of attribute parent_transaction_id


22
23
24
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 22

def parent_transaction_id
  @parent_transaction_id
end

#payment_dateObject (readonly)

Returns the value of attribute payment_date


17
18
19
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 17

def payment_date
  @payment_date
end

#payment_item_amountObject (readonly)

Returns the value of attribute payment_item_amount


15
16
17
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 15

def payment_item_amount
  @payment_item_amount
end

#payment_statusObject (readonly)

Returns the value of attribute payment_status


19
20
21
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 19

def payment_status
  @payment_status
end

#payment_typeObject (readonly)

Returns the value of attribute payment_type


18
19
20
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 18

def payment_type
  @payment_type
end

#pending_reasonObject (readonly)

Returns the value of attribute pending_reason


20
21
22
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 20

def pending_reason
  @pending_reason
end

#raw_transactionObject (readonly)

Returns the value of attribute raw_transaction


5
6
7
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 5

def raw_transaction
  @raw_transaction
end

#tax_amountObject (readonly)

Returns the value of attribute tax_amount


14
15
16
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 14

def tax_amount
  @tax_amount
end

#timestampObject (readonly)

Returns the value of attribute timestamp


9
10
11
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 9

def timestamp
  @timestamp
end

#transaction_typeObject (readonly)

Returns the value of attribute transaction_type


10
11
12
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 10

def transaction_type
  @transaction_type
end

Class Method Details

.find(id) ⇒ Object


87
88
89
90
91
92
93
94
95
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 87

def find(id)
  paypal_transaction = find_raw(id)

  if paypal_transaction
    new(paypal_transaction, id: id)
  else
    nil
  end
end

.find_raw(id) ⇒ Object


97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 97

def find_raw(id)
  api = ::PaymentRecipes::PayPal::SOAP::Settings.api

  begin
    get_transaction_details = api.build_get_transaction_details({
      :TransactionID => id })

    response = api.get_transaction_details(get_transaction_details)

    response

  rescue Exception
    nil
  end
end

Instance Method Details

#complete?Boolean

Returns:

  • (Boolean)

66
67
68
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 66

def complete?
  @payment_status == "Completed"
end

#extract_and_store(paypal_transaction) ⇒ Object


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 35

def extract_and_store(paypal_transaction)
  @raw_transaction = paypal_transaction

  @id = id || paypal_transaction.payment_transaction_details.payment_info.transaction_id
  @correlation_id = paypal_transaction.correlation_id
  @timestamp = paypal_transaction.timestamp.to_time

  @transaction_type = paypal_transaction.payment_transaction_details.payment_info.transaction_type.to_s
  @payment_type = paypal_transaction.payment_transaction_details.payment_info.payment_type.to_s
  @payment_status = paypal_transaction.payment_transaction_details.payment_info.payment_status.to_s
  @pending_reason = paypal_transaction.payment_transaction_details.payment_info.pending_reason.to_s
  @parent_transaction_id = paypal_transaction.payment_transaction_details.payment_info.parent_transaction_id.to_s
  @payment_date = paypal_transaction.payment_transaction_details.payment_info.payment_date.to_time

  paypal_gross_amount = paypal_transaction.payment_transaction_details.payment_info.gross_amount
  @gross_amount = convert_to_money(amount: paypal_gross_amount.value, currency: paypal_gross_amount.currencyID)

  paypal_fee_amount = paypal_transaction.payment_transaction_details.payment_info.fee_amount
  @fee_amount = convert_to_money(amount: paypal_fee_amount.value, currency: paypal_fee_amount.currencyID)

  paypal_tax_amount = paypal_transaction.payment_transaction_details.payment_info.tax_amount
  @tax_amount = convert_to_money(amount: paypal_tax_amount.value, currency: paypal_tax_amount.currencyID)

  payment_item_amount = paypal_transaction.payment_transaction_details.payment_item_info.payment_item.first.amount
  @payment_item_amount = convert_to_money(amount: payment_item_amount.value, currency: payment_item_amount.currencyID)
end

#inspectObject


70
71
72
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 70

def inspect
  to_str
end

#pending?Boolean

Returns:

  • (Boolean)

62
63
64
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 62

def pending?
  @payment_status == "Pending"
end

#to_sObject


74
75
76
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 74

def to_s
  to_str
end

#to_strObject


78
79
80
81
82
83
84
# File 'lib/payment_recipes/paypal/soap/transaction.rb', line 78

def to_str
  if pending?
    "<#{ self.class.name } type=#{ @transaction_type } payment_type=#{ @payment_type } payment_status=#{ @payment_status } [#{ @pending_reason }] id=#{ @id }>"
  else
    "<#{ self.class.name } type=#{ @transaction_type } payment_type=#{ @payment_type } payment_status=#{ @payment_status } id=#{ @id }>"
  end
end