1

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

Acampoh
  • 589
  • 1
  • 8
  • 23
  • "No such..." errors are usually caused by either a mismatch in API keys (e.g. using a mixture of your test plus live keys) or by trying to access objects that exist on a different account (e.g. trying to perform an operation from your platform account on an object that was created on a connected account). In your case you should check that the customer exists on the account set in `seller.getStripeAccountId()`. – Paul Asjes Dec 28 '20 at 01:46
  • I have been debugging it and everything looks ok to me. In fact i can see the error on the developer dashboard and i can go to the customer that gives me error through the link provided on the request data there. Maybe i have something broken on my account, I sent a request to stripe support to try to find what's wrong. I'll post their answer here too – Acampoh Dec 28 '20 at 14:42

1 Answers1

1

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!

Acampoh
  • 589
  • 1
  • 8
  • 23