【问题标题】:Android: Create a new customer record with Stripe APIAndroid:使用 Stripe API 创建新的客户记录
【发布时间】: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


    【解决方案1】:

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

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

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

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

    【讨论】:

    • 我明白了。谢谢你说清楚。我只是想知道是否有一个Android选项。好吧,我需要求助于 Node.js -_-
    猜你喜欢
    • 2014-03-30
    • 2016-04-17
    • 2022-10-19
    • 1970-01-01
    • 2023-01-18
    • 2015-12-26
    • 2014-11-12
    • 2014-03-08
    • 2014-03-28
    相关资源
    最近更新 更多