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



我有一位新客户正在结账,并希望存储他们的卡以备将来使用。如果我正确阅读了文档,我需要单独调用 Stripe,一个用于创建带有卡的客户,另一个用于向卡收费。

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

因为我在使用此处所述的 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", "paying.user@example.com");
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);

有没有办法通过使用Android/Java代码而不使用任何后端服务器大小代码(如PHP,Node.JS等(在Stripe中创建新的客户记录?

不。Stripe 的 Android SDK 只能用于收集和标记客户支付信息。此操作是使用可发布的 API 密钥完成的。

所有其他操作(例如,使用令牌创建客户对象或费用(都是使用您的密钥完成的,该密钥不得共享或嵌入到您的移动应用程序中,因为攻击者随后可以检索它并使用它来代表您发出 API 请求。

Stripe 确实提供了一个 Java 库,但它是供服务器端使用的,不能在 Android 移动应用程序中使用。

最新更新