【问题标题】:Stripe.apiKey not resolving in AndroidStripe.apiKey 在 Android 中无法解析
【发布时间】:2017-06-15 04:14:03
【问题描述】:

我在我的 Android 应用中使用 Stripe 作为支付处理器,并尝试按照文档中的描述从卡中扣款:https://stripe.com/docs/charges

我的问题具体是它无法解决Stripe.apiKeycan 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

【问题讨论】:

  • 确保你使用了com.stripe.Stripe而不是其他一些包

标签: android stripe-payments


【解决方案1】:

要解决Stripe.apikey cannot resolve,请将Stripe.apiKey 更改为

com.stripe.Stripe.apiKey = "Your secret";

【讨论】:

    【解决方案2】:

    您提供的代码是服务器端使用令牌的creating a charge 的Java 代码。它不适用于 Android 应用程序。

    使用 Stripe 的支付流程分为两个步骤:

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

    • 服务器端,在您的后端代码中,您在 API 请求中使用生成的令牌,例如到create a chargea customer object

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

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

    【讨论】:

      【解决方案3】:

      试试:Stripe stripe = new Stripe("pk_test_6pRNASCoBOKtIshFeQd4XMUh");

      欲了解更多信息,请查看:https://stripe.com/docs/mobile/android#credit-card-form

      【讨论】:

      • 应该是 Stripe stripe = new Stripe(context, "pk_test_6pRNASCoBOKtIshFeQd4XMUh");
      猜你喜欢
      • 2017-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-15
      • 2019-03-29
      相关资源
      最近更新 更多