Java 从Android中删除用户卡

Java 从Android中删除用户卡,java,android,stripe-payments,Java,Android,Stripe Payments,我正在尝试使用以下代码从条带中删除卡: 第一次尝试: com.stripe.Stripe.apiKey = getString(R.string.stripe_test_secret_key); com.stripe.model.Token token = com.stripe.model.Token.retrieve(CardId); String cardId = token.getCard().getId(); customer = Customer.retrieve(payments.a

我正在尝试使用以下代码从条带中删除卡:

第一次尝试:

com.stripe.Stripe.apiKey = getString(R.string.stripe_test_secret_key);
com.stripe.model.Token token = com.stripe.model.Token.retrieve(CardId);
String cardId = token.getCard().getId();
customer = Customer.retrieve(payments.appPreference.getStripeCustomerId());
DeletedExternalAccount delete = customer.getSources().retrieve(cardId).delete();
com.stripe.Stripe.apiKey = getString(R.string.stripe_test_secret_key);    
com.stripe.model.Token token = com.stripe.model.Token.retrieve(CardId);
DeletedCard delete = token.getCard().delete();
错误: 我得到com.stripe.exception.InvalidRequestException:没有这样的来源:card_uxxxxxxxxxxxxxxxxxxxxxxxx;请求id:req_uXXXXXXXXXX

第二次尝试:

com.stripe.Stripe.apiKey = getString(R.string.stripe_test_secret_key);
com.stripe.model.Token token = com.stripe.model.Token.retrieve(CardId);
String cardId = token.getCard().getId();
customer = Customer.retrieve(payments.appPreference.getStripeCustomerId());
DeletedExternalAccount delete = customer.getSources().retrieve(cardId).delete();
com.stripe.Stripe.apiKey = getString(R.string.stripe_test_secret_key);    
com.stripe.model.Token token = com.stripe.model.Token.retrieve(CardId);
DeletedCard delete = token.getCard().delete();
错误: com.stripe.exception.APIConnectionException:IOException在API请求stripe()时发生:null请检查您的internet连接,然后重试。如果此问题仍然存在,您应该在处检查条带的服务状态,或在处通知我们support@stripe.com.

原因:java.net.MalformedURLException


有人能帮我解决这个问题吗?

在您的Android应用程序中无法执行任何操作,因为这些调用需要您的API密钥。你永远不应该在你的Android应用程序中拥有这个秘密API密钥,否则攻击者可能会得到它,然后代表你进行收费、退款或转账

这里需要做的是在服务器端处理此代码。您将调用删除卡[API][1],并确保在代码中传递正确的客户和卡id。在Java中,但在服务器端,您可以执行以下操作:

Customer customer = Customer.retrieve("cus_XXXXXXX");
customer.getSources().retrieve("card_YYYYYY").delete();

@库帕亚是对的。从移动端看不安全

这是因为我创建了令牌,但并没有调用api来创建卡。
令牌具有卡对象,但未分配给任何客户端。所以,我遇到了这个错误。

我知道从手机端看是不安全的。但我想知道为什么它不起作用。我正在尝试使用currect客户id和卡id(来自令牌),但出现错误。@SANAT:如果来自令牌,卡将无法工作。您需要存储在客户上的卡id,您可以通过API或仪表板进行查找。