Class: MercadoPago::CustomCheckout::Account

Inherits:
Object
  • Object
show all
Defined in:
lib/mercadopago/custom_checkout/account.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(public_key: nil, access_token: nil) ⇒ Account

Returns a new instance of Account.



6
7
8
# File 'lib/mercadopago/custom_checkout/account.rb', line 6

def initialize(public_key: nil, access_token: nil)
  @client = MercadoPago::Core::Client.new(public_key, access_token)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



4
5
6
# File 'lib/mercadopago/custom_checkout/account.rb', line 4

def client
  @client
end

Instance Method Details

#add_card_to_customer(customer_id:, **payload) ⇒ Object



128
129
130
# File 'lib/mercadopago/custom_checkout/account.rb', line 128

def add_card_to_customer(customer_id:, **payload)
  @client.call(:cards, :create, payload.merge(customer_id: customer_id))
end

#card_issuers_for(payment_method_id) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/mercadopago/custom_checkout/account.rb', line 46

def card_issuers_for(payment_method_id)
  response = @client.call(:card_issuers, :retrieve, {
    payment_method_id: payment_method_id
  })
  if response.is_a?(Array)
    response.map do |issuer|
      CardIssuer.new(issuer)
    end
  else
    response
  end
end

#create_card_token(**payload) ⇒ Object

The payload to create the card token is:

cardNumber: '',
securityCode: '',
cardExpirationMonth: '',
cardExpirationYear: '',
cardholderName: '',
paymentMethodId: '',
docType: '', # Except for México
docNumber: '' # Except for México



95
96
97
98
99
100
101
102
# File 'lib/mercadopago/custom_checkout/account.rb', line 95

def create_card_token(**payload)
  response = @client.call(:card_tokens, :create, payload)
  if response.key?(:error)
    response
  else
    CardToken.new(@client, response)
  end
end

#create_customer(**payload) ⇒ Object



124
125
126
# File 'lib/mercadopago/custom_checkout/account.rb', line 124

def create_customer(**payload)
  @client.call(:customers, :create, payload)
end

#create_payment(**payload) ⇒ Object



104
105
106
# File 'lib/mercadopago/custom_checkout/account.rb', line 104

def create_payment(**payload)
  @client.call(:payments, :create, payload)
end

#customer(customer_id) ⇒ Object



132
133
134
# File 'lib/mercadopago/custom_checkout/account.rb', line 132

def customer(customer_id)
  @client.call(:customers, :retrieve, { id: customer_id })
end

#customers(**payload) ⇒ Object



136
137
138
139
140
141
142
# File 'lib/mercadopago/custom_checkout/account.rb', line 136

def customers(**payload)
  if response = @client.call(:customers, :search, payload)
    response[:results]
  else
    []
  end
end

#full_refund_payment(payment_id, metadata = {}) ⇒ Object



108
109
110
# File 'lib/mercadopago/custom_checkout/account.rb', line 108

def full_refund_payment(payment_id,  = {})
  @client.call(:payments, :refund, { id: payment_id, metadata:  } )
end

#identification_typesObject



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/mercadopago/custom_checkout/account.rb', line 65

def identification_types
  return @identification_types unless @identification_types.nil?

  response = @client.call(:identification_types, :retrieve)
  if response.is_a?(Array)
    @identification_types = response.map do |identification|
      IdentificationType.new(identification)
    end
  else
    if response[:status] == 404
      @identification_types = []
    else
      response
    end
  end
end

#inspectObject



10
11
12
# File 'lib/mercadopago/custom_checkout/account.rb', line 10

def inspect
  "#<#{self.class.name} public_key:#{@client.public_key}>"
end

#installments_for(payment_method_id) ⇒ Object



59
60
61
62
63
# File 'lib/mercadopago/custom_checkout/account.rb', line 59

def installments_for(payment_method_id)
  @client.call(:installments, :retrieve, {
    payment_method_id: payment_method_id
  })
end

#payment(payment_id) ⇒ Object



112
113
114
# File 'lib/mercadopago/custom_checkout/account.rb', line 112

def payment(payment_id)
  @client.call(:payments, :retrieve, { id: payment_id })
end

#payment_method(bin_number) ⇒ Object



36
37
38
39
40
41
42
43
44
# File 'lib/mercadopago/custom_checkout/account.rb', line 36

def payment_method(bin_number)
  number = bin_number.gsub(/\s*/, '')[0,6]
  payment_methods.select do |method|
    bin = method.bin
    bin &&
    (number.match(bin[:pattern]) ? true : false) &&
    (!bin[:exclusion_pattern] || !number.match(bin[:exclusion_pattern]))
  end
end

#payment_methodsObject

—- Informative Methods —- ## This methods allows to retrieve information only, there is no create/update just informative, about :payment_methods, or :card_issuers of a PaymentMethod etc. All of them are accesible with the :public_key.



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/mercadopago/custom_checkout/account.rb', line 23

def payment_methods
  return @payment_methods unless @payment_methods.nil? || @payment_methods.empty?

  response = @client.call(:payment_methods, :retrieve)
  if response.is_a?(Array)
    @payment_methods = response.map do |method|
      PaymentMethod.new(self, method)
    end
  else
    response
  end
end

#payments(**payload) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/mercadopago/custom_checkout/account.rb', line 116

def payments(**payload)
  if response = @client.call(:payments, :search, payload)
    response[:results]
  else
    []
  end
end

#valid?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/mercadopago/custom_checkout/account.rb', line 14

def valid?
  me.key?(:id)
end