我在我的
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应用程序使用Checkout或Stripe.js,对于本机移动应用程序使用iOS/Android SDK)
>服务器端,在后端代码中,您在API请求中使用生成的令牌,例如到create a charge或a customer object.
第一步是使用可发布的API密钥(pk _…)完成的.第二步是使用您的秘密API密钥(sk _…)完成的.
您绝不能与您的前端代码共享秘密API密钥,否则攻击者可以检索它并使用它代表您发出API请求.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。