【发布时间】:2018-01-01 09:43:40
【问题描述】:
我有一位新客户正在结账并想保存他们的卡以备将来使用。如果我正确阅读了documentation,我需要单独调用 Stripe,一个是用卡创建客户,另一个是从卡上收费。
问题是.. 有没有一种方法可以通过仅使用 Android/Java 代码而不使用任何后端服务器大小代码(如 PHP、Node.JS 等)来在 Stripe 中创建新的客户记录?
因为我在使用here for 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);
【问题讨论】:
标签: java android stripe-payments