conekta-tiempometa 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +24 -0
- data/.rspec +1 -0
- data/CHANGELOG.md +124 -0
- data/Dockerfile +44 -0
- data/Gemfile +13 -0
- data/LICENSE.txt +22 -0
- data/README.md +182 -0
- data/Rakefile +1 -0
- data/conekta.gemspec +29 -0
- data/lib/conekta/address.rb +5 -0
- data/lib/conekta/card.rb +21 -0
- data/lib/conekta/charge.rb +25 -0
- data/lib/conekta/conekta_object.rb +109 -0
- data/lib/conekta/customer.rb +82 -0
- data/lib/conekta/customer_info.rb +5 -0
- data/lib/conekta/destination.rb +17 -0
- data/lib/conekta/details.rb +5 -0
- data/lib/conekta/discount_line.rb +19 -0
- data/lib/conekta/error.rb +99 -0
- data/lib/conekta/error_details.rb +14 -0
- data/lib/conekta/event.rb +9 -0
- data/lib/conekta/line_item.rb +21 -0
- data/lib/conekta/list.rb +59 -0
- data/lib/conekta/log.rb +10 -0
- data/lib/conekta/method.rb +4 -0
- data/lib/conekta/operations/create.rb +19 -0
- data/lib/conekta/operations/create_member.rb +40 -0
- data/lib/conekta/operations/custom_action.rb +13 -0
- data/lib/conekta/operations/delete.rb +45 -0
- data/lib/conekta/operations/find.rb +21 -0
- data/lib/conekta/operations/update.rb +11 -0
- data/lib/conekta/operations/where.rb +30 -0
- data/lib/conekta/order.rb +87 -0
- data/lib/conekta/payee.rb +66 -0
- data/lib/conekta/payment_method.rb +4 -0
- data/lib/conekta/payment_source.rb +17 -0
- data/lib/conekta/payout.rb +7 -0
- data/lib/conekta/payout_method.rb +17 -0
- data/lib/conekta/plan.rb +16 -0
- data/lib/conekta/refund.rb +6 -0
- data/lib/conekta/requestor.rb +80 -0
- data/lib/conekta/resource.rb +54 -0
- data/lib/conekta/return.rb +12 -0
- data/lib/conekta/shipping_contact.rb +19 -0
- data/lib/conekta/shipping_line.rb +20 -0
- data/lib/conekta/subscription.rb +25 -0
- data/lib/conekta/tax_line.rb +19 -0
- data/lib/conekta/token.rb +8 -0
- data/lib/conekta/transfer.rb +7 -0
- data/lib/conekta/util.rb +136 -0
- data/lib/conekta/version.rb +3 -0
- data/lib/conekta/webhook.rb +12 -0
- data/lib/conekta/webhook_log.rb +4 -0
- data/lib/conekta.rb +101 -0
- data/lib/ssl_data/ca_bundle.crt +3955 -0
- data/locales/en.yml +9 -0
- data/locales/es.yml +10 -0
- data/readme_files/banner.png +0 -0
- data/readme_files/conekta-badge.png +0 -0
- data/readme_files/ruby-badge.png +0 -0
- data/spec/conekta/1.0.0/.DS_Store +0 -0
- data/spec/conekta/1.0.0/card_spec.rb +40 -0
- data/spec/conekta/1.0.0/charge_spec.rb +152 -0
- data/spec/conekta/1.0.0/customer_spec.rb +147 -0
- data/spec/conekta/1.0.0/error_spec.rb +69 -0
- data/spec/conekta/1.0.0/event_spec.rb +26 -0
- data/spec/conekta/1.0.0/log_spec.rb +20 -0
- data/spec/conekta/1.0.0/payout_spec.rb +60 -0
- data/spec/conekta/1.0.0/plan_spec.rb +53 -0
- data/spec/conekta/1.0.0/token_spec.rb +5 -0
- data/spec/conekta/1.0.0/webhook_spec.rb +36 -0
- data/spec/conekta/2.0.0/customer_spec.rb +77 -0
- data/spec/conekta/2.0.0/discount_line_spec.rb +49 -0
- data/spec/conekta/2.0.0/error_spec.rb +61 -0
- data/spec/conekta/2.0.0/line_item_spec.rb +53 -0
- data/spec/conekta/2.0.0/list_spec.rb +29 -0
- data/spec/conekta/2.0.0/order_spec.rb +291 -0
- data/spec/conekta/2.0.0/payee_spec.rb +55 -0
- data/spec/conekta/2.0.0/shipping_contact_spec.rb +60 -0
- data/spec/conekta/2.0.0/shipping_line_spec.rb +53 -0
- data/spec/conekta/2.0.0/source_spec.rb +31 -0
- data/spec/conekta/2.0.0/tax_line_spec.rb +44 -0
- data/spec/conekta/2.0.0/transfer_spec.rb +59 -0
- data/spec/conekta_spec.rb +29 -0
- data/spec/spec_helper.rb +14 -0
- data/spec/support/fixtures/orders.json +1127 -0
- data/spec/support/shared_context.rb +49 -0
- metadata +229 -0
| @@ -0,0 +1,82 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              class Customer < Resource
         | 
