java - 没有这样的收件人错误 Stripe

原文 标签 java stripe-payments

尝试通过 Stripe 将测试付款转帐到测试银行帐户时出现此错误

我的前端代码:

<html>
<head>
<script type="text/javascript" ></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="http://code.jquery.com/ui/1.9.2/jquery-ui.js"></script>
<script type="text/javascript" src="https://js.stripe.com/v2/"></script>
<script type="text/javascript">
  Stripe.setPublishableKey('//key//');
</script>
</head>
<body>
    <form action="Payout" method="POST" id="payment-form">
  <span class="payment-errors"></span>

  <div class="form-row">
    <label>
      <span>Card Number</span>
      <input type="text" size="20" data-stripe="number">
    </label>
  </div>

  <div class="form-row">
    <label>
      <span>Expiration (MM/YY)</span>
      <input type="text" size="2" data-stripe="exp_month">
    </label>
    <span> / </span>
    <input type="text" size="2" data-stripe="exp_year">
  </div>

  <div class="form-row">
    <label>
      <span>CVC</span>
      <input type="text" size="4" data-stripe="cvc">
    </label>
  </div>

  <input type="submit" class="submit" value="Submit Payment">
</form>

<script>
    $(function() {
  var $form = $('#payment-form');
  $form.submit(function(event) {
    // Disable the submit button to prevent repeated clicks:
    $form.find('.submit').prop('disabled', true);

    // Request a token from Stripe:
    Stripe.card.createToken($form, stripeResponseHandler);

    // Prevent the form from being submitted:
    return false;
  });
});

function stripeResponseHandler(status, response) {
  // Grab the form:
  var $form = $('#payment-form');

  if (response.error) { // Problem!

    // Show the errors on the form:
    $form.find('.payment-errors').text(response.error.message);
    $form.find('.submit').prop('disabled', false); // Re-enable submission

  } else { // Token was created!

    // Get the token ID:
    var token = response.id;

    // Insert the token ID into the form so it gets submitted to the server:
    $form.append($('<input type="hidden" name="stripeToken">').val(token));

    // Submit the form:
    $form.get(0).submit();
  }
};
    </script>
</body>

 </html>

我的 servlet 是:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        try {
            //processRequest(request, response);

            Stripe.apiKey = "//test key//";

// Get the card details submitted by the form
            String tokenID = request.getParameter("stripeToken");

// Create a Recipient
            Map<String, Object> recipientParams = new HashMap<String, Object>();
            recipientParams.put("name", "Lord");
            recipientParams.put("type", "individual");
            recipientParams.put("card", tokenID);
            recipientParams.put("email", "test6@gmail.com");

            Recipient recipient = Recipient.create(recipientParams);

            Map<String, Object> transferParams = new HashMap<String, Object>();
transferParams.put("amount", 1000); // amount in cents
transferParams.put("currency", "usd");
transferParams.put("recipient", recipient);
transferParams.put("bank_account", "000123456789");
transferParams.put("statement_descriptor", "JULY SALES");

Transfer transfer = Transfer.create(transferParams);

            System.out.print("hi");
            RequestDispatcher view = request.getRequestDispatcher("index2.html");
            view.forward(request, response);

        } catch (AuthenticationException ex) {
            Logger.getLogger(Payout.class.getName()).log(Level.SEVERE, null, ex);
        } catch (InvalidRequestException ex) {
            Logger.getLogger(Payout.class.getName()).log(Level.SEVERE, null, ex);
        } catch (APIConnectionException ex) {
            Logger.getLogger(Payout.class.getName()).log(Level.SEVERE, null, ex);
        } catch (CardException ex) {
            Logger.getLogger(Payout.class.getName()).log(Level.SEVERE, null, ex);
        } catch (APIException ex) {
            Logger.getLogger(Payout.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

我收到未找到错误接收者,我不明白为什么。任何人都可以帮忙吗?我对此感到非常震惊。
Stack Trace:
SEVERE:   com.stripe.exception.InvalidRequestException: No such recipient: <com.stripe.model.Recipient@1975641541 id=rp_186thkGbhnSWFx0lIDZm2cmQ> JSON: {
  "id": "rp_186thkGbhnSWFx0lIDZm2cmQ",
  "active_account": null,
  "cards": {
    "data": [
      {
        "address_city": null,
        "address_country": null,
        "address_line1": null,
        "address_line1_check": null,
        "address_line2": null,
        "address_state": null,
        "address_zip": null,
        "address_zip_check": null,
        "brand": "Visa",
        "country": "US",
        "currency": null,
        "cvc_check": "pass",
        "default_for_currency": null,
        "dynamic_last4": null,
        "exp_month": 12,
        "exp_year": 2017,
        "fingerprint": "qhUUS5Kf5JM2a8L8",
        "funding": "debit",
        "last4": "5556",
        "name": null,
        "recipient": "rp_186thkGbhnSWFx0lIDZm2cmQ",
        "status": null,
        "tokenization_method": null,
        "type": null,
        "id": "card_186thjGbhnSWFx0lu8w3m1Sq",
        "object": "card",
        "account": null,
        "customer": null,
        "metadata": {}
      }
    ],
    "has_more": false,
    "total_count": 1,
    "url": "/v1/recipients/rp_186thkGbhnSWFx0lIDZm2cmQ/cards",
    "count": null,
    "request_options": null,
    "request_params": null
  },
  "created": 1462244168,
  "default_card": "card_186thjGbhnSWFx0lu8w3m1Sq",
  "deleted": null,
  "description": null,
  "email": "test@gmail.com",
  "livemode": false,
  "metadata": {},
  "migrated_to": null,
  "name": "Lord Blue",
  "type": "individual",
  "verified": false
}; request-id: req_8Nf12m7y81JQlC
    at com.stripe.net.LiveStripeResponseGetter.handleAPIError(LiveStripeResponseGetter.java:591)
    at com.stripe.net.LiveStripeResponseGetter._request(LiveStripeResponseGetter.java:443)
    at com.stripe.net.LiveStripeResponseGetter.request(LiveStripeResponseGetter.java:65)
    at com.stripe.net.APIResource.request(APIResource.java:133)
    at com.stripe.model.Transfer.create(Transfer.java:359)
    at com.stripe.model.Transfer.create(Transfer.java:318)
    at pay.Payout.doPost(Payout.java:114)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
    at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)
    at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)
    at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)
    at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)
    at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282)
    at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459)
    at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)
    at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201)
    at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175)
    at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)
    at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)
    at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)
    at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
    at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561)
    at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
    at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
    at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
    at java.lang.Thread.run(Thread.java:724)

