0

I'm trying to convert the following cURL request to AFNetworking but am unsure how to go about doing it.

curl https://api.stripe.com/v1/tokens \
   -u XXXXXXXXXXXXXXXXXXXXX: \
   -d bank_account[country]=CA \
   -d bank_account[currency]=cad \
   -d bank_account[name]="Jane Austen" \
   -d bank_account[account_holder_type]=individual \
   -d bank_account[routing_number]=110000000 \
   -d bank_account[account_number]=000123456789

Here's my AFNetworking code.

 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
NSDictionary *params = @{@"bank_account[country]": @"CA",
                         @"ubank_account[currency]": @"cad",
                         @"bank_account[name]":@"Jane Austen",
                         @"bank_account[account_holder_type]": @"individual",
                         @"bank_account[routing_number]":@"110000000",
                         @"bank_account[account_number]": @"000123456789"
                         };
[manager POST:@"https://api.stripe.com/v1/tokens" parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
    NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

I'm unsure what to do with the -u flag.

Viper
  • 1,327
  • 2
  • 12
  • 33

1 Answers1

1

The curl -u flag simply means that basic auth should be used. The API key is the username, and the password is empty.

I'm not familiar with AFNetworking but I think this StackOverflow answer should have the information you need to implement basic auth.

Alternatively, instead of using basic auth, you can also add a special header to your request:

Authorization: Bearer sk_...

This other StackOverflow answer explains how to add additional headers to a request.

Community
  • 1
  • 1
Ywain
  • 16,854
  • 4
  • 51
  • 67