| 3 | 
            +
                include Conekta::Operations::Find
         | 
| 4 | 
            +
                include Conekta::Operations::Where
         | 
| 5 | 
            +
                include Conekta::Operations::Create
         | 
| 6 | 
            +
                include Conekta::Operations::Delete
         | 
| 7 | 
            +
                include Conekta::Operations::Update
         | 
| 8 | 
            +
                include Conekta::Operations::CustomAction
         | 
| 9 | 
            +
                include Conekta::Operations::CreateMember
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                attr_accessor :livemode, :name, :email, :phone, :default_shipping_contact_id,
         | 
| 12 | 
            +
                              :referrer, :account_age,
         | 
| 13 | 
            +
                              :paid_transactions, :first_paid_at, :corporate, :default_payment_source_id,
         | 
| 14 | 
            +
                              :shipping_contacts, :subscription, :payment_sources, :cards
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                def initialize(id=nil)
         | 
| 17 | 
            +
                  @id = id
         | 
| 18 | 
            +
                  @payment_sources ||= List.new("PaymentSource", {})
         | 
| 19 | 
            +
                  @shipping_contacts ||= List.new("ShippingContacts", {})
         | 
| 20 | 
            +
                  super(id)
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def load_from(response=nil)
         | 
| 24 | 
            +
                  if response
         | 
| 25 | 
            +
                    super
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  customer = self
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  if Conekta.api_version == "2.0.0"
         | 
| 31 | 
            +
                    submodels = [:payment_sources, :shipping_contacts]
         | 
| 32 | 
            +
                    create_submodels_lists(customer, submodels)
         | 
| 33 | 
            +
                  else
         | 
| 34 | 
            +
                    submodels = [:cards]
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    submodels.each do |submodel|
         | 
| 37 | 
            +
                      self.send(submodel).each do |k,v|
         | 
| 38 | 
            +
                        if !v.respond_to? :deleted or !v.deleted
         | 
| 39 | 
            +
                          v.create_attr('customer', customer)
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                          self.send(submodel).set_val(k,v)
         | 
| 42 | 
            +
                        end
         | 
| 43 | 
            +
                      end
         | 
| 44 | 
            +
                    end
         | 
| 45 | 
            +
                  end
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                  if self.respond_to? :subscription and self.subscription
         | 
| 48 | 
            +
                     self.subscription.create_attr('customer', customer)
         | 
| 49 | 
            +
                  end
         | 
| 50 | 
            +
                end
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                def create_card(params)
         | 
| 53 | 
            +
                  self.create_member_with_relation('cards', params, self)
         | 
| 54 | 
            +
                end
         | 
| 55 | 
            +
             | 
| 56 | 
            +
                def create_payment_source(params)
         | 
| 57 | 
            +
                  self.create_member_with_relation('payment_sources', params, self)
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
             | 
| 60 | 
            +
                def create_offline_recurrent_reference(params)
         | 
| 61 | 
            +
                  self.create_member_with_relation('payment_sources', params, self)
         | 
| 62 | 
            +
                end
         | 
| 63 | 
            +
             | 
| 64 | 
            +
                def create_subscription(params)
         | 
| 65 | 
            +
                  self.create_member('subscription', params)
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                def create_shipping_contact(params)
         | 
| 69 | 
            +
                  self.create_member_with_relation('shipping_contacts', params, self)
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                def create_submodels_lists(customer, submodels)
         | 
| 73 | 
            +
                  submodels.each do |submodel|
         | 
| 74 | 
            +
                    self.send(submodel).each do |k, v|
         | 
