盛康基办 v2.7.0版本的 MD5 值为:4c3c440b077245f6a1d9c80bb73439c1
以下内容为反编译后的 Stripe.java 源代码,内容仅作参考
package com.stripe.android;
import android.os.AsyncTask;
import android.os.Build;
import com.stripe.android.exception.APIConnectionException;
import com.stripe.android.exception.APIException;
import com.stripe.android.exception.AuthenticationException;
import com.stripe.android.exception.CardException;
import com.stripe.android.exception.InvalidRequestException;
import com.stripe.android.exception.StripeException;
import com.stripe.android.model.Card;
import com.stripe.android.model.Token;
import com.stripe.android.net.RequestOptions;
import com.stripe.android.net.StripeApiHandler;
import com.stripe.android.util.StripeNetworkUtils;
import java.util.concurrent.Executor;
public class Stripe {
private String defaultPublishableKey;
TokenCreator tokenCreator = new TokenCreator() {
@Override
public void create(final Card card, final String str, Executor executor, final TokenCallback tokenCallback) {
Stripe.this.executeTokenTask(executor, new AsyncTask<Void, Void, ResponseWrapper>() {
@Override
public ResponseWrapper doInBackground(Void... voidArr) {
Exception exc = null;
Object[] objArr = 0;
Object[] objArr2 = 0;
Object[] objArr3 = 0;
try {
return new ResponseWrapper(StripeApiHandler.createToken(StripeNetworkUtils.hashMapFromCard(card), RequestOptions.builder(str).build()), exc);
} catch (StripeException e) {
return new ResponseWrapper(objArr2 == true ? 1 : 0, e);
}
}
@Override
public void onPostExecute(ResponseWrapper responseWrapper) {
Stripe.this.tokenTaskPostExecution(responseWrapper, tokenCallback);
}
});
}
};
public interface TokenCreator {
void create(Card card, String str, Executor executor, TokenCallback tokenCallback);
}
public Stripe() {
}
public Stripe(String str) throws AuthenticationException {
setDefaultPublishableKey(str);
}
public void createToken(Card card, TokenCallback tokenCallback) {
createToken(card, this.defaultPublishableKey, tokenCallback);
}
public void createToken(Card card, String str, TokenCallback tokenCallback) {
createToken(card, str, null, tokenCallback);
}
public void createToken(Card card, Executor executor, TokenCallback tokenCallback) {
createToken(card, this.defaultPublishableKey, executor, tokenCallback);
}
public void createToken(Card card, String str, Executor executor, TokenCallback tokenCallback) {
try {
if (card == null) {
throw new RuntimeException("Required Parameter: 'card' is required to create a token");
}
if (tokenCallback == null) {
throw new RuntimeException("Required Parameter: 'callback' is required to use the created token and handle errors");
}
validateKey(str);
this.tokenCreator.create(card, str, executor, tokenCallback);
} catch (AuthenticationException e) {
tokenCallback.onError(e);
}
}
public Token createTokenSynchronous(Card card) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
return createTokenSynchronous(card, this.defaultPublishableKey);
}
public Token createTokenSynchronous(Card card, String str) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
validateKey(str);
return StripeApiHandler.createToken(StripeNetworkUtils.hashMapFromCard(card), RequestOptions.builder(str).build());
}
public void setDefaultPublishableKey(String str) throws AuthenticationException {
validateKey(str);
this.defaultPublishableKey = str;
}
private void validateKey(String str) throws AuthenticationException {
if (str == null || str.length() == 0) {
throw new AuthenticationException("Invalid Publishable Key: You must use a valid publishable key to create a token. For more info, see https://stripe.com/docs/stripe.js.", null, 0);
}
if (str.startsWith("sk_")) {
throw new AuthenticationException("Invalid Publishable Key: You are using a secret key to create a token, instead of the publishable one. For more info, see https://stripe.com/docs/stripe.js", null, 0);
}
}
public void tokenTaskPostExecution(ResponseWrapper responseWrapper, TokenCallback tokenCallback) {
if (responseWrapper.token != null) {
tokenCallback.onSuccess(responseWrapper.token);
} else if (responseWrapper.error != null) {
tokenCallback.onError(responseWrapper.error);
} else {
tokenCallback.onError(new RuntimeException("Somehow got neither a token response or an error response"));
}
}
public void executeTokenTask(Executor executor, AsyncTask<Void, Void, ResponseWrapper> asyncTask) {
if (executor != null && Build.VERSION.SDK_INT > 11) {
asyncTask.executeOnExecutor(executor, new Void[0]);
} else {
asyncTask.execute(new Void[0]);
}
}
public class ResponseWrapper {
final Exception error;
final Token token;
private ResponseWrapper(Token token, Exception exc) {
this.error = exc;
this.token = token;
}
}
}