我在我的Android应用中使用Stripe作为支付处理器并尝试按照文档中所述对卡进行充值:https://stripe.com/docs/charges
我的问题是,它无法解决Stripe.apiKey
或can not resolve symbol apiKey
我正在从文档中实现的代码:
// Set your secret key: remember to change this to your live secret key in production
// See your keys here: https://dashboard.stripe.com/account/apikeys
Stripe.apiKey = "sk_test_********************";//this is where i hit a wall
// Token is created using Stripe.js or Checkout!
// Get the payment token submitted by the form:
String token = request.getParameter("stripeToken");
// Charge the user's card:
Map<String, Object> params = new HashMap<String, Object>();
params.put("amount", 1000);
params.put("currency", "usd");
params.put("description", "Example charge");
params.put("source", token);
Charge charge = Charge.create(params);
我还在文件顶部导入了import com.stripe.android.*;
。
在我的Gradle文件中,我导入了Stripe库:
compile 'com.stripe:stripe-android:2.0.2'
为什么Android无法解析Stripe.apiKey
?
答案 0 :(得分:7)
您提供的代码是使用令牌的creating a charge的服务器端 Java代码。它并不适用于Android应用程序。
使用Stripe的付款流程分为两个步骤:
客户端,在您的前端代码中,您收集并标记用户的付款信息(使用Checkout或Stripe.js作为网络应用程序,或iOS / { {3}}本地移动应用程序的SDK)
服务器端,在您的后端代码中,您在API请求中使用生成的令牌,例如到Android或create a charge。
第一步是使用可发布的API密钥(pk_...
)完成的。第二步是使用您的秘密API密钥(sk_...
)完成的。
您绝不能与您的前端代码共享秘密API密钥,否则攻击者可以检索它并使用它代表您发出API请求。
答案 1 :(得分:1)
要解决Stripe.apikey cannot resolve
,请将Stripe.apiKey
更改为
com.stripe.Stripe.apiKey = "Your secret";
答案 2 :(得分:0)
尝试:Stripe stripe = new Stripe("pk_test_6pRNASCoBOKtIshFeQd4XMUh");
有关详细信息,请查看:https://stripe.com/docs/mobile/android#credit-card-form