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

Create StripeRepository interface #1387

Merged
merged 2 commits into from
Aug 15, 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
22 changes: 11 additions & 11 deletions stripe/src/main/java/com/stripe/android/CustomerSession.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public class CustomerSession {
@NonNull private final Set<String> mProductUsageTokens;
@Nullable private final Calendar mProxyNowCalendar;
@NonNull private final ThreadPoolExecutor mThreadPoolExecutor;
@NonNull private final StripeApiHandler mApiHandler;
@NonNull private final StripeRepository mStripeRepository;
@NonNull private final String mPublishableKey;
@Nullable private final String mStripeAccountId;

Expand Down Expand Up @@ -240,7 +240,7 @@ private CustomerSession(@NonNull Context context, @NonNull EphemeralKeyProvider
@NonNull EphemeralKeyProvider keyProvider,
@Nullable Calendar proxyNowCalendar,
@NonNull ThreadPoolExecutor threadPoolExecutor,
@NonNull StripeApiHandler apiHandler,
@NonNull StripeRepository stripeRepository,
@NonNull String publishableKey,
@Nullable String stripeAccountId,
boolean shouldPrefetchEphemeralKey) {
Expand All @@ -249,7 +249,7 @@ private CustomerSession(@NonNull Context context, @NonNull EphemeralKeyProvider
mThreadPoolExecutor = threadPoolExecutor;
mProxyNowCalendar = proxyNowCalendar;
mProductUsageTokens = new HashSet<>();
mApiHandler = apiHandler;
mStripeRepository = stripeRepository;
mStripeAccountId = stripeAccountId;
mPublishableKey = publishableKey;
mUiThreadHandler = new CustomerSessionHandler(new CustomerSessionHandler.Listener() {
Expand Down Expand Up @@ -774,7 +774,7 @@ private Source addCustomerSourceWithKey(
@NonNull CustomerEphemeralKey key,
@NonNull String sourceId,
@NonNull @Source.SourceType String sourceType) throws StripeException {
return mApiHandler.addCustomerSource(
return mStripeRepository.addCustomerSource(
key.getCustomerId(),
mPublishableKey,
new ArrayList<>(mProductUsageTokens),
Expand All @@ -788,7 +788,7 @@ private Source addCustomerSourceWithKey(
private Source deleteCustomerSourceWithKey(
@NonNull CustomerEphemeralKey key,
@NonNull String sourceId) throws StripeException {
return mApiHandler.deleteCustomerSource(
return mStripeRepository.deleteCustomerSource(
key.getCustomerId(),
mPublishableKey,
new ArrayList<>(mProductUsageTokens),
Expand All @@ -801,7 +801,7 @@ private Source deleteCustomerSourceWithKey(
private PaymentMethod attachCustomerPaymentMethodWithKey(
@NonNull CustomerEphemeralKey key,
@NonNull String paymentMethodId) throws StripeException {
return mApiHandler.attachPaymentMethod(
return mStripeRepository.attachPaymentMethod(
key.getCustomerId(),
mPublishableKey,
new ArrayList<>(mProductUsageTokens),
Expand All @@ -814,7 +814,7 @@ private PaymentMethod attachCustomerPaymentMethodWithKey(
private PaymentMethod detachCustomerPaymentMethodWithKey(
@NonNull CustomerEphemeralKey key,
@NonNull String paymentMethodId) throws StripeException {
return mApiHandler.detachPaymentMethod(
return mStripeRepository.detachPaymentMethod(
mPublishableKey,
new ArrayList<>(mProductUsageTokens),
paymentMethodId,
Expand All @@ -826,7 +826,7 @@ private PaymentMethod detachCustomerPaymentMethodWithKey(
private List<PaymentMethod> getCustomerPaymentMethodsWithKey(
@NonNull CustomerEphemeralKey key,
@NonNull String paymentMethodType) throws StripeException {
return mApiHandler.getPaymentMethods(
return mStripeRepository.getPaymentMethods(
key.getCustomerId(),
paymentMethodType,
mPublishableKey,
Expand All @@ -839,7 +839,7 @@ private List<PaymentMethod> getCustomerPaymentMethodsWithKey(
private Customer setCustomerShippingInfoWithKey(
@NonNull CustomerEphemeralKey key,
@NonNull ShippingInformation shippingInformation) throws StripeException {
return mApiHandler.setCustomerShippingInfo(
return mStripeRepository.setCustomerShippingInfo(
key.getCustomerId(),
mPublishableKey,
new ArrayList<>(mProductUsageTokens),
Expand All @@ -853,7 +853,7 @@ private Customer setCustomerSourceDefaultWithKey(
@NonNull CustomerEphemeralKey key,
@NonNull String sourceId,
@NonNull @Source.SourceType String sourceType) throws StripeException {
return mApiHandler.setDefaultCustomerSource(
return mStripeRepository.setDefaultCustomerSource(
key.getCustomerId(),
mPublishableKey,
new ArrayList<>(mProductUsageTokens),
Expand All @@ -875,7 +875,7 @@ private Customer setCustomerSourceDefaultWithKey(
@Nullable
private Customer retrieveCustomerWithKey(@NonNull CustomerEphemeralKey key)
throws StripeException {
return mApiHandler.retrieveCustomer(key.getCustomerId(),
return mStripeRepository.retrieveCustomer(key.getCustomerId(),
ApiRequest.Options.create(key.getSecret(), mStripeAccountId));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class IssuingCardPinService
@NonNull
private final EphemeralKeyManager<IssuingCardEphemeralKey> mEphemeralKeyManager;
@NonNull
private final StripeApiHandler mApiHandler;
private final StripeRepository mStripeRepository;
@NonNull
private final OperationIdFactory mOperationIdFactory;
@NonNull
Expand Down Expand Up @@ -70,10 +70,10 @@ private IssuingCardPinService(
@VisibleForTesting
IssuingCardPinService(
@NonNull EphemeralKeyProvider keyProvider,
@NonNull StripeApiHandler apiHandler,
@NonNull StripeRepository stripeRepository,
@NonNull OperationIdFactory operationIdFactory) {
mOperationIdFactory = operationIdFactory;
mApiHandler = apiHandler;
mStripeRepository = stripeRepository;
mEphemeralKeyManager = new EphemeralKeyManager<>(
keyProvider,
this,
Expand Down Expand Up @@ -166,7 +166,7 @@ public void onKeyUpdate(@NonNull IssuingCardEphemeralKey ephemeralKey,
final String userOneTimeCode =
(String) Objects.requireNonNull(arguments.get(ARGUMENT_ONE_TIME_CODE));
try {
final String pin = mApiHandler.retrieveIssuingCardPin(cardId, verificationId,
final String pin = mStripeRepository.retrieveIssuingCardPin(cardId, verificationId,
userOneTimeCode, ephemeralKey.getSecret());
listener.onIssuingCardPinRetrieved(pin);

Expand Down Expand Up @@ -237,8 +237,8 @@ public void onKeyUpdate(@NonNull IssuingCardEphemeralKey ephemeralKey,
final String userOneTimeCode =
(String) Objects.requireNonNull(arguments.get(ARGUMENT_ONE_TIME_CODE));
try {
mApiHandler.updateIssuingCardPin(cardId, newPin, verificationId, userOneTimeCode,
ephemeralKey.getSecret());
mStripeRepository.updateIssuingCardPin(cardId, newPin, verificationId,
userOneTimeCode, ephemeralKey.getSecret());
listener.onIssuingCardPinUpdated();
} catch (InvalidRequestException e) {
if ("expired".equals(e.getErrorCode())) {
Expand Down
Loading