Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add STPAPIClient method to convert ssn_last_4 to a Token #1432

Merged
merged 1 commit into from
Oct 31, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Stripe/PublicHeaders/STPAPIClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,14 @@ static NSString *const STPSDKVersion = @"18.1.0";
*/
- (void)createTokenWithPersonalIDNumber:(NSString *)pii completion:(__nullable STPTokenCompletionBlock)completion;

/**
Converts the last 4 SSN digits into a Stripe token using the Stripe API.

@param ssnLast4 The last 4 digits of the user's SSN. Cannot be nil.
@param completion The callback to run with the returned Stripe token (and any errors that may have occurred).
*/
- (void)createTokenWithSSNLast4:(NSString *)ssnLast4 completion:(STPTokenCompletionBlock)completion;

@end

#pragma mark Connect Accounts
Expand Down
8 changes: 7 additions & 1 deletion Stripe/STPAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,9 +277,15 @@ - (void)createTokenWithPersonalIDNumber:(NSString *)pii completion:(__nullable S
NSMutableDictionary *params = [@{@"pii": @{ @"personal_id_number": pii }} mutableCopy];
[[STPTelemetryClient sharedInstance] addTelemetryFieldsToParams:params];
[self createTokenWithParameters:params completion:completion];
[[STPTelemetryClient sharedInstance] sendTelemetryData];}

- (void)createTokenWithSSNLast4:(NSString *)ssnLast4 completion:(STPTokenCompletionBlock)completion {
NSMutableDictionary *params = [@{@"pii": @{ @"ssn_last_4": ssnLast4 }} mutableCopy];
[[STPTelemetryClient sharedInstance] addTelemetryFieldsToParams:params];
[self createTokenWithParameters:params completion:completion];
[[STPTelemetryClient sharedInstance] sendTelemetryData];
}

@end

#pragma mark - Connect Accounts
Expand Down
16 changes: 16 additions & 0 deletions Tests/Tests/STPPIIFunctionalTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,20 @@ - (void)testCreatePersonallyIdentifiableInformationToken {
[self waitForExpectationsWithTimeout:5.0f handler:nil];
}

- (void)testSSNLast4Token {
STPAPIClient *client = [[STPAPIClient alloc] initWithPublishableKey:@"pk_test_vOo1umqsYxSrP5UXfOeL3ecm"];

XCTestExpectation *expectation = [self expectationWithDescription:@"PII creation"];

[client createTokenWithSSNLast4:@"1234" completion:^(STPToken * _Nullable token, NSError * _Nullable error) {
[expectation fulfill];
XCTAssertNil(error, @"error should be nil %@", error.localizedDescription);
XCTAssertNotNil(token, @"token should not be nil");
XCTAssertNotNil(token.tokenId);
XCTAssertEqual(token.type, STPTokenTypePII);
}];

[self waitForExpectationsWithTimeout:5.0f handler:nil];
}

@end
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,25 @@ POST
application/json
Content-Type: application/json
Access-Control-Allow-Origin: *
access-control-allow-methods: GET, POST, HEAD, OPTIONS, DELETE
Server: nginx
access-control-allow-methods: GET, POST, HEAD, OPTIONS, DELETE
access-control-expose-headers: Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
access-control-max-age: 300
Cache-Control: no-cache, no-store
Date: Wed, 24 Jul 2019 23:23:07 GMT
Date: Wed, 30 Oct 2019 23:56:38 GMT
stripe-version: 2019-05-16
access-control-allow-credentials: true
Content-Length: 175
Strict-Transport-Security: max-age=31556926; includeSubDomains; preload
Connection: keep-alive
request-id: req_HTETf1BQbwtL3v
Strict-Transport-Security: max-age=31556926; includeSubDomains; preload
request-id: req_G0mrDBE9JwOmuv

{
"object" : "token",
"id" : "pii_1EztnbBbvEcIpqUbJEDM98Z2",
"id" : "pii_1FZR1mBbvEcIpqUbR2ADMXtG",
"livemode" : false,
"client_ip" : "8.21.168.117",
"created" : 1564010587,
"client_ip" : "8.21.168.115",
"created" : 1572479798,
"used" : false,
"type" : "pii"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
POST
/v1/tokens$
200
application/json
Content-Type: application/json
Access-Control-Allow-Origin: *
Server: nginx
access-control-allow-methods: GET, POST, HEAD, OPTIONS, DELETE
access-control-expose-headers: Request-Id, Stripe-Manage-Version, X-Stripe-External-Auth-Required, X-Stripe-Privileged-Session-Required
access-control-max-age: 300
Cache-Control: no-cache, no-store
Date: Wed, 30 Oct 2019 23:56:38 GMT
stripe-version: 2019-05-16
access-control-allow-credentials: true
Content-Length: 175
Connection: keep-alive
Strict-Transport-Security: max-age=31556926; includeSubDomains; preload
request-id: req_TqZBbf0VIoU6HU

{
"object" : "token",
"id" : "pii_1FZR1mBbvEcIpqUbmYvOI5c1",
"livemode" : false,
"client_ip" : "8.21.168.115",
"created" : 1572479798,
"used" : false,
"type" : "pii"
}