Class: PaymentRecipes::PayPal::REST::Transaction
- Inherits:
-
Object
- Object
- PaymentRecipes::PayPal::REST::Transaction
- Includes:
- Utils::Converters
- Defined in:
- lib/payment_recipes/paypal/rest/transaction.rb
Instance Attribute Summary collapse
-
#authorizations ⇒ Object
readonly
Returns the value of attribute authorizations.
-
#captures ⇒ Object
readonly
Returns the value of attribute captures.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#fee ⇒ Object
readonly
Returns the value of attribute fee.
-
#gift_wrap ⇒ Object
readonly
Returns the value of attribute gift_wrap.
-
#handling_fee ⇒ Object
readonly
Returns the value of attribute handling_fee.
-
#insurance ⇒ Object
readonly
Returns the value of attribute insurance.
-
#payment ⇒ Object
readonly
Returns the value of attribute payment.
-
#payment_id ⇒ Object
readonly
Returns the value of attribute payment_id.
-
#raw_transaction ⇒ Object
readonly
Returns the value of attribute raw_transaction.
-
#refunds ⇒ Object
readonly
Returns the value of attribute refunds.
-
#sales ⇒ Object
readonly
Returns the value of attribute sales.
-
#shipping ⇒ Object
readonly
Returns the value of attribute shipping.
-
#shipping_discount ⇒ Object
readonly
Returns the value of attribute shipping_discount.
-
#subtotal ⇒ Object
readonly
Returns the value of attribute subtotal.
-
#tax ⇒ Object
readonly
Returns the value of attribute tax.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
Instance Method Summary collapse
- #authorization ⇒ Object
- #capture ⇒ Object
-
#initialize(paypal_transaction, payment:, expand: false) ⇒ Transaction
constructor
A new instance of Transaction.
- #inspect ⇒ Object
- #refund ⇒ Object
- #sale ⇒ Object
- #to_s ⇒ Object
- #to_str ⇒ Object
Methods included from Utils::Converters
#convert_to_money, #convert_to_string, #convert_to_symbol, #convert_to_time
Constructor Details
#initialize(paypal_transaction, payment:, expand: false) ⇒ Transaction
Returns a new instance of Transaction.
30 31 32 33 34 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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 30 def initialize(paypal_transaction, payment:, expand: false) unless paypal_transaction.is_a?(::PayPal::SDK::REST::DataTypes::Transaction) raise Exception, "#{ self.class.name } must be initialized with a PayPal Transaction" end unless payment.is_a?(::PaymentRecipes::PayPal::REST::Payment) raise Exception, "Parameter payment must be a PaymentRecipes::PayPal::REST::Payment" end @currency = convert_to_string(paypal_transaction.amount.currency) @total = convert_to_money(amount: paypal_transaction.amount.total, currency: @currency) @description = convert_to_string(paypal_transaction.description) @payment = payment @payment_id = payment.id @subtotal = convert_to_money(amount: paypal_transaction.amount.details.subtotal, currency: @currency) @tax = convert_to_money(amount: paypal_transaction.amount.details.tax, currency: @currency) @fee = convert_to_money(amount: paypal_transaction.amount.details.fee, currency: @currency) @shipping = convert_to_money(amount: paypal_transaction.amount.details.shipping, currency: @currency) @handling_fee = convert_to_money(amount: paypal_transaction.amount.details.handling_fee, currency: @currency) @insurance = convert_to_money(amount: paypal_transaction.amount.details.insurance, currency: @currency) @shipping_discount = convert_to_money(amount: paypal_transaction.amount.details.shipping_discount, currency: @currency) @insurance = convert_to_money(amount: paypal_transaction.amount.details.insurance, currency: @currency) @gift_wrap = convert_to_money(amount: paypal_transaction.amount.details.gift_wrap, currency: @currency) @raw_transaction = paypal_transaction @sales = [] @authorizations = [] @captures = [] @refunds = [] paypal_transaction..each do || if .sale.id sale = ::PaymentRecipes::PayPal::REST::Sale.new(.sale, payment: payment) sale.reload! if @sales << sale end if ..id = ::PaymentRecipes::PayPal::REST::Authorization.new(., payment: payment) .reload! if @authorizations << end if .capture.id capture = ::PaymentRecipes::PayPal::REST::Capture.new(.capture, payment: payment) @captures << capture end if .refund.id refund = ::PaymentRecipes::PayPal::REST::Refund.new(.refund, payment: payment) @refunds << refund end end end |
Instance Attribute Details
#authorizations ⇒ Object (readonly)
Returns the value of attribute authorizations.
22 23 24 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 22 def @authorizations end |
#captures ⇒ Object (readonly)
Returns the value of attribute captures.
23 24 25 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 23 def captures @captures end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency.
5 6 7 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 5 def currency @currency end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
9 10 11 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 9 def description @description end |
#fee ⇒ Object (readonly)
Returns the value of attribute fee.
13 14 15 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 13 def fee @fee end |
#gift_wrap ⇒ Object (readonly)
Returns the value of attribute gift_wrap.
19 20 21 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 19 def gift_wrap @gift_wrap end |
#handling_fee ⇒ Object (readonly)
Returns the value of attribute handling_fee.
15 16 17 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 15 def handling_fee @handling_fee end |
#insurance ⇒ Object (readonly)
Returns the value of attribute insurance.
16 17 18 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 16 def insurance @insurance end |
#payment ⇒ Object (readonly)
Returns the value of attribute payment.
7 8 9 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 7 def payment @payment end |
#payment_id ⇒ Object (readonly)
Returns the value of attribute payment_id.
8 9 10 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 8 def payment_id @payment_id end |
#raw_transaction ⇒ Object (readonly)
Returns the value of attribute raw_transaction.
26 27 28 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 26 def raw_transaction @raw_transaction end |
#refunds ⇒ Object (readonly)
Returns the value of attribute refunds.
24 25 26 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 24 def refunds @refunds end |
#sales ⇒ Object (readonly)
Returns the value of attribute sales.
21 22 23 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 21 def sales @sales end |
#shipping ⇒ Object (readonly)
Returns the value of attribute shipping.
14 15 16 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 14 def shipping @shipping end |
#shipping_discount ⇒ Object (readonly)
Returns the value of attribute shipping_discount.
17 18 19 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 17 def shipping_discount @shipping_discount end |
#subtotal ⇒ Object (readonly)
Returns the value of attribute subtotal.
11 12 13 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 11 def subtotal @subtotal end |
#tax ⇒ Object (readonly)
Returns the value of attribute tax.
12 13 14 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 12 def tax @tax end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
6 7 8 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 6 def total @total end |
Instance Method Details
#authorization ⇒ Object
92 93 94 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 92 def @authorizations.first end |
#capture ⇒ Object
96 97 98 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 96 def capture @captures.first end |
#inspect ⇒ Object
104 105 106 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 104 def inspect to_str end |
#refund ⇒ Object
100 101 102 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 100 def refund @refunds.first end |
#sale ⇒ Object
88 89 90 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 88 def sale @sales.first end |
#to_s ⇒ Object
108 109 110 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 108 def to_s to_str end |
#to_str ⇒ Object
112 113 114 |
# File 'lib/payment_recipes/paypal/rest/transaction.rb', line 112 def to_str "<#{ self.class.name } total=#{ @total.format } sales=#{ @sales.size } authorizations=#{ @authorizations.size } captures=#{ @captures.size }>" end |