条带支付模式-没有这样的客户例外

vaqhlq81  于 2021-07-12  发布在  Java
关注(0)|答案(1)|浏览(253)

我成功地将条带 checkout 集成到一个javaweb应用程序中。
我想有电子邮件和姓名字段的前缀。根据文档,我必须创建一个新客户,然后将其传递给会话。以下是代码的相关部分:

Stripe.apiKey = retrieveKey("CLIENT_SECRET_KEY");

        Map<String, Object> paramsC = new HashMap<>();
        paramsC.put("description", "My First Test Customer (created for API docs)");
        paramsC.put("email", "person@example.com");
        paramsC.put("name", "some name");
        Customer customer = Customer.create(paramsC);

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

        ArrayList<String> paymentMethodTypes = new ArrayList<>();
        paymentMethodTypes.add("card");
        params.put("payment_method_types", paymentMethodTypes);

        ArrayList<HashMap<String, Object>> lineItems = new ArrayList<>();
        HashMap<String, Object> lineItem = new HashMap<>();
        lineItem.put("name", "Stainless Steel Water Bottle");
        lineItem.put("amount", 8834);
        lineItem.put("currency", "eur");
        lineItem.put("quantity", 1);
        lineItems.add(lineItem);
        params.put("line_items", lineItems);
        params.put("customer", customer.getId());

        params.put("success_url", DOMAIN_URL);
        params.put("cancel_url", DOMAIN_URL + "/cancel.xhtml");

        RequestOptions requestOptions = RequestOptions.builder().setStripeAccount(CONNECTED_ACCOUNT_ID).build();

        session = Session.create(params, requestOptions);

不幸的是,我得到了这个错误: Severe: com.stripe.exception.InvalidRequestException: No such customer: 'cus_****'; code: resource_missing; request-id: 从创建会话的行抛出。
有人知道怎么解决这个问题吗。非常感谢你。

iecba09b

iecba09b1#

这是因为 requestOptions 对于 checkout 会话,您正在设置一个已连接的帐户 setStripeAccount(CONNECTED_ACCOUNT_ID) . 客户创建没有这个,所以客户是在您的平台帐户上创建的,而不是在连接的帐户上创建的。
如果您想在已连接的帐户上拥有会话,您还需要在那里创建客户。你应该添加相同的 requestOptionssetStripeAccount(CONNECTED_ACCOUNT_ID) 向您的客户创建请求。

相关问题