| 75 | 
            +
                      v.create_attr('customer', customer)
         | 
| 76 | 
            +
             | 
| 77 | 
            +
                      self.send(submodel).set_val(k,v)
         | 
| 78 | 
            +
                    end if self.respond_to?(submodel) && !self.send(submodel).nil?
         | 
| 79 | 
            +
                  end
         | 
| 80 | 
            +
                end
         | 
| 81 | 
            +
              end
         | 
| 82 | 
            +
            end
         | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              class Destination < Resource
         | 
| 3 | 
            +
                include Conekta::Operations::Delete
         | 
| 4 | 
            +
                include Conekta::Operations::Update
         | 
| 5 | 
            +
                include Conekta::Operations::CustomAction
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                def _url
         | 
| 8 | 
            +
                  ensure_id
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                  self.payee._url + self.class._url + "/" + id
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                def delete
         | 
| 14 | 
            +
                  self.delete_member('payee','destinations')
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
              end
         | 
| 17 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              class DiscountLine < Resource
         | 
| 3 | 
            +
                include Conekta::Operations::Delete
         | 
| 4 | 
            +
                include Conekta::Operations::Update
         | 
| 5 | 
            +
                include Conekta::Operations::CustomAction
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                attr_accessor :code, :amount, :type, :parent_id
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                def _url
         | 
| 10 | 
            +
                  ensure_id
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                  "#{self.order._url}#{self.class._url}/#{id}"
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def delete
         | 
| 16 | 
            +
                  self.delete_member('order', 'discount_lines')
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,99 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              class Error < StandardError
         | 
| 3 | 
            +
                attr_reader :message, :type, :log_id, :details, :data
         | 
| 4 | 
            +
                
         | 
| 5 | 
            +
                def initialize(options={})
         | 
| 6 | 
            +
                  @type = options["type"]
         | 
| 7 | 
            +
                  @log_id = options["log_id"]
         | 
| 8 | 
            +
                  if options["details"]
         | 
| 9 | 
            +
                    @details = options["details"].collect{|details|
         | 
| 10 | 
            +
                      Conekta::ErrorDetails.new(details)
         | 
| 11 | 
            +
                    }
         | 
| 12 | 
            +
                  else
         | 
| 13 | 
            +
                    temp_details = Conekta::ErrorDetails.new({
         | 
| 14 | 
            +
                        "message" => options["message_to_purchaser"],
         | 
| 15 | 
            +
                        "debug_message" => options["message"],
         | 
| 16 | 
            +
                        "param" => options["param"]
         | 
| 17 | 
            +
                      })
         | 
| 18 | 
            +
                    @details = [temp_details]
         | 
| 19 | 
            +
                  end
         | 
| 20 | 
            +
                  @message = @details.first.debug_message
         | 
| 21 | 
            +
                  @data = options["data"]
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                  super
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                def class_name
         | 
| 27 | 
            +
                  self.class.name.split('::')[-1]
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                def self.error_handler(response, http_status)
         | 
| 31 | 
            +
                  if http_status.to_s.empty? || http_status == 0
         | 
| 32 | 
            +
                    NoConnectionError.new({
         | 
| 33 | 
            +
                      "details" => [
         | 
| 34 | 
            +
                        {
         | 
| 35 | 
            +
                          "debug_message" => I18n.t(
         | 
| 36 | 
            +
                            'error.requestor.connection',
         | 
| 37 | 
            +
                            { base: Conekta.api_base, locale: :en }
         | 
| 38 | 
            +
                          ),
         | 
| 39 | 
            +
                          "message" => I18n.t(
         | 
| 40 | 
            +
                            'error.requestor.connection_purchaser',
         | 
| 41 | 
            +
                            { locale: Conekta.locale.to_sym }
         | 
| 42 | 
            +
                          ),
         | 
| 43 | 
            +
                          "code" => "error.requestor.connection"
         | 
| 44 | 
            +
                        }
         | 
| 45 | 
            +
                      ]
         | 
| 46 | 
            +
                    })
         | 
| 47 | 
            +
                  else
         | 
| 48 | 
            +
                    case http_status
         | 
| 49 | 
            +
                    when -1, 0
         | 
| 50 | 
            +
                      NoConnectionError.new(response)
         | 
| 51 | 
            +
                    when 400
         | 
| 52 | 
            +
                      MalformedRequestError.new(response)
         | 
