class MercadoPago::CustomCheckout::Account
Attributes
client[R]
Public Class Methods
new(public_key: nil, access_token: nil)
click to toggle source
# 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
Public Instance Methods
add_card_to_customer(customer_id:, **payload)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
The payload to create the card token is: {
cardNumber: '', securityCode: '', cardExpirationMonth: '', cardExpirationYear: '', cardholderName: '', paymentMethodId: '', docType: '', # Except for México docNumber: '' # Except for México
}
# 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)
click to toggle source
# File lib/mercadopago/custom_checkout/account.rb, line 124 def create_customer(**payload) @client.call(:customers, :create, payload) end
create_payment(**payload)
click to toggle source
# File lib/mercadopago/custom_checkout/account.rb, line 104 def create_payment(**payload) @client.call(:payments, :create, payload) end
customer(customer_id)
click to toggle source
# File lib/mercadopago/custom_checkout/account.rb, line 132 def customer(customer_id) @client.call(:customers, :retrieve, { id: customer_id }) end
customers(**payload)
click to toggle source
# 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 = {})
click to toggle source
# File lib/mercadopago/custom_checkout/account.rb, line 108 def full_refund_payment(payment_id, metadata = {}) @client.call(:payments, :refund, { id: payment_id, metadata: metadata } ) end
identification_types()
click to toggle source
# 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
inspect()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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_methods()
click to toggle source
---- 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.
# 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)
click to toggle source
# 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?()
click to toggle source
# File lib/mercadopago/custom_checkout/account.rb, line 14 def valid? me.key?(:id) end
Private Instance Methods
me()
click to toggle source
# Payments
include MercadoPago::CustomCheckout::Payments
# File lib/mercadopago/custom_checkout/account.rb, line 161 def me @me ||= @client.call(:users, :me) end