Class: SolidusBraintree::Source
- Inherits:
-
Spree::PaymentSource
- Object
- Spree::PaymentSource
- SolidusBraintree::Source
- 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
- #actions ⇒ Object
- #apple_pay? ⇒ Boolean
- #can_capture?(payment) ⇒ Boolean
- #can_credit?(payment) ⇒ Boolean
- #can_void?(payment) ⇒ Boolean
- #credit_card? ⇒ Boolean
- #display_number ⇒ Object
- #display_payment_type ⇒ Object
- #display_paypal_funding_source ⇒ Object
- #friendly_payment_type ⇒ Object
-
#imported ⇒ Object
we are not currenctly supporting an “imported” flag.
- #paypal? ⇒ Boolean
- #reusable? ⇒ Boolean
- #venmo? ⇒ Boolean
Methods included from RequestProtection
Instance Method Details
#actions ⇒ Object
50 51 52 |
# File 'app/models/solidus_braintree/source.rb', line 50 def actions %w[capture void credit] end |
#apple_pay? ⇒ Boolean
77 78 79 |
# File 'app/models/solidus_braintree/source.rb', line 77 def apple_pay? payment_type == APPLE_PAY end |
#can_capture?(payment) ⇒ Boolean
54 55 56 |
# File 'app/models/solidus_braintree/source.rb', line 54 def can_capture?(payment) payment.pending? || payment.checkout? end |
#can_credit?(payment) ⇒ Boolean
69 70 71 |
# File 'app/models/solidus_braintree/source.rb', line 69 def can_credit?(payment) payment.completed? && payment.credit_allowed > 0 end |
#can_void?(payment) ⇒ Boolean
58 59 60 61 62 63 64 65 66 67 |
# File 'app/models/solidus_braintree/source.rb', line 58 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
93 94 95 |
# File 'app/models/solidus_braintree/source.rb', line 93 def credit_card? payment_type == CREDIT_CARD end |
#display_number ⇒ Object
97 98 99 100 101 102 103 104 105 |
# File 'app/models/solidus_braintree/source.rb', line 97 def display_number if paypal? email elsif venmo? username else "XXXX-XXXX-XXXX-#{last_digits.to_s.rjust(4, 'X')}" end end |
#display_payment_type ⇒ Object
113 114 115 |
# File 'app/models/solidus_braintree/source.rb', line 113 def display_payment_type "#{I18n.t('solidus_braintree.payment_type.label')}: #{friendly_payment_type}" end |
#display_paypal_funding_source ⇒ Object
107 108 109 110 111 |
# File 'app/models/solidus_braintree/source.rb', line 107 def display_paypal_funding_source I18n.t(paypal_funding_source, scope: 'solidus_braintree.paypal_funding_sources', default: paypal_funding_source) end |
#friendly_payment_type ⇒ Object
73 74 75 |
# File 'app/models/solidus_braintree/source.rb', line 73 def friendly_payment_type I18n.t(payment_type.underscore, scope: "solidus_braintree.payment_type") end |
#imported ⇒ Object
we are not currenctly supporting an “imported” flag
46 47 48 |
# File 'app/models/solidus_braintree/source.rb', line 46 def imported false end |
#paypal? ⇒ Boolean
81 82 83 |
# File 'app/models/solidus_braintree/source.rb', line 81 def paypal? payment_type == PAYPAL end |
#reusable? ⇒ Boolean
89 90 91 |
# File 'app/models/solidus_braintree/source.rb', line 89 def reusable? token.present? end |
#venmo? ⇒ Boolean
85 86 87 |
# File 'app/models/solidus_braintree/source.rb', line 85 def venmo? payment_type == VENMO end |