| 53 | 
            +
                    when 401
         | 
| 54 | 
            +
                      AuthenticationError.new(response)
         | 
| 55 | 
            +
                    when 402
         | 
| 56 | 
            +
                      ProcessingError.new(response)
         | 
| 57 | 
            +
                    when 404
         | 
| 58 | 
            +
                      ResourceNotFoundError.new(response)
         | 
| 59 | 
            +
                    when 409
         | 
| 60 | 
            +
                      VersionConflictError.new(response)
         | 
| 61 | 
            +
                    when 422
         | 
| 62 | 
            +
                      ParameterValidationError.new(response)
         | 
| 63 | 
            +
                    when 428
         | 
| 64 | 
            +
                      PreconditionRequiredError.new(response)
         | 
| 65 | 
            +
                    when 500
         | 
| 66 | 
            +
                      ApiError.new(response)
         | 
| 67 | 
            +
                    else
         | 
| 68 | 
            +
                      Error.new(response)
         | 
| 69 | 
            +
                    end
         | 
| 70 | 
            +
                  end
         | 
| 71 | 
            +
                end
         | 
| 72 | 
            +
              end
         | 
| 73 | 
            +
              class ApiError < Error    
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
              
         | 
| 76 | 
            +
              class NoConnectionError < Error 
         | 
| 77 | 
            +
              end
         | 
| 78 | 
            +
             | 
| 79 | 
            +
              class AuthenticationError < Error 
         | 
| 80 | 
            +
              end
         | 
| 81 | 
            +
             | 
| 82 | 
            +
              class ParameterValidationError < Error 
         | 
| 83 | 
            +
              end
         | 
| 84 | 
            +
             | 
| 85 | 
            +
              class ProcessingError < Error 
         | 
| 86 | 
            +
              end
         | 
| 87 | 
            +
             | 
| 88 | 
            +
              class ResourceNotFoundError < Error 
         | 
| 89 | 
            +
              end
         | 
| 90 | 
            +
             | 
| 91 | 
            +
              class VersionConflictError < Error 
         | 
| 92 | 
            +
              end
         | 
| 93 | 
            +
             | 
| 94 | 
            +
              class PreconditionRequiredError < Error 
         | 
| 95 | 
            +
              end
         | 
| 96 | 
            +
             | 
| 97 | 
            +
              class MalformedRequestError < Error 
         | 
| 98 | 
            +
              end
         | 
| 99 | 
            +
            end
         | 
| @@ -0,0 +1,14 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              class ErrorDetails < ConektaObject
         | 
| 3 | 
            +
                attr_reader :debug_message, :message, :param, :code
         | 
| 4 | 
            +
                
         | 
| 5 | 
            +
                def initialize(options={})
         | 
| 6 | 
            +
                  load_from(options)
         | 
| 7 | 
            +
                  @debug_message = options["debug_message"]
         | 
| 8 | 
            +
                  @message = options["message"]
         | 
| 9 | 
            +
                  @param = options["param"]
         | 
| 10 | 
            +
                  @code = options["code"]
         | 
| 11 | 
            +
                  super()
         | 
| 12 | 
            +
                end
         | 
| 13 | 
            +
              end
         | 
| 14 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              class LineItem < Resource
         | 
| 3 | 
            +
                include Conekta::Operations::Delete
         | 
| 4 | 
            +
                include Conekta::Operations::Update
         | 
| 5 | 
            +
                include Conekta::Operations::CustomAction
         | 
| 6 | 
            +
             | 
| 7 | 
            +
                attr_accessor :name, :description, :unit_price, :quantity,
         | 
| 8 | 
            +
                              :sku, :shippable, :tags, :brand, :type,
         | 
| 9 | 
            +
                              :parent_id
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                def _url
         | 
| 12 | 
            +
                  ensure_id
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                  "#{self.order._url}#{self.class._url}/#{id}"
         | 
| 15 | 
            +
                end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
                def delete
         | 
| 18 | 
            +
                  self.delete_member('order','line_items')
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
    
        data/lib/conekta/list.rb
    ADDED
    
    | @@ -0,0 +1,59 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              class List < ConektaObject
         | 
| 3 | 
            +
                attr_reader :elements_type, :params, :has_more, :total
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                def initialize(elements_type, params)
         | 
| 6 | 
            +
                  super()
         | 
