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

Use STPAPIClient.shared by default #1469

Merged
merged 13 commits into from
Jan 22, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
15 changes: 12 additions & 3 deletions Stripe/STPAPIClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ @interface STPAPIClient()

@property (nonatomic, strong, readwrite) NSMutableDictionary<NSString *,NSObject *> *sourcePollers;
@property (nonatomic, strong, readwrite) dispatch_queue_t sourcePollersQueue;
@property (nonatomic, strong, readwrite) STPEphemeralKey *ephemeralKey;
/// If YES, the ephemeralKey will be sent as the authorization bearer for the next API request
@property (nonatomic, assign, readwrite) BOOL useEphemeralKeyForNextRequest;
@property (nonatomic, strong, readwrite) NSString *apiKey;

// See STPAPIClient+Private.h
Expand Down Expand Up @@ -163,7 +166,12 @@ - (NSMutableURLRequest *)configuredRequestForURL:(NSURL *)url {
NSMutableDictionary *additionalHeaders = [NSMutableDictionary new];
additionalHeaders[@"X-Stripe-User-Agent"] = [self.class stripeUserAgentDetailsWithAppInfo:self.appInfo];
additionalHeaders[@"Stripe-Version"] = APIVersion;
additionalHeaders[@"Authorization"] = [@"Bearer " stringByAppendingString:self.apiKey ?: @""];
NSString *authorizationBearer = self.apiKey ?: @"";
if (self.useEphemeralKeyForNextRequest && self.ephemeralKey.secret) {
self.useEphemeralKeyForNextRequest = NO;
yuki-stripe marked this conversation as resolved.
Show resolved Hide resolved
authorizationBearer = self.ephemeralKey.secret;
}
additionalHeaders[@"Authorization"] = [@"Bearer " stringByAppendingString:authorizationBearer];
additionalHeaders[@"Stripe-Account"] = self.stripeAccount;
return [additionalHeaders copy];
}
Expand Down Expand Up @@ -538,8 +546,9 @@ - (void)stopPollingSourceWithId:(NSString *)identifier {
@implementation STPAPIClient (Customers)

+ (STPAPIClient *)apiClientWithEphemeralKey:(STPEphemeralKey *)key {
STPAPIClient *client = [[self alloc] init];
client.apiKey = key.secret;
STPAPIClient *client = [STPAPIClient sharedClient];
client.ephemeralKey = key;
client.useEphemeralKeyForNextRequest = YES;
return client;
}

Expand Down
1 change: 0 additions & 1 deletion Stripe/STPCustomerContext.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

@interface STPCustomerContext ()

@property (nonatomic) STPAPIClient *apiClient;
@property (nonatomic) STPCustomer *customer;
@property (nonatomic) NSDate *customerRetrievedDate;
@property (nonatomic, copy) NSArray<STPPaymentMethod *> *paymentMethods;
Expand Down