Warm tip: This article is reproduced from serverfault.com, please click

stripe: problems setting connected account on subscription

发布于 2020-12-27 11:07:59

I'm having some issues for adding an amount fee on a subscription on Stripe. Looking at this documentation I should be able to add a connected account when creating the subscription so i can set an application fee on the subscription without having to do any modification on it afterwards.

I'm trying to use a RequestOptions on the subscription creation to add the connected stripe account but it seems that if i use it it's redirecting to the live account and it's not finding the customer i'm using making the request to fail.

Here is the code of the whole process:

        attachPayMethodToCustomer(bookingDetails.getPaymentMethod(), user.getCustomerId());
        Price price = getPriceForItem(item, bookingDetails.isExclusive());

        SubscriptionCreateParams.Item item = SubscriptionCreateParams.Item.builder()
                .setQuantity(1L)
                .setPrice(price.getId())
                .build();

        BigDecimal bd = new BigDecimal(calculateSubscriptionFee(price.getUnitAmount() / 100, bookingDetails.isRecorded()), new MathContext(2, RoundingMode.HALF_UP));

        SubscriptionCreateParams.Builder params = SubscriptionCreateParams.builder()
                .setCustomer(user.getCustomerId())
                .setApplicationFeePercent(bd)
                .addItem(item);

        if (bookingDetails.hasExtras()) {
            Price recordPrice = getExtrasPrice(seller().getCurrency());
            SubscriptionCreateParams.Item extraItem = SubscriptionCreateParams.Item.builder()
                    .setQuantity(1L)
                    .setPrice(extraPrice.getId())
                    .build();

            params.addItem(extraItem);
        }

        RequestOptions ro = new RequestOptions.RequestOptionsBuilder()
                .setStripeAccount(seller.getStripeAccountId())
                .build();

        Subscription subscription = Subscription.create(params.build(), ro);

I'm receiving this exception when it tries to create the subscription:

com.stripe.exception.InvalidRequestException: No such customer: 'cus_IaFZjrBAlBsXXX'; code: resource_missing; request-id: req_C67JN4tgneXXXX but i can see the customer on the dashboard. I tried also to override the stripe api key to use the test one, but i have the same issue.

Thanks a lot, Adrián

Questioner
Acampoh
Viewed
0
Acampoh 2020-12-29 22:22:02

After talking with Stripe support it seems i was doing it in the wrong way.

For this they have a different way they call destination charges (here is the link)

Basically instead of using the RequestOptions for there is an option in the subscription called TransferData where you can place the Connected account id. Here is the sample from their web

SubscriptionCreateParams params = SubscriptionCreateParams.builder()
  .setCustomer("cus_XXXXXXX")
  .addItem(SubscriptionCreateParams.Item.builder()
    .setPrice("price_XXXXX")
    .build())
  .setTransferData(
    SubscriptionCreateParams.TransferData.builder()
      .setDestination("{{CONNECTED_STRIPE_ACCOUNT_ID}}")
      .build())
  .addExpand("latest_invoice.payment_intent")
  .build();
Subscription subscription = Subscription.create(params);

Thanks a lot and kudos to Stripe support team!