| 7 | 
            +
                  @elements_type = elements_type
         | 
| 8 | 
            +
                  @params        = (params || {})
         | 
| 9 | 
            +
                  @total         = 0
         | 
| 10 | 
            +
                end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                def add_element(element)
         | 
| 13 | 
            +
                  element =
         | 
| 14 | 
            +
                    Conekta::Util.convert_to_conekta_object(element['object'], element)
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                  self[@total]        = element
         | 
| 17 | 
            +
                  self.values[@total] = element
         | 
| 18 | 
            +
                  @total              = @total + 1
         | 
| 19 | 
            +
             | 
| 20 | 
            +
                  self
         | 
| 21 | 
            +
                end
         | 
| 22 | 
            +
             | 
| 23 | 
            +
                def next(options={})
         | 
| 24 | 
            +
                  if self.size > 0
         | 
| 25 | 
            +
                    @params["next"] = self.last.id
         | 
| 26 | 
            +
                  end
         | 
| 27 | 
            +
             | 
| 28 | 
            +
                  @params["previous"] = nil
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  move_cursor(options[:limit])
         | 
| 31 | 
            +
                end
         | 
| 32 | 
            +
             | 
| 33 | 
            +
                def previous(options={})
         | 
| 34 | 
            +
                  if self.size > 0
         | 
| 35 | 
            +
                    @params["previous"] = self.first.id
         | 
| 36 | 
            +
                  end
         | 
| 37 | 
            +
             | 
| 38 | 
            +
                  @params["next"] = nil
         | 
| 39 | 
            +
             | 
| 40 | 
            +
                  move_cursor(options[:limit])
         | 
| 41 | 
            +
                end
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                def load_from(response)
         | 
| 44 | 
            +
                  @has_more       = response["has_more"]
         | 
| 45 | 
            +
                  @total          = response["total"]
         | 
| 46 | 
            +
                  self.map{|key, _| self.unset_key(key) }
         | 
| 47 | 
            +
                  super(response["data"])
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                private
         | 
| 51 | 
            +
             | 
| 52 | 
            +
                def move_cursor(limit)
         | 
| 53 | 
            +
                  @params["limit"] = limit if !limit.nil? && !limit.to_s.empty?
         | 
| 54 | 
            +
                  _url = Util.types[@elements_type.downcase]._url
         | 
| 55 | 
            +
                  response = Requestor.new.request(:get, _url, @params)
         | 
| 56 | 
            +
                  self.load_from(response)
         | 
| 57 | 
            +
                end
         | 
| 58 | 
            +
              end
         | 
| 59 | 
            +
            end
         | 
    
        data/lib/conekta/log.rb
    ADDED
    
    | @@ -0,0 +1,10 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              class Log < Resource
         | 
| 3 | 
            +
                include Conekta::Operations::Where
         | 
| 4 | 
            +
                include Conekta::Operations::Find
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                attr_accessor :method, :url, :status, :version, :ip_address, :related,
         | 
| 7 | 
            +
                              :request_body, :response_body, :request_headers,
         | 
| 8 | 
            +
                              :response_headers, :created_at, :query_string
         | 
| 9 | 
            +
              end
         | 
| 10 | 
            +
            end
         | 
| @@ -0,0 +1,19 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              module Operations
         | 
| 3 | 
            +
                module Create
         | 
| 4 | 
            +
                  module ClassMethods
         | 
| 5 | 
            +
                    def create(api_key, params)
         | 
| 6 | 
            +
                      _url = Util.types[self.class_name.downcase]._url
         | 
| 7 | 
            +
                      response = Requestor.new(api_key).request(:post, _url, params)
         | 
| 8 | 
            +
                      instance = self.new
         | 
| 9 | 
            +
                      instance.load_from(response)
         | 
| 10 | 
            +
                      instance.api_key = api_key
         | 
| 11 | 
            +
                      instance
         | 
| 12 | 
            +
                    end
         | 
| 13 | 
            +
                  end
         | 
| 14 | 
            +
                  def self.included(base)
         | 
| 15 | 
            +
                    base.extend(ClassMethods)
         | 
| 16 | 
            +
                  end
         | 
| 17 | 
            +
                end
         | 
| 18 | 
            +
              end
         | 
| 19 | 
            +
            end
         | 
| @@ -0,0 +1,40 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              module Operations
         | 
| 3 | 
            +
                module CreateMember
         | 
