Class: Pay::Braintree::PaymentMethod

Inherits:
Object
  • Object
show all
Defined in:
lib/pay/braintree/payment_method.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pay_payment_method) ⇒ PaymentMethod

Returns a new instance of PaymentMethod.



17
18
19
# File 'lib/pay/braintree/payment_method.rb', line 17

def initialize(pay_payment_method)
  @pay_payment_method = pay_payment_method
end

Instance Attribute Details

#pay_payment_methodObject (readonly)

Returns the value of attribute pay_payment_method.



4
5
6
# File 'lib/pay/braintree/payment_method.rb', line 4

def pay_payment_method
  @pay_payment_method
end

Class Method Details

.sync(id, object: nil, try: 0, retries: 1) ⇒ Object



8
9
10
11
12
13
14
15
# File 'lib/pay/braintree/payment_method.rb', line 8

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



29
30
31
32
33
# File 'lib/pay/braintree/payment_method.rb', line 29

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



22
23
24
25
26
# File 'lib/pay/braintree/payment_method.rb', line 22

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