Class: Pay::Braintree::PaymentMethod
- Inherits:
-
PaymentMethod
- Object
- ApplicationRecord
- PaymentMethod
- Pay::Braintree::PaymentMethod
- Defined in:
- app/models/pay/braintree/payment_method.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#detach ⇒ Object
Remove payment method.
-
#make_default! ⇒ Object
Sets payment method as default.
Methods inherited from PaymentMethod
find_by_processor_and_id, pay_processor_for
Class Method Details
.sync(id, object: nil, try: 0, retries: 1) ⇒ Object
4 5 6 7 8 9 10 11 |
# File 'app/models/pay/braintree/payment_method.rb', line 4 def self.sync(id, object: nil, try: 0, retries: 1) object ||= Pay.braintree_gateway.payment_method.find(id) pay_customer = Pay::Braintree::Customer.find_by(processor_id: object.customer_id) return unless pay_customer pay_customer.save_payment_method(object, default: object.default?) end |
Instance Method Details
#detach ⇒ Object
Remove payment method
27 28 29 30 31 |
# File 'app/models/pay/braintree/payment_method.rb', line 27 def detach result = gateway.payment_method.delete(processor_id) raise Pay::Braintree::Error, result unless result.success? result.success? end |
#make_default! ⇒ Object
Sets payment method as default
14 15 16 17 18 19 20 21 22 23 24 |
# File 'app/models/pay/braintree/payment_method.rb', line 14 def make_default! return if default? result = gateway.customer.update(customer.processor_id, default_payment_method_token: processor_id) raise Pay::Braintree::Error, result unless result.success? customer.payment_methods.update_all(default: false) update!(default: true) result.success? end |