| 4 | 
            +
                  def create_member(api_key, member, params)
         | 
| 5 | 
            +
                    _url     = [self._url, member].join('/')
         | 
| 6 | 
            +
                    member   = member.to_sym
         | 
| 7 | 
            +
                    response = Requestor.new(api_key).request(:post, _url, params)
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                    if self.send(member) &&
         | 
| 10 | 
            +
                       (self.send(member).class.class_name == "ConektaObject" ||
         | 
| 11 | 
            +
                        self.send(member).class.class_name == "List")
         | 
| 12 | 
            +
                      arr = []
         | 
| 13 | 
            +
             | 
| 14 | 
            +
                      if self.send(member).class.class_name == "List"
         | 
| 15 | 
            +
                        self.send(member).add_element(response)
         | 
| 16 | 
            +
                      else
         | 
| 17 | 
            +
                        self.method(member).call.values.each do |_,v|
         | 
| 18 | 
            +
                          arr << v.to_hash
         | 
| 19 | 
            +
                        end
         | 
| 20 | 
            +
             | 
| 21 | 
            +
                        arr << response
         | 
| 22 | 
            +
                        self.send(member).load_from(arr)
         | 
| 23 | 
            +
                        self.load_from
         | 
| 24 | 
            +
                      end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                      instances = self.send(member)
         | 
| 27 | 
            +
                      instance = instances.last
         | 
| 28 | 
            +
                    else
         | 
| 29 | 
            +
                      instance = Util.types[member.to_s].new()
         | 
| 30 | 
            +
                      instance.load_from(response)
         | 
| 31 | 
            +
                      self.create_attr(member.to_s, instance)
         | 
| 32 | 
            +
                      self.set_val(member.to_sym, instance)
         | 
| 33 | 
            +
                      self.load_from
         | 
| 34 | 
            +
                    end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                    instance
         | 
| 37 | 
            +
                  end
         | 
| 38 | 
            +
                end
         | 
| 39 | 
            +
              end
         | 
| 40 | 
            +
            end
         | 
| @@ -0,0 +1,13 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              module Operations
         | 
| 3 | 
            +
                module CustomAction
         | 
| 4 | 
            +
                  def custom_action(method, action=nil, params=nil)
         | 
| 5 | 
            +
                    _url     = action ? [self._url, action].join('/') : self._url
         | 
| 6 | 
            +
                    response = Requestor.new.request(method, _url, params)
         | 
| 7 | 
            +
             | 
| 8 | 
            +
                    self.load_from(response)
         | 
| 9 | 
            +
                    self
         | 
| 10 | 
            +
                  end
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
            end
         | 
| @@ -0,0 +1,45 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              module Operations
         | 
| 3 | 
            +
                module Delete
         | 
| 4 | 
            +
                  def delete
         | 
| 5 | 
            +
                    self.custom_action(:delete, nil, nil)
         | 
| 6 | 
            +
                    self
         | 
| 7 | 
            +
                  end
         | 
| 8 | 
            +
                  def delete_member(parent, member)
         | 
| 9 | 
            +
                    self.custom_action(:delete, nil, nil)
         | 
| 10 | 
            +
             | 
| 11 | 
            +
                    parent = parent.to_sym
         | 
| 12 | 
            +
                    member = member.to_sym
         | 
| 13 | 
            +
                    obj    = self.method(parent).call.method(member).call
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                    if obj.class.class_name == "ConektaObject"
         | 
| 16 | 
            +
                      self.method(parent).call.method(member).call.each do |(k, v)|
         | 
| 17 | 
            +
                        if v.id == self.id
         | 
| 18 | 
            +
                          self.method(parent).call.method(member).call[k] = nil
         | 
| 19 | 
            +
                          # Shift hash array
         | 
| 20 | 
            +
                          shift = false
         | 
| 21 | 
            +
                          self.method(parent).call.method(member).call.each_with_index do |v,i|
         | 
| 22 | 
            +
                            if shift
         | 
| 23 | 
            +
                              self.method(parent).call.method(member).call.set_val(i-1,v[1])
         | 
| 24 | 
            +
                              self.method(parent).call.method(member).call[i-1] = v[1]
         | 
| 25 | 
            +
                            end
         | 
| 26 | 
            +
                            if v[1] == nil
         | 
| 27 | 
            +
                              shift = true
         | 