最佳答案

看起来您尝试进行转移的方式已被弃用。

这在此处记录:https://stripe.com/docs/sending-transfers

我能够使用以下步骤成功进行测试传输:

第1步

确保您的 Dashboard 中有足够的资金

当我没有足够的时候,我收到了这个错误:

com.stripe.exception.InvalidRequestException: Insufficient funds in Stripe account. In test mode, you can add funds to your available balance (bypassing your pending balance) by creating a charge with 4000 0000 0000 0077 as the card number. You can use the the /v1/balance endpoint to view your Stripe balance (for more details, see stripe.com/docs/api#balance).; request-id: req_***************



我运行以下代码将 1000 美元放入我的:
import java.util.HashMap;
import java.util.Map;

import com.stripe.exception.StripeException;
import com.stripe.model.Charge;
import com.stripe.net.RequestOptions;

import com.stripe.net.RequestOptions.RequestOptionsBuilder;;

public class ChargeTest
{
    public static void main(String[] args)
    {
        String key = "sk_test_**************************";

        RequestOptions requestOptions = (new RequestOptionsBuilder()).setApiKey(key).build();
        Map<String, Object> chargeMap = new HashMap<String, Object>();
        chargeMap.put("amount", 100000);
        chargeMap.put("currency", "usd");
        Map<String, Object> cardMap = new HashMap<String, Object>();
        cardMap.put("number", "4000000000000077");
        cardMap.put("exp_month", 12);
        cardMap.put("exp_year", 2020);
        chargeMap.put("card", cardMap);
        try
        {
            Charge charge = Charge.create(chargeMap, requestOptions);
            System.out.println(charge);
        }
        catch (StripeException e)
        {
            e.printStackTrace();
        }
    }
}

第2步

为了创建新帐户,您需要注册您的平台,您可以在 https://dashboard.stripe.com/account/applications/settings 上进行。

如果不是,您将收到“invalid_request_error”

第 3 步

遵循创建传输的新方法。我能够通过查看 github 上的 StripeTest.java 找到这一点。

这是我的测试:
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import com.stripe.Stripe;
import com.stripe.exception.StripeException;
import com.stripe.model.Account;
import com.stripe.model.Transfer;

public class StripeExample
{
    public static void main(String[] args)
    {
        String key = "sk_test_*********";
        try
        {
            // 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 = key;

            Map<String, Object> defaultAccountParams = new HashMap<String, Object>();

            Map<String, Object> externalAccount = new HashMap<String, Object>();

            externalAccount.put("country", "US");
            externalAccount.put("routing_number", "110000000");
            externalAccount.put("account_number", "000123456789");
            externalAccount.put("account_holder_name", "Test Holder");
            externalAccount.put("account_holder_type", "individual");
            externalAccount.put("object", "bank_account");

            defaultAccountParams.put("external_account", externalAccount);
            defaultAccountParams.put("email", getUniqueEmail());

            Account destination = Account.create(defaultAccountParams);

            Map<String, Object> transferParams = new HashMap<String, Object>();

            transferParams.put("amount", 1000);
            transferParams.put("currency", "usd");
            transferParams.put("destination", destination.getId());

            Transfer transfer = Transfer.create(transferParams);
        }
        catch (StripeException e)
        {
            e.printStackTrace();
        }
    }

    static String getUniqueEmail()
    {
        return String.format("test+bindings-%s@stripe.com", UUID.randomUUID().toString().substring(24));
    }
}

关于java - 没有这样的收件人错误 Stripe ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36994786/

相关文章:

java - 简单的Java套接字客户端,是什么引发了此ConnectException?

java - 记录用于播放的 android 事件

java - 子类是否继承私有(private)字段?

php - 使用PHP,如何访问从Stripe API返回的 protected _values属性?

java - 打印机作家让我输入两次以循环一次

java - 以编程方式添加安全方案时,架构从组件中消失

stripe-payments - 可以查询Stripe管理帐户的余额吗?

python - 如何通过他们的Python库使用Stripe API的卡片指纹功能?

php - Stripe PHP 订阅 Webhook

javascript - Stripe 动态支付