首页 > 解决方案 > com.stripe.exception.InvalidRequestException:根据印度法规,出口交易需要客户姓名和地址。在春季靴子中

问题描述

我在我的 Spring Boot 项目中集成了条带

    @PostMapping("/create-charge")
     public @ResponseBody Response createCharge(String email, String token) {
            if (token == null) {
                return new Response(false, "Stripe payment token is missing. Please, try again later.");
            }
            String chargeId = stripeService.createCharge(email, token, 999); //$9.99 USD
            if (chargeId == null) {
                return new Response(false, "An error occurred while trying to create a charge.");
            }

            return new Response(true, "Success! Your charge id is " + chargeId);
        }

我的服务

public String createCharge(String email, String token, int amount) {
        String id = null;
        try {
            Stripe.apiKey = API_SECRET_KEY;
            Map<String, Object> chargeParams = new HashMap<>();
            chargeParams.put("amount", amount);
            chargeParams.put("currency", "usd");
            chargeParams.put("description", "Charge for " + email);
            chargeParams.put("source", token); // ^ obtained with Stripe.js

            //create a charge
            Charge charge = Charge.create(chargeParams);
            id = charge.getId();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return id;
    }

我收到异常 com.stripe.exception.InvalidRequestException:根据印度法规,出口交易需要客户姓名和地址。更多信息在这里:https ://stripe.com/docs/india-exports 我应该如何在请求中传递地址?我试图通过这样的地址

 Stripe.apiKey = API_SECRET_KEY;
            Map<String, Object> chargeParams = new HashMap<>();
            chargeParams.put("amount", amount);
            chargeParams.put("currency", "usd");
            chargeParams.put("description", "Charge for " + email);
            chargeParams.put("source", token); // ^ obtained with Stripe.js
            Map<String, Object> customerParams = new HashMap<>();
            Map<String, String> addressParams = new HashMap<>();
            customerParams.put("description", "Customer for " + email);
            customerParams.put("email", email);
            customerParams.put("address", addressParams);
            addressParams.put("city", "varanasi");
            addressParams.put("country", "india");

            customerParams.put("source", token); // ^ obtained with Stripe.js
            //create a new customer
            Customer customer = Customer.create(customerParams);
            chargeParams.put("customer", customer.getId());

            //create a charge
            Charge charge = Charge.create(chargeParams);
            id = charge.getId();

但现在出现异常 com.stripe.exception.InvalidRequestException: Customer cus_JIMd90oUI9V8e6 does not have a linked source with ID tok_1Iflu8AuNrJFnosEZI2huyYo.; 代码:缺失

当我将货币更改为 inr 时,问题已解决,但我不想更改货币

标签: javaspring-bootstripe-payments

解决方案


我在使用 Stripe API 创建费用时也收到了这个异常。

我对Java不太熟悉,但假设没有其他错误。

试试这个:货币USD更改为INR

这对我有用,所以希望对你也有用。


推荐阅读