-
-
Save matthewarkin/2f19181be39578921cbf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
NSDictionary *achInfo = @{@"country":@"US", @"routing_number":rountingNumber, @"account_number":accountNumber}; | |
NSDictionary *dataDictionary = @{@"bank_account[country]": @"US", | |
@"bank_account[routing_number]" : rountingNumber, | |
@"bank_account[account_number]" : accountNumber}; | |
NSURL *url = [NSURL URLWithString:@"https://api.stripe.com/v1/tokens"]; | |
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url | |
cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10]; | |
[request setHTTPMethod:@"POST"]; | |
[request setValue:@"Basic sk_live_key" forHTTPHeaderField:@"Authorization"]; | |
[request setValue: @"application/json" forHTTPHeaderField:@"Content-Type"]; | |
NSMutableData *postBody = [NSMutableData data]; | |
NSData *plainData = [@"bank_account[country]: US" dataUsingEncoding:NSUTF8StringEncoding]; | |
NSString *base64String = [plainData base64EncodedStringWithOptions:0]; | |
[postBody appendData:[base64String dataUsingEncoding:NSUTF8StringEncoding]]; | |
NSData *plainData2 = [@"bank_account[routing_number]: %@" dataUsingEncoding:NSUTF8StringEncoding]; | |
NSString *base64String2 = [plainData2 base64EncodedStringWithOptions:0]; | |
[postBody appendData:[[NSString stringWithFormat:base64String2, rountingNumber] dataUsingEncoding:NSUTF8StringEncoding]]; | |
NSData *plainData3 = [@"bank_account[account_number]: %@" dataUsingEncoding:NSUTF8StringEncoding]; | |
NSString *base64String3 = [plainData3 base64EncodedStringWithOptions:0]; | |
[postBody appendData:[[NSString stringWithFormat:base64String3, accountNumber] dataUsingEncoding:NSUTF8StringEncoding]]; | |
[request setHTTPBody: postBody]; | |
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request]; | |
// op.responseSerializer = [AFJSONResponseSerializer serializer]; | |
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { | |
NSLog(@"JSON responseObject: %@ ",responseObject); | |
} failure:^(AFHTTPRequestOperation *operation, NSError *error) { | |
NSLog(@"Error: %@", [error localizedDescription]); | |
}]; | |
NSURLResponse * response = nil; | |
NSError * error = nil; | |
NSData * data = [NSURLConnection sendSynchronousRequest:request | |
returningResponse:&response | |
error:&error]; | |
if (error == nil) | |
{ | |
NSDictionary *jsonObject=[NSJSONSerialization | |
JSONObjectWithData:data | |
options:NSJSONReadingMutableLeaves | |
error:nil]; | |
NSLog(@"%@", jsonObject); | |
} else { | |
NSLog(@"here"); | |
NSLog(@"error - %@", error.description); | |
} | |
Error message: In produciton { | |
error = { | |
message = "Invalid ASCII characters found in API key: \"\\xB2Ib\\xBD\\xEE\\x10\\x06z\\xE4\\xB3\\x05=\\x1A\\xD3\\xC6\\xB3\\x9BE\\xB2#\\f\". For assistance, please contact [email protected]."; | |
type = "invalid_request_error"; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment