//
//  CreditCard.swift
//  Spreedly
//
//  Created by David Santoso on 10/8/15.
//  Copyright © 2015 Spreedly Inc. All rights reserved.
//

import Foundation

public class CreditCard {
    public var firstName, lastName, number, verificationValue, month, year: String?
    public var address1, address2, city, state, zip, country, phoneNumber: String?
    
    public init() {}
    
    public func isValid() -> Bool {
        if (number != nil &&
            verificationValue != nil &&
            month != nil &&
            year != nil) {
                return(true)
        } else {
            return(false)
        }
    }
    
    public static func extractMonth(expiration: String) -> String {
        return(self.splitExpirationString(expiration).first!)
    }
    
    public static func extractYear(expiration: String) -> String {
        return("20" + self.splitExpirationString(expiration).last!)
    }
    
    static func splitExpirationString(expiration: String) -> [String] {
        let expirationArray = expiration.componentsSeparatedByString("/")
        return expirationArray
    }
}
//
//  CreditCard.swift
//  Spreedly
//
//  Created by David Santoso on 10/8/15.
//  Copyright © 2015 Spreedly Inc. All rights reserved.
//

import Foundation

public class CreditCard {
    public var firstName, lastName, number, verificationValue, month, year: String?
    public var address1, address2, city, state, zip, country, phoneNumber: String?
    
    public init() {}
    
    public func isValid() -> Bool {
        if (firstName != nil &&
            lastName != nil &&
            number != nil &&
            verificationValue != nil &&
            month != nil &&
            year != nil) {
                return(true)
        } else {
            return(false)
        }
    }
    
    public static func extractMonth(expiration: String) -> String {
        return(self.splitExpirationString(expiration).first!)
    }
    
    public static func extractYear(expiration: String) -> String {
        return("20" + self.splitExpirationString(expiration).last!)
    }
    
    static func splitExpirationString(expiration: String) -> [String] {
        let expirationArray = expiration.componentsSeparatedByString("/")
        return expirationArray
    }
}
Include first name and last name in credit card validation
Include first name and last name in credit card validation
