Class: SolidusBraintree::Source

Inherits:
Spree::PaymentSource
  • Object
show all
Includes:
RequestProtection
Defined in:
app/models/solidus_braintree/source.rb

Constant Summary collapse

PAYPAL =
"PayPalAccount"
APPLE_PAY =
"ApplePayCard"
VENMO =
"VenmoAccount"
CREDIT_CARD =
"CreditCard"

Instance Method Summary collapse

Methods included from RequestProtection

#protected_request

Instance Method Details

#actionsObject



48
49
50
# File 'app/models/solidus_braintree/source.rb', line 48

def actions
  %w[capture void credit]
end

#apple_pay?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'app/models/solidus_braintree/source.rb', line 75

def apple_pay?
  payment_type == APPLE_PAY
end

#can_capture?(payment) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'app/models/solidus_braintree/source.rb', line 52

def can_capture?(payment)
  payment.pending? || payment.checkout?
end

#can_credit?(payment) ⇒ Boolean

Returns:

  • (Boolean)


67
68
69
# File 'app/models/solidus_braintree/source.rb', line 67

def can_credit?(payment)
  payment.completed? && payment.credit_allowed > 0
end

#can_void?(payment) ⇒ Boolean

Returns:

  • (Boolean)


56
57
58
59
60
61
62
63
64
65
# File 'app/models/solidus_braintree/source.rb', line 56

def can_void?(payment)
  return false unless payment.response_code

  transaction = protected_request do
    braintree_client.transaction.find(payment.response_code)
  end
  Gateway::VOIDABLE_STATUSES.include?(transaction.status)
rescue ActiveMerchant::ConnectionError
  false
end

#credit_card?Boolean

Returns:

  • (Boolean)


91
92
93
# File 'app/models/solidus_braintree/source.rb', line 91

def credit_card?
  payment_type == CREDIT_CARD
end

#display_numberObject



95
96
97
98
99
100
101
102
103
# File 'app/models/solidus_braintree/source.rb', line 95

def display_number
  if paypal?
    email
  elsif venmo?
    username
  else
    "XXXX-XXXX-XXXX-#{last_digits.to_s.rjust(4, 'X')}"
  end
end

#display_payment_typeObject



111
112
113
# File 'app/models/solidus_braintree/source.rb', line 111

def display_payment_type
  "#{I18n.t('solidus_braintree.payment_type.label')}: #{friendly_payment_type}"
end

#display_paypal_funding_sourceObject



105
106
107
108
109
# File 'app/models/solidus_braintree/source.rb', line 105

def display_paypal_funding_source
  I18n.t(paypal_funding_source,
    scope: 'solidus_braintree.paypal_funding_sources',
    default: paypal_funding_source)
end

#friendly_payment_typeObject



71
72
73
# File 'app/models/solidus_braintree/source.rb', line 71

def friendly_payment_type
  I18n.t(payment_type.underscore, scope: "solidus_braintree.payment_type")
end

#importedObject

we are not currenctly supporting an “imported” flag



44
45
46
# File 'app/models/solidus_braintree/source.rb', line 44

def imported
  false
end

#paypal?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'app/models/solidus_braintree/source.rb', line 79

def paypal?
  payment_type == PAYPAL
end

#reusable?Boolean

Returns:

  • (Boolean)


87
88
89
# File 'app/models/solidus_braintree/source.rb', line 87

def reusable?
  token.present?
end

#venmo?Boolean

Returns:

  • (Boolean)


83
84
85
# File 'app/models/solidus_braintree/source.rb', line 83

def venmo?
  payment_type == VENMO
end