java - Android:使用 Stripe API 创建新的客户记录

标签 java android stripe-payments

我有一位新客户正在结帐,并希望存储他们的卡以供将来使用。如果我正在阅读 documentation正确的是,我需要单独调用 Stripe,一个调用使用该卡创建客户,另一个调用对该卡进行收费。

问题是..有没有一种方法可以仅使用 Android/Java 代码在 Stripe 中创建新的客户记录,而不使用任何后端服务器大小的代码(如 PHP、Node.JS 等)?

因为我在使用here所述的文档时遇到问题对于Java。我尝试遵循文档,但遗憾的是,这些代码在我的 Android 项目中不起作用(即使我将其添加到 build.gradle 等)

我是 Stripe 新手,所以我不太了解。

这是我试图遵循并应用于我的项目的代码。

// 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_ejKNr41rD0SbiNVxkZOcneG0";

// Token is created using Stripe.js or Checkout!
// Get the payment token submitted by the form:
String token = request.getParameter("stripeToken");

// Create a Customer:
Map<String, Object> customerParams = new HashMap<String, Object>();
customerParams.put("email", "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b6c6d7cfdfd8d198c3c5d3c4f6d3ced7dbc6dad398d5d9db" rel="noreferrer noopener nofollow">[email protected]</a>");
customerParams.put("source", token);
Customer customer = Customer.create(customerParams);

// Charge the Customer instead of the card:
Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", 1000);
chargeParams.put("currency", "eur");
chargeParams.put("customer", customer.getId());
Charge charge = Charge.create(chargeParams);

// YOUR CODE: Save the customer ID and other info in a database for later.

// YOUR CODE (LATER): When it's time to charge the customer again, retrieve the customer ID.
Map<String, Object> chargeParams = new HashMap<String, Object>();
chargeParams.put("amount", 1500); // $15.00 this time
chargeParams.put("currency", "eur");
chargeParams.put("customer", customerId);
Charge charge = Charge.create(chargeParams);

最佳答案

is there a way to create a new Customer record into Stripe by just using Android/Java codes without utilizing any back-end server size codes like PHP, Node.JS, etc?

没有。 Stripe 的Android SDK只能用于收集和标记客户付款信息。此操作是使用您的可发布 API key 完成的。

所有其他操作(例如使用 create a customer objecta charge 的 token )都是使用您的 key 完成的,该 key 绝不能共享或嵌入到您的移动应用程序中,因为攻击者可以检索它并使用它来发布代表您发出 API 请求。

Stripe 确实提供了 Java library ,但它适用于服务器端使用,而不是从 Android 移动应用程序使用。

关于java - Android:使用 Stripe API 创建新的客户记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45320669/

相关文章:

java - 当我需要使用两列时如何使用@oneToMany

java - Hibernate(映射到交叉引用表)

java - 带有淡入淡出 ImageView 动画的启动画面

android - 当应用程序被杀死时,应用程序小部件点击不起作用

javascript - 使用 NodeJS 将卡添加到 Stripe 客户

java - DAO 中的结果集问题

java - 生成 0000 到 9999 之间的随机数

android - LOCAL_LDLIBS 与 LOCAL_LDFLAGS

angular - Stripe oAuth token URL 被 CORS 阻止

javascript - 我第一次在 javascript 中看到这种语法