Skip to content

Commit

Permalink
Solve internal crashers, enhancements, tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OscarSwanros committed Jan 15, 2016
1 parent 16e01e0 commit bfc86aa
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 46 deletions.
4 changes: 0 additions & 4 deletions SwiftyOpenPay.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
DF2B62A41C4962B800279269 /* CardTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF2B62A31C4962B800279269 /* CardTest.swift */; };
DF31AB291C45BEDF00025798 /* SwiftyOpenPay.h in Headers */ = {isa = PBXBuildFile; fileRef = DF31AB281C45BEDF00025798 /* SwiftyOpenPay.h */; settings = {ATTRIBUTES = (Public, ); }; };
DF31AB301C45BEDF00025798 /* SwiftyOpenPay.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DF31AB251C45BEDF00025798 /* SwiftyOpenPay.framework */; };
DF31AB351C45BEDF00025798 /* SwiftyOpenPayTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF31AB341C45BEDF00025798 /* SwiftyOpenPayTests.swift */; };
DF31AB411C45BF9A00025798 /* Address.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF31AB401C45BF9A00025798 /* Address.swift */; };
DF31AB431C45C03A00025798 /* Card.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF31AB421C45C03A00025798 /* Card.swift */; };
DF31AB451C45C4B100025798 /* CardValidator.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF31AB441C45C4B100025798 /* CardValidator.swift */; };
Expand Down Expand Up @@ -68,7 +67,6 @@
DF31AB281C45BEDF00025798 /* SwiftyOpenPay.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftyOpenPay.h; sourceTree = "<group>"; };
DF31AB2A1C45BEDF00025798 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DF31AB2F1C45BEDF00025798 /* SwiftyOpenPayTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftyOpenPayTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
DF31AB341C45BEDF00025798 /* SwiftyOpenPayTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftyOpenPayTests.swift; sourceTree = "<group>"; };
DF31AB361C45BEDF00025798 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DF31AB401C45BF9A00025798 /* Address.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Address.swift; sourceTree = "<group>"; };
DF31AB421C45C03A00025798 /* Card.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Card.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -142,7 +140,6 @@
DF31AB331C45BEDF00025798 /* SwiftyOpenPayTests */ = {
isa = PBXGroup;
children = (
DF31AB341C45BEDF00025798 /* SwiftyOpenPayTests.swift */,
DF2B62A31C4962B800279269 /* CardTest.swift */,
DF31AB361C45BEDF00025798 /* Info.plist */,
);
Expand Down Expand Up @@ -293,7 +290,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
DF31AB351C45BEDF00025798 /* SwiftyOpenPayTests.swift in Sources */,
DF2B62A41C4962B800279269 /* CardTest.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
13 changes: 7 additions & 6 deletions SwiftyOpenPay/SwiftyOpenPay.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,16 @@ extension SwiftyOpenPay {
private func requestForURL(url: NSURL, method: HTTPMethod, payload: [String:AnyObject]? = nil) -> NSURLRequest {
let request = NSMutableURLRequest(URL: url, cachePolicy: NSURLRequestCachePolicy.ReloadIgnoringLocalAndRemoteCacheData, timeoutInterval: 30)

request.setValue("application/json;revision=1.1", forKey: "Accept")
request.setValue("application/json;revision=1.1", forHTTPHeaderField: "Accept")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.setValue("OpenPay-iOS/1.0.0", forKey: "User-Agent")
request.setValue("OpenPay-iOS/1.0.0", forHTTPHeaderField: "User-Agent")
request.HTTPMethod = method.rawValue

let authStr = "\(apiKey):"
let data = authStr.dataUsingEncoding(NSASCIIStringEncoding)
let value = data?.base64EncodedStringWithOptions(.EncodingEndLineWithCarriageReturn)

request.setValue("Basic \(value)", forKey: "Authorization")
request.setValue("Basic \(value)", forHTTPHeaderField: "Authorization")

if let payload = payload {
do {
Expand All @@ -108,10 +108,11 @@ extension SwiftyOpenPay {
let session = NSURLSession(configuration: NSURLSessionConfiguration.ephemeralSessionConfiguration())
let task = session.dataTaskWithRequest(request) { data, reponse, error in
guard
error != nil,
let data = data
let data = data where error === nil
else {
errorClosure?(error!)
if let error = error {
errorClosure?(error)
}
return
}

Expand Down
19 changes: 19 additions & 0 deletions SwiftyOpenPayTests/CardTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,4 +162,23 @@ class CardTests: XCTestCase {
}
}

func testInvalidMasterCardCardExpired() {
for number in masterCardNumbers! {
let myCard = Card(
holderName: "John Doe",
expirationMonth: "04",
expirationYear: "12",
address: address!,
number: number,
cvv2: "123"
)

do {
try myCard.isValid()
} catch {
assert(error as! CardValidator.CardValidationError == .InvalidCard)
}
}
}

}
36 changes: 0 additions & 36 deletions SwiftyOpenPayTests/SwiftyOpenPayTests.swift

This file was deleted.

0 comments on commit bfc86aa

Please sign in to comment.