Class: Pay::Braintree::PaymentMethod

Inherits:
PaymentMethod show all
Defined in:
app/models/pay/braintree/payment_method.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from PaymentMethod

find_by_processor_and_id, pay_processor_for, #payment_processor

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::Customer.find_by(processor: :braintree, processor_id: object.customer_id)
  return unless pay_customer

  pay_customer.save_payment_method(object, default: object.default?)
end

Instance Method Details

#detachObject

Remove payment method



21
22
23
24
25
# File 'app/models/pay/braintree/payment_method.rb', line 21

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 on Stripe



14
15
16
17
18
# File 'app/models/pay/braintree/payment_method.rb', line 14

def make_default!
  result = gateway.customer.update(customer.processor_id, default_payment_method_token: processor_id)
  raise Pay::Braintree::Error, result unless result.success?
  result.success?
end