正在查看: Plus 12 v10.13.1.1 应用的 Stripe.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Plus 12 v10.13.1.1 应用的 Stripe.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.stripe.android;
import android.os.AsyncTask;
import android.os.Build;
import com.stripe.android.exception.AuthenticationException;
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 {
public String defaultPublishableKey;
public 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(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, 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 void setDefaultPublishableKey(String str) throws AuthenticationException {
validateKey(str);
this.defaultPublishableKey = str;
}
public final 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 final void tokenTaskPostExecution(ResponseWrapper responseWrapper, TokenCallback tokenCallback) {
Token token = responseWrapper.token;
if (token != null) {
tokenCallback.onSuccess(token);
return;
}
Exception exc = responseWrapper.error;
if (exc != null) {
tokenCallback.onError(exc);
} else {
tokenCallback.onError(new RuntimeException("Somehow got neither a token response or an error response"));
}
}
public final 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 {
public final Exception error;
public final Token token;
public ResponseWrapper(Stripe stripe, Token token, Exception exc) {
this.error = exc;
this.token = token;
}
}
}