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
48 49 50 |
# File 'app/models/solidus_braintree/source.rb', line 48 def actions %w[capture void credit] end |
#apple_pay? ⇒ 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
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
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
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
91 92 93 |
# File 'app/models/solidus_braintree/source.rb', line 91 def credit_card? payment_type == CREDIT_CARD end |
#display_number ⇒ Object
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_type ⇒ Object
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_source ⇒ Object
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_type ⇒ Object
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 |
#imported ⇒ Object
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
79 80 81 |
# File 'app/models/solidus_braintree/source.rb', line 79 def paypal? payment_type == PAYPAL end |
#reusable? ⇒ Boolean
87 88 89 |
# File 'app/models/solidus_braintree/source.rb', line 87 def reusable? token.present? end |
#venmo? ⇒ Boolean
83 84 85 |
# File 'app/models/solidus_braintree/source.rb', line 83 def venmo? payment_type == VENMO end |