Class: PaypalAdaptivePaymentAccount

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/paypal_adaptive_payment_account.rb

Overview

Instance Method Summary (collapse)

Instance Method Details

- (Object) actions



5
6
7
# File 'app/models/paypal_adaptive_payment_account.rb', line 5

def actions
  %w{capture credit}
end

- (Boolean) can_capture?(payment)

Returns:

  • (Boolean)


22
23
24
# File 'app/models/paypal_adaptive_payment_account.rb', line 22

def can_capture?(payment)
  !echeck?(payment) && payment.state == "pending"
end

- (Boolean) can_credit?(payment)

Returns:

  • (Boolean)


43
44
45
46
47
48
# File 'app/models/paypal_adaptive_payment_account.rb', line 43

def can_credit?(payment)
  return false unless payment.state == "completed"
  return false unless payment.order.payment_state == "credit_owed"
  payment.credit_allowed > 0
  !find_capture(payment).nil?
end

- (Object) capture(payment)



9
10
11
12
13
14
15
16
17
18
19
20
# File 'app/models/paypal_adaptive_payment_account.rb', line 9

def capture(payment)
  authorization = find_authorization(payment)

  ppx_response = payment.payment_method.provider.capture((100 * payment.amount).to_i, authorization.params["transaction_id"])
  if ppx_response.success?
    record_log payment, ppx_response
    payment.complete
  else
    gateway_error(ppx_response.message)
  end

end

- (Object) credit(payment, amount = nil)



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/paypal_adaptive_payment_account.rb', line 26

def credit(payment, amount=nil)
  authorization = find_capture(payment)

  amount = payment.credit_allowed >= payment.order.outstanding_balance.abs ? payment.order.outstanding_balance : payment.credit_allowed

  ppx_response = payment.payment_method.provider.credit(amount.nil? ? (100 * amount).to_i : (100 * amount).to_i, authorization.params['transaction_id'])

  if ppx_response.success?
    record_log payment, ppx_response
    payment.update_attribute(:amount, payment.amount - amount)
    payment.complete
    payment.order.update!
  else
    gateway_error(ppx_response.message)
  end
end

- (Boolean) echeck?(payment)

Returns:

  • (Boolean)


55
56
57
58
59
60
61
62
63
64
# File 'app/models/paypal_adaptive_payment_account.rb', line 55

def echeck?(payment)
  logs = payment.log_entries.all(:order => 'created_at DESC')
  logs.each do |log|
    details = YAML.load(log.details) # return the transaction details
    if details.params['payment_type'] == 'echeck'
      return true
    end
  end
  return false
end

- (Object) payment_gateway

fix for Payment#payment_profiles_supported?



51
52
53
# File 'app/models/paypal_adaptive_payment_account.rb', line 51

def payment_gateway
  false
end

- (Object) record_log(payment, response)



66
67
68
# File 'app/models/paypal_adaptive_payment_account.rb', line 66

def record_log(payment, response)
  payment.log_entries.create(:details => response.to_yaml)
end