欢欲药 v1.1.4版本的 MD5 值为:7d0994a905ec6c6aceeef0cd822647fc
以下内容为反编译后的 Stripe.java 源代码,内容仅作参考
package com.stripe.android;
import android.os.AsyncTask;
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 publishableKey, Executor executor, final TokenCallback callback) {
AsyncTask<Void, Void, ResponseWrapper> task = 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(publishableKey).build()), exc);
} catch (StripeException e) {
return new ResponseWrapper(objArr2 == true ? 1 : 0, e);
}
}
@Override
public void onPostExecute(ResponseWrapper result) {
Stripe.this.tokenTaskPostExecution(result, callback);
}
};
Stripe.this.executeTokenTask(executor, task);
}
};
public interface TokenCreator {
void create(Card card, String str, Executor executor, TokenCallback tokenCallback);
}
public Stripe() {
}
public Stripe(String publishableKey) throws AuthenticationException {
setDefaultPublishableKey(publishableKey);
}
public void createToken(Card card, TokenCallback callback) {
createToken(card, this.defaultPublishableKey, callback);
}
public void createToken(Card card, String publishableKey, TokenCallback callback) {
createToken(card, publishableKey, null, callback);
}
public void createToken(Card card, Executor executor, TokenCallback callback) {
createToken(card, this.defaultPublishableKey, executor, callback);
}
public void createToken(Card card, String publishableKey, Executor executor, TokenCallback callback) {
try {
if (card == null) {
throw new RuntimeException("Required Parameter: 'card' is required to create a token");
}
if (callback == null) {
throw new RuntimeException("Required Parameter: 'callback' is required to use the created token and handle errors");
}
validateKey(publishableKey);
this.tokenCreator.create(card, publishableKey, executor, callback);
} catch (AuthenticationException e) {
callback.onError(e);
}
}
public Token createTokenSynchronous(Card card) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
return createTokenSynchronous(card, this.defaultPublishableKey);
}
public Token createTokenSynchronous(Card card, String publishableKey) throws AuthenticationException, InvalidRequestException, APIConnectionException, CardException, APIException {
validateKey(publishableKey);
RequestOptions requestOptions = RequestOptions.builder(publishableKey).build();
return StripeApiHandler.createToken(StripeNetworkUtils.hashMapFromCard(card), requestOptions);
}
public void setDefaultPublishableKey(String publishableKey) throws AuthenticationException {
validateKey(publishableKey);
this.defaultPublishableKey = publishableKey;
}
private void validateKey(String publishableKey) throws AuthenticationException {
if (publishableKey == null || publishableKey.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 (publishableKey.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 result, TokenCallback callback) {
if (result.token != null) {
callback.onSuccess(result.token);
} else if (result.error != null) {
callback.onError(result.error);
} else {
callback.onError(new RuntimeException("Somehow got neither a token response or an error response"));
}
}
public void executeTokenTask(Executor executor, AsyncTask<Void, Void, ResponseWrapper> task) {
if (executor != null) {
task.executeOnExecutor(executor, new Void[0]);
} else {
task.execute(new Void[0]);
}
}
public class ResponseWrapper {
final Exception error;
final Token token;
private ResponseWrapper(Token token, Exception error) {
this.error = error;
this.token = token;
}
}
}