Stripe.apiKey无法在Android中解析

bec*_*kah 3 android stripe-payments

我在我的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);
Run Code Online (Sandbox Code Playgroud)

我也在import com.stripe.android.*;我的文件顶部导入.

在我的Gradle文件中,我导入了Stripe库:

compile 'com.stripe:stripe-android:2.0.2'
Run Code Online (Sandbox Code Playgroud)

为什么Android无法解决Stripe.apiKey

Ywa*_*ain 7

您提供的代码是服务器端 Java代码,用于使用令牌创建费用.它并不适用于Android应用程序.

Stripe的付款流程分为两个步骤:

  • 客户端,在您的前端代码中,您收集并标记用户的付款信息(使用CheckoutStripe.js作为Web应用程序,或iOS/Android SDK作为本机移动应用程序)

  • 在服务器端,在后端代码中,您在API请求中使用生成的令牌,例如创建费用客户对象.

第一步是使用可发布的API密钥(pk_...)完成的.第二步是使用您的秘密API密钥(sk_...)完成的.

您绝不能与您的前端代码共享秘密API密钥,否则攻击者可以检索它并使用它代表您发出API请求.