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 stripeAccount to STPPaymentConfiguration #875

Merged
merged 1 commit into from
Jan 8, 2018
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
9 changes: 9 additions & 0 deletions Stripe/PublicHeaders/STPPaymentConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ NS_ASSUME_NONNULL_BEGIN
*/
@property (nonatomic, assign, readwrite) BOOL canDeletePaymentMethods;

/**
In order to perform API requests on behalf of a connected account, e.g. to
create a source on a connected account, set this property to the ID of the
account for which this request is being made.

@see https://stripe.com/docs/connect/authentication#authentication-via-the-stripe-account-header
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That docs page says this authentication option works with the platform secret key (I'm nearly positive you can also use the platform publishable key too: DOCS-529).

Does the publishable key work? Should we update the docs?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the publishable key does work—this is what Stripe.js does when you set the stripeAccount property: https://stripe.com/docs/stripe-js/reference#stripe-function

This is somewhat covered, since tokenization can & should be done with a publishable key. It's also discussed in the sources documentation: https://stripe.com/docs/sources/connect#creating-direct-charges

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks @fred-stripe ! :)

*/
@property (nonatomic, copy, nullable) NSString *stripeAccount;

@end

NS_ASSUME_NONNULL_END
3 changes: 2 additions & 1 deletion Stripe/STPAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,11 @@ - (instancetype)initWithConfiguration:(STPPaymentConfiguration *)configuration {
if (self) {
_apiKey = publishableKey;
_apiURL = [NSURL URLWithString:APIBaseURL];
_urlSession = [NSURLSession sessionWithConfiguration:[self sessionConfiguration]];
_configuration = configuration;
_stripeAccount = configuration.stripeAccount;
_sourcePollers = [NSMutableDictionary dictionary];
_sourcePollersQueue = dispatch_queue_create("com.stripe.sourcepollers", DISPATCH_QUEUE_SERIAL);
_urlSession = [NSURLSession sessionWithConfiguration:[self sessionConfiguration]];
}
return self;
}
Expand Down
12 changes: 12 additions & 0 deletions Tests/Tests/STPAPIClientTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
@import XCTest;

#import "STPAPIClient+Private.h"
#import "STPFixtures.h"

@interface STPAPIClient (Testing)

Expand Down Expand Up @@ -55,4 +56,15 @@ - (void)testSetStripeAccount {
XCTAssertEqualObjects(accountHeader, @"acct_123");
}

- (void)testInitWithConfiguration {
STPPaymentConfiguration *config = [STPFixtures paymentConfiguration];
config.stripeAccount = @"acct_123";

STPAPIClient *sut = [[STPAPIClient alloc] initWithConfiguration:config];
XCTAssertEqualObjects(sut.publishableKey, config.publishableKey);
XCTAssertEqualObjects(sut.stripeAccount, config.stripeAccount);
NSString *accountHeader = sut.urlSession.configuration.HTTPAdditionalHeaders[@"Stripe-Account"];
XCTAssertEqualObjects(accountHeader, @"acct_123");
}

@end