| 28 | 
            +
                            end
         | 
| 29 | 
            +
                          end
         | 
| 30 | 
            +
                          n_members = self.method(parent).call.method(member).call.count
         | 
| 31 | 
            +
                          last_index = n_members - 1
         | 
| 32 | 
            +
                          # Remove last member because the hash array was shifted
         | 
| 33 | 
            +
                          self.method(parent).call.method(member).call.unset_key(last_index)
         | 
| 34 | 
            +
                          self.method(parent).call.method(member).call.delete(last_index)
         | 
| 35 | 
            +
                          break
         | 
| 36 | 
            +
                        end
         | 
| 37 | 
            +
                      end
         | 
| 38 | 
            +
                    else
         | 
| 39 | 
            +
                      self.create_attr(member.to_s, nil)
         | 
| 40 | 
            +
                    end
         | 
| 41 | 
            +
                    self
         | 
| 42 | 
            +
                  end
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| @@ -0,0 +1,21 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              module Operations
         | 
| 3 | 
            +
                module Find
         | 
| 4 | 
            +
                  module ClassMethods
         | 
| 5 | 
            +
                    def find(api_key, id)
         | 
| 6 | 
            +
                      instance = self.new(id)
         | 
| 7 | 
            +
                      response = Requestor.new(api_key).request(:get, instance._url)
         | 
| 8 | 
            +
                      instance.load_from(response)
         | 
| 9 | 
            +
                      instance.api_key = api_key
         | 
| 10 | 
            +
                      instance
         | 
| 11 | 
            +
                    end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                    # <b>DEPRECATED:</b> Please use <tt>find</tt> instead.
         | 
| 14 | 
            +
                    alias_method :retrieve, :find
         | 
| 15 | 
            +
                  end
         | 
| 16 | 
            +
                  def self.included(base)
         | 
| 17 | 
            +
                    base.extend(ClassMethods)
         | 
| 18 | 
            +
                  end
         | 
| 19 | 
            +
                end
         | 
| 20 | 
            +
              end
         | 
| 21 | 
            +
            end
         | 
| @@ -0,0 +1,30 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              module Operations
         | 
| 3 | 
            +
                module Where
         | 
| 4 | 
            +
             | 
| 5 | 
            +
                  def self.handle_type_of_paging(response, class_name, params)
         | 
| 6 | 
            +
                    if response.kind_of?(Hash) && response["object"] == "list"
         | 
| 7 | 
            +
                      List.new(class_name, params)
         | 
| 8 | 
            +
                    else
         | 
| 9 | 
            +
                      ConektaObject.new
         | 
| 10 | 
            +
                    end
         | 
| 11 | 
            +
                  end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                  module ClassMethods
         | 
| 14 | 
            +
                    def where(params=nil)
         | 
| 15 | 
            +
                      _url = Util.types[self.class_name.downcase]._url
         | 
| 16 | 
            +
                      response = Requestor.new.request(:get, _url, params)
         | 
| 17 | 
            +
                      instance = ::Conekta::Operations::Where.handle_type_of_paging(response, self.class_name, params)
         | 
| 18 | 
            +
                      instance.load_from(response)
         | 
| 19 | 
            +
                      instance
         | 
| 20 | 
            +
                    end
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                    # <b>DEPRECATED:</b> Please use <tt>where</tt> instead.
         | 
| 23 | 
            +
                    alias_method :all, :where
         | 
| 24 | 
            +
                  end
         | 
| 25 | 
            +
                  def self.included(base)
         | 
| 26 | 
            +
                    base.extend(ClassMethods)
         | 
| 27 | 
            +
                  end
         | 
| 28 | 
            +
                end
         | 
| 29 | 
            +
              end
         | 
| 30 | 
            +
            end
         | 
| @@ -0,0 +1,87 @@ | |
| 1 | 
            +
            module Conekta
         | 
| 2 | 
            +
              class Order < Resource
         | 
| 3 | 
            +
                include Conekta::Operations::Find
         | 
| 4 | 
            +
                include Conekta::Operations::Where
         | 
| 5 | 
            +
                include Conekta::Operations::Create
         | 
| 6 | 
            +
                include Conekta::Operations::Update
         | 
| 7 | 
            +
                include Conekta::Operations::CreateMember
         | 
| 8 | 
            +
                include Conekta::Operations::CustomAction
         | 
| 9 | 
            +
             | 
