Sha256: c7e5634666096b31446797ebcbf18daab4d5a43033288f4d06f3ec747ffaef73

Contents?: true

Size: 1.67 KB

Versions: 5

Compression:

Stored size: 1.67 KB

Contents

module MpApi
  
  class Token
    
    attr_reader :card_number, :expiration_year, :expiration_month, :security_code, :cardholder_name, :id
    def initialize(card_number:nil, expiration_year:nil, expiration_month:nil, security_code:nil, cardholder_name:nil, id:nil)
      @card_number = card_number
      @expiration_year = expiration_year
      @expiration_month = expiration_month
      @security_code = security_code
      @cardholder_name = cardholder_name
      @id = id
    end

    def build_json
      {
        card_number: card_number,
        expiration_year: expiration_year,
        expiration_month: expiration_month,
        security_code: security_code,
        cardholder: {
          name: cardholder_name
        }
      }
    end

    def create
      response = Client.new.create_token(JSON.dump(build_json))
      self.class.new(**self.class.build_hash(response))
    end

    def self.build_hash(response)
      {
        id: response['id'],
        expiration_year: response['expiration_year'],
        expiration_month: response['expiration_month'],
        cardholder_name: response['cardholder']['name']
      }
    end

  end
end

# {"id"=>"78558e7bbb73b8939df27269fb6dcbf5",
#   "first_six_digits"=>"503143",
#   "expiration_month"=>11,
#   "expiration_year"=>2025,
#   "last_four_digits"=>"6351",
#   "cardholder"=>{"identification"=>{}, "name"=>"APRO"},
#   "status"=>"active",
#   "date_created"=>"2023-11-27T09:42:13.887-04:00",
#   "date_last_updated"=>"2023-11-27T09:42:13.887-04:00",
#   "date_due"=>"2023-12-05T09:42:13.887-04:00",
#   "luhn_validation"=>true,
#   "live_mode"=>false,
#   "require_esc"=>false,
#   "card_number_length"=>16,
#   "security_code_length"=>3}

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mp_api-0.1.8 lib/mp_api/token.rb
mp_api-0.1.7 lib/mp_api/token.rb
mp_api-0.1.6 lib/mp_api/token.rb
mp_api-0.1.5 lib/mp_api/token.rb
mp_api-0.1.4 lib/mp_api/token.rb