Skip to content
This repository was archived by the owner on Jul 30, 2021. It is now read-only.

Commit 0ff65ce

Browse files
committed
finish renaming things
1 parent 0b93f95 commit 0ff65ce

19 files changed

+1505
-0
lines changed

PaymentKit/PTKAddressZip.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// PTKZip.h
3+
// PTKPayment Example
4+
//
5+
// Created by Alex MacCaw on 2/1/13.
6+
// Copyright (c) 2013 Stripe. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "PTKComponent.h"
11+
12+
@interface PTKAddressZip : PTKComponent {
13+
@protected
14+
NSString *_zip;
15+
}
16+
17+
@property (nonatomic, readonly) NSString *string;
18+
19+
+ (instancetype)addressZipWithString:(NSString *)string;
20+
- (instancetype)initWithString:(NSString *)string;
21+
22+
@end

PaymentKit/PTKAddressZip.m

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//
2+
// PTKZip.m
3+
// PTKPayment Example
4+
//
5+
// Created by Alex MacCaw on 2/1/13.
6+
// Copyright (c) 2013 Stripe. All rights reserved.
7+
//
8+
9+
#import "PTKAddressZip.h"
10+
11+
@implementation PTKAddressZip
12+
13+
+ (instancetype)addressZipWithString:(NSString *)string
14+
{
15+
return [[self alloc] initWithString:string];
16+
}
17+
18+
- (instancetype)initWithString:(NSString *)string
19+
{
20+
if (self = [super init]) {
21+
_zip = [string copy];
22+
}
23+
return self;
24+
}
25+
26+
- (NSString *)string
27+
{
28+
return _zip;
29+
}
30+
31+
- (BOOL)isValid
32+
{
33+
NSString *stripped = [_zip stringByReplacingOccurrencesOfString:@"\\s"
34+
withString:@""
35+
options:NSRegularExpressionSearch
36+
range:NSMakeRange(0, _zip.length)];
37+
38+
return stripped.length > 2;
39+
}
40+
41+
- (BOOL)isPartiallyValid
42+
{
43+
return _zip.length < 10;
44+
}
45+
46+
@end

PaymentKit/PTKCard.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// PTKCard.h
3+
// PTKPayment Example
4+
//
5+
// Created by Alex MacCaw on 1/31/13.
6+
// Copyright (c) 2013 Stripe. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@interface PTKCard : NSObject
12+
13+
@property (nonatomic, copy) NSString *number;
14+
@property (nonatomic, copy) NSString *cvc;
15+
@property (nonatomic, copy) NSString *addressZip;
16+
@property (nonatomic, assign) NSUInteger expMonth;
17+
@property (nonatomic, assign) NSUInteger expYear;
18+
19+
@property (nonatomic, readonly) NSString *last4;
20+
21+
@end

PaymentKit/PTKCard.m

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// PTKCard.m
3+
// PTKPayment Example
4+
//
5+
// Created by Alex MacCaw on 1/31/13.
6+
// Copyright (c) 2013 Stripe. All rights reserved.
7+
//
8+
9+
#import "PTKCard.h"
10+
11+
@implementation PTKCard
12+
13+
- (NSString *)last4
14+
{
15+
if (_number.length >= 4) {
16+
return [_number substringFromIndex:([_number length] - 4)];
17+
} else {
18+
return nil;
19+
}
20+
}
21+
22+
@end

PaymentKit/PTKCardCVC.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// PTKCardCVC.h
3+
// PTKPayment Example
4+
//
5+
// Created by Alex MacCaw on 1/22/13.
6+
// Copyright (c) 2013 Stripe. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "PTKCardType.h"
11+
#import "PTKComponent.h"
12+
13+
@interface PTKCardCVC : PTKComponent
14+
15+
@property (nonatomic, readonly) NSString *string;
16+
17+
+ (instancetype)cardCVCWithString:(NSString *)string;
18+
- (BOOL)isValidWithType:(PTKCardType)type;
19+
- (BOOL)isPartiallyValidWithType:(PTKCardType)type;
20+
21+
@end

PaymentKit/PTKCardCVC.m

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
//
2+
// PTKCardCVC.m
3+
// PTKPayment Example
4+
//
5+
// Created by Alex MacCaw on 1/22/13.
6+
// Copyright (c) 2013 Stripe. All rights reserved.
7+
//
8+
9+
#import "PTKCardCVC.h"
10+
11+
@implementation PTKCardCVC {
12+
@private
13+
NSString *_cvc;
14+
}
15+
16+
+ (instancetype)cardCVCWithString:(NSString *)string
17+
{
18+
return [[self alloc] initWithString:string];
19+
}
20+
21+
- (instancetype)initWithString:(NSString *)string
22+
{
23+
if (self = [super init]) {
24+
// Strip non-digits
25+
if (string) {
26+
_cvc = [string stringByReplacingOccurrencesOfString:@"\\D"
27+
withString:@""
28+
options:NSRegularExpressionSearch
29+
range:NSMakeRange(0, string.length)];
30+
} else {
31+
_cvc = [NSString string];
32+
}
33+
}
34+
return self;
35+
}
36+
37+
- (NSString *)string
38+
{
39+
return _cvc;
40+
}
41+
42+
- (BOOL)isValid
43+
{
44+
return _cvc.length >= 3 && _cvc.length <= 4;
45+
}
46+
47+
- (BOOL)isValidWithType:(PTKCardType)type
48+
{
49+
if (type == PTKCardTypeAmex) {
50+
return _cvc.length == 4;
51+
} else {
52+
return _cvc.length == 3;
53+
}
54+
}
55+
56+
- (BOOL)isPartiallyValid
57+
{
58+
return _cvc.length <= 4;
59+
}
60+
61+
- (BOOL)isPartiallyValidWithType:(PTKCardType)type
62+
{
63+
if (type == PTKCardTypeAmex) {
64+
return _cvc.length <= 4;
65+
} else {
66+
return _cvc.length <= 3;
67+
}
68+
}
69+
@end

PaymentKit/PTKCardExpiry.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//
2+
// PTKCardExpiry.h
3+
// PTKPayment Example
4+
//
5+
// Created by Alex MacCaw on 1/22/13.
6+
// Copyright (c) 2013 Stripe. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
#import "PTKComponent.h"
11+
12+
@interface PTKCardExpiry : PTKComponent
13+
14+
@property (nonatomic, readonly) NSUInteger month;
15+
@property (nonatomic, readonly) NSUInteger year;
16+
@property (nonatomic, readonly) NSString *formattedString;
17+
@property (nonatomic, readonly) NSString *formattedStringWithTrail;
18+
19+
+ (instancetype)cardExpiryWithString:(NSString *)string;
20+
- (instancetype)initWithString:(NSString *)string;
21+
- (BOOL)isValidLength;
22+
- (BOOL)isValidDate;
23+
24+
@end

0 commit comments

Comments
 (0)