| 10 | 
            +
                attr_accessor :livemode, :amount, :payment_status, :customer_id, :currency,
         | 
| 11 | 
            +
                              :metadata, :created_at, :updated_at, :tax_lines, :line_items,
         | 
| 12 | 
            +
                              :shipping_lines, :discount_lines, :shipping_contact, :charges,
         | 
| 13 | 
            +
                              :api_key
         | 
| 14 | 
            +
             | 
| 15 | 
            +
                def initialize(id=nil)
         | 
| 16 | 
            +
                  @id = id
         | 
| 17 | 
            +
                  @line_items ||= List.new("LineItem", {})
         | 
| 18 | 
            +
                  @tax_lines ||= List.new("TaxLine", {})
         | 
| 19 | 
            +
                  @shipping_lines ||= List.new("ShippingLine", {})
         | 
| 20 | 
            +
                  @discount_lines ||= List.new("DiscountLine", {})
         | 
| 21 | 
            +
                  @charges ||= List.new("Charge", {})
         | 
| 22 | 
            +
                  super(id)
         | 
| 23 | 
            +
                end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                def load_from(response = nil)
         | 
| 26 | 
            +
                  if response
         | 
| 27 | 
            +
                    super
         | 
| 28 | 
            +
                  end
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  order     = self
         | 
| 31 | 
            +
                  submodels = [:line_items, :tax_lines, :shipping_lines, :discount_lines,
         | 
| 32 | 
            +
                               :charges]
         | 
| 33 | 
            +
                  create_submodels_lists(order, submodels)
         | 
| 34 | 
            +
                end
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                #Attribute accessors
         | 
| 37 | 
            +
                def create_line_item(params)
         | 
| 38 | 
            +
                  self.create_member_with_relation(api_key, 'line_items', params, self)
         | 
| 39 | 
            +
                end
         | 
| 40 | 
            +
             | 
| 41 | 
            +
                def create_tax_line(params)
         | 
| 42 | 
            +
                  self.create_member_with_relation(api_key, 'tax_lines', params, self)
         | 
| 43 | 
            +
                end
         | 
| 44 | 
            +
             | 
| 45 | 
            +
                def create_shipping_line(params)
         | 
| 46 | 
            +
                  self.create_member_with_relation(api_key, 'shipping_lines', params, self)
         | 
| 47 | 
            +
                end
         | 
| 48 | 
            +
             | 
| 49 | 
            +
                def create_discount_line(params)
         | 
| 50 | 
            +
                  self.create_member_with_relation(api_key, 'discount_lines', params, self)
         | 
| 51 | 
            +
                end
         | 
| 52 | 
            +
             | 
| 53 | 
            +
                def create_charge(params)
         | 
| 54 | 
            +
                  self.create_member(api_key, 'charges', params)
         | 
| 55 | 
            +
                end
         | 
| 56 | 
            +
             | 
| 57 | 
            +
                def create_shipping_contact(params)
         | 
| 58 | 
            +
                  self.update(shipping_contact: params).shipping_contact
         | 
| 59 | 
            +
                end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
            		#State transitions
         | 
| 62 | 
            +
                def authorize_capture(params={})
         | 
| 63 | 
            +
                  custom_action(:post, 'capture', params)
         | 
| 64 | 
            +
                end
         | 
| 65 | 
            +
             | 
| 66 | 
            +
                def void(params={})
         | 
| 67 | 
            +
                  custom_action(:post, 'void', params)
         | 
| 68 | 
            +
                end
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                def refund(params={})
         | 
| 71 | 
            +
                  custom_action(:post, 'refund', params)
         | 
| 72 | 
            +
                end
         | 
| 73 | 
            +
             | 
| 74 | 
            +
                private
         | 
| 75 | 
            +
             | 
| 76 | 
            +
                def create_submodels_lists(order, submodels)
         | 
| 77 | 
            +
                  submodels.each do |submodel|
         | 
| 78 | 
            +
                    self.send(submodel).each do |k, v|
         | 
| 79 | 
            +
                      v.create_attr('order', order)
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                      self.send(submodel).set_val(k,v)
         | 
| 82 | 
            +
                    end if self.respond_to?(submodel) && !self.send(submodel).nil?
         | 
| 83 | 
            +
                  end
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
             | 
| 86 | 
            +
              end
         | 
| 87 | 
            +
            end
         |