删除用户卡从条纹安卓

时间:2022-09-06 16:27:57

I am trying to delete card from stripe using this code :

我正在尝试用这段代码从stripe删除card:

First Try :

第一次尝试:

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();

Error : I am getting com.stripe.exception.InvalidRequestException: No such source: card_xxxxxxxxxxxxxxxxxxxxxx; request-id: req_xxxxxxxxxxxx

错误:我将得到com.stripe.exception。InvalidRequestException:无此类来源:card_xxxxxxxxxxxxxxxxxx;请求id:req_xxxxxxxxxxxx

Second Try :

第二次尝试:

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();

Error : com.stripe.exception.APIConnectionException: IOException during API request to Stripe (https://api.stripe.com): null Please check your internet connection and try again. If this problem persists,you should check Stripe's service status at https://twitter.com/stripestatus, or let us know at support@stripe.com.

错误:com.stripe.exception。APIConnectionException: IOException在API请求Stripe时(https://api.stripe.com): null,请检查您的internet连接并重试。如果这个问题持续存在,您应该在https://twitter.com/stripestatus检查Stripe的服务状态,或者在support@stripe.com让我们知道。

Caused by: java.net.MalformedURLException

引起的:java.net.MalformedURLException

Can anyone help me to resolve this?

谁能帮我解决这个问题吗?

2 个解决方案

#1


1  

It's not possible to do any of this in your Android application as those calls require your Secret API key. You should never have the Secret API key in your Android application otherwise an attacker could get his hands on it and then create charges, refunds or transfers on your behalf.

在Android应用程序中不可能实现这些操作,因为这些调用需要您的秘密API密钥。你不应该在你的Android应用程序中使用秘密的API密钥,否则攻击者可能会得到它,然后为你创造费用、退款或转账。

What you need to do here is handle this code server-side. You'll call the Delete Card [API][1] and make sure that you pass the correct customer and card id in your code. In Java, but server-side, you would do:

这里需要做的是处理服务器端代码。您将调用Delete Card [API][1]并确保在代码中传递正确的客户和卡id。在Java中,但是在服务器端,您需要:

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

#2


0  

@koopajah is right. Its not secure from mobile side.

@koopajah是正确的。移动端不安全。

It happened because i created Token but did not call api for creating card. Token had Card object but it was not assigned to any client. So, I was getting this error.

这是因为我创建了Token,但是没有调用api来创建card。Token有Card对象,但它没有分配给任何客户端。我得到了这个误差。

#1


1  

It's not possible to do any of this in your Android application as those calls require your Secret API key. You should never have the Secret API key in your Android application otherwise an attacker could get his hands on it and then create charges, refunds or transfers on your behalf.

在Android应用程序中不可能实现这些操作,因为这些调用需要您的秘密API密钥。你不应该在你的Android应用程序中使用秘密的API密钥,否则攻击者可能会得到它,然后为你创造费用、退款或转账。

What you need to do here is handle this code server-side. You'll call the Delete Card [API][1] and make sure that you pass the correct customer and card id in your code. In Java, but server-side, you would do:

这里需要做的是处理服务器端代码。您将调用Delete Card [API][1]并确保在代码中传递正确的客户和卡id。在Java中,但是在服务器端,您需要:

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

#2


0  

@koopajah is right. Its not secure from mobile side.

@koopajah是正确的。移动端不安全。

It happened because i created Token but did not call api for creating card. Token had Card object but it was not assigned to any client. So, I was getting this error.

这是因为我创建了Token,但是没有调用api来创建card。Token有Card对象,但它没有分配给任何客户端。我得到了这个误差。