Class: Moip::Customer
- Includes:
- HTTParty, Header
- Defined in:
- lib/moip/models/customer.rb
Instance Attribute Summary collapse
- #address ⇒ Object
- #billing_info ⇒ Object
- #birthdate_day ⇒ Object
- #birthdate_month ⇒ Object
- #birthdate_year ⇒ Object
- #code ⇒ Object
- #cpf ⇒ Object
- #creation_date ⇒ Object
- #creation_time ⇒ Object
- #customers ⇒ Object
- #email ⇒ Object
- #fullname ⇒ Object
- #phone_area_code ⇒ Object
- #phone_number ⇒ Object
Instance Method Summary collapse
- #attributes ⇒ Object
-
#create ⇒ Object
metodo que envia as informações para a API do moip e cria um novo cliente see moiplabs.github.io/assinaturas-docs/api.html#criar_cliente.
- #find(code) ⇒ Object
- #load ⇒ Object
-
#update_billing_info(billing_info) ⇒ Object
metodo que envia as informações para a API do moip e atualiza os dados do cartão see moiplabs.github.io/assinaturas-docs/api.html#atualizar_cartao.
- #validates_format_of_email ⇒ Object
- #validates_presence_of_address ⇒ Object
- #validates_presence_of_billing_info ⇒ Object
Methods included from Header
#auth, #base_url, #default_header
Methods inherited from Model
build, #set_parameters, #to_json, #validate_response
Instance Attribute Details
#address ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def address @address end |
#billing_info ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def billing_info @billing_info end |
#birthdate_day ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def birthdate_day @birthdate_day end |
#birthdate_month ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def birthdate_month @birthdate_month end |
#birthdate_year ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def birthdate_year @birthdate_year end |
#code ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def code @code end |
#cpf ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def cpf @cpf end |
#creation_date ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def creation_date @creation_date end |
#creation_time ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def creation_time @creation_time end |
#customers ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def customers @customers end |
#email ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def email @email end |
#fullname ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def fullname @fullname end |
#phone_area_code ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def phone_area_code @phone_area_code end |
#phone_number ⇒ Object
7 8 9 |
# File 'lib/moip/models/customer.rb', line 7 def phone_number @phone_number end |
Instance Method Details
#attributes ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/moip/models/customer.rb', line 18 def attributes { "code" => code, "email" => email, "fullname" => fullname, "cpf" => cpf, "phone_area_code" => phone_area_code, "phone_number" => phone_number, "birthdate_day" => birthdate_day, "birthdate_month" => birthdate_month, "birthdate_year" => birthdate_year, "address" => address, "billing_info" => billing_info } end |
#create ⇒ Object
metodo que envia as informações para a API do moip e cria um novo cliente see moiplabs.github.io/assinaturas-docs/api.html#criar_cliente
104 105 106 107 108 109 110 111 |
# File 'lib/moip/models/customer.rb', line 104 def create if self.valid? response = self.class.post(base_url(:customers, :params => "new_vault=true"), default_header(self.to_json)).parsed_response self.validate_response response else false end end |
#find(code) ⇒ Object
127 128 129 130 |
# File 'lib/moip/models/customer.rb', line 127 def find code response = self.class.get(base_url(:customers, :code => code), default_header).parsed_response self.set_parameters response unless response.nil? end |
#load ⇒ Object
97 98 99 100 |
# File 'lib/moip/models/customer.rb', line 97 def load list = self.class.get(base_url(:customers), default_header).parsed_response self.costumers = list["costumers"] end |
#update_billing_info(billing_info) ⇒ Object
metodo que envia as informações para a API do moip e atualiza os dados do cartão see moiplabs.github.io/assinaturas-docs/api.html#atualizar_cartao
116 117 118 119 120 121 122 123 124 |
# File 'lib/moip/models/customer.rb', line 116 def update_billing_info billing_info if billing_info.valid? response = self.class.put(base_url(:customers, :code => self.code, :status => "billing_infos"), default_header(billing_info.build_update.to_json)).parsed_response puts response self.validate_response response else false end end |
#validates_format_of_email ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/moip/models/customer.rb', line 78 def validates_format_of_email if !self.email.nil? and self.email.match /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i true else self.errors.add :email, I18n.t("moip.errors.invalid_format") and return end end |
#validates_presence_of_address ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/moip/models/customer.rb', line 58 def validates_presence_of_address self.errors.add :address, I18n.t("moip.errors.presence_of_address") and return if @address.nil? if @address.valid? true else self.errors.add @address.errors.first[0], @address.errors.first[1] end end |
#validates_presence_of_billing_info ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/moip/models/customer.rb', line 68 def validates_presence_of_billing_info self.errors.add :billing_info, I18n.t("moip.errors.presence_of_billing_info") and return if @billing_info.nil? if @billing_info.valid? true else self.errors.add @billing_info.errors.first[0], @billing_info.errors.first[1] end end |