Stripe.apiKey无法在Android中解析

我在我的 Android应用程序中使用Stripe作为支付处理器,并尝试按照文档中描述的方式对卡进行充电: https://stripe.com/docs/charges

我的问题具体是它无法解析Stripe.apiKey,或无法解析符号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?

解决方法

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

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

>客户端,在您的前端代码中,您收集并标记用户的付款信息(对于Web应用程序使用CheckoutStripe.js,对于本机移动应用程序使用iOS/Android SDK)
>服务器端,在后端代码中,您在API请求中使用生成的令牌,例如到create a chargea customer object.

第一步是使用可发布的API密钥(pk _…)完成的.第二步是使用您的秘密API密钥(sk _…)完成的.

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

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...