#arya_

1 messages · Page 1 of 1 (latest)

summer latchBOT
#

Hello! We'll be with you shortly. Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

gusty pumice
#

I am looking to use Stripe Connect where I can accept recurring payment from users, keep a cut, and pass on the remainder to merchants. I read through many Stripe docs, so please don't refer me there. I want to understand the following:
How can I create a way in which the user simply chooses the product, gets redirected to the stripe page, pays and I receive a webhook notification containing the information that the user paid for so and so product?
Meanwhile, I want to forward the payment (after keeping a cut) to the merchant. What's the best way to onboard a merchant?
Again, I read the docs but they weren't clear enough to answer my questions

regal acorn
#

I'm still going to send you docs links because they will answer your question

#

For accepting a payment on a stripe-hosted link you can do this:
https://stripe.com/docs/payments/accept-a-payment

It sounds like the connect charge flow you want is destination charges:
https://stripe.com/docs/connect/destination-charges

You can do that with checkout too (the first link I sent) by passing in transfer_data here: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-transfer_data

The issue is if you're doing 1-time payments, only payment intents are created by default in Checkout, so you would only get the amount in the webhook event payment_intent.succeeded. Is that sufficient? If not, you can add some metadata to the payment intent as well for information on the product: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-payment_intent_data-metadata

#

The above should be more than enough to get you going

#

But if you have specific questions then don't hesitate to ask

gusty pumice
#

Thank you let me go through them rn

#

Btw if I have to create a recurring payment, can I use the following flow (what changes do I need to do)

customer = await stripe.customers.create({
        email: user.email,
        description: user.fullName,
      });
const subscription = await stripe.subscriptions.create(subscriptionObject);
return res.json({
  // subscriptionId: subscription.id,
  clientSecret: subscription.latest_invoice.payment_intent.client_secret,
});
regal acorn
#

You said you wanted a stripe hosted payment link?

#

Above is if you're handling payment on your site with a custom integration

#

And if you're doing subscriptions, then you can listen to invoice.paid

#

It'll have the product information in the webhook event

#

My above answer was for if you were doing 1-time payments

#

Sorry I missed where you said recurring payments in your question

#

The rest of my answer still applies though (you'd pass transfer_data to specify connect account to transfer funds to), and listen to invoice.paid events on your webhook endpoint

gusty pumice
#

I was thinking of using Express with Destination charges
Goal is to collect recurring payments from end customer, take a part of it and forward the remaining to the merchant

regal acorn
#

Yeah

#

My answer covers that

#

That's what transfer_data does

gusty pumice
#

So essentially, the above code I sent just needs the transfer data field and it's done?
Where do I specify the platform's cut?

regal acorn
#

No

#

You said you wanted a stripe hosted payment link, yeah?

#

If that's the case, you can't create subscriptions directly

#

You need to create a checkout session

gusty pumice
#

For an existing codebase I use the following code for subscriptions (no paymentintent is here so I wanted to use the same method - lmk if that's wrong):

const createSubscription = async (req, res) => {
  try {
    const { planType, renewalPeriod, promoCode } = req.body;

    // Create or retrieve customer
    const user = await UserModel.findById(req.user._id);
    let customer;
    if (!user.customerId || user.customerId === "") {
      customer = await stripe.customers.create({
        email: user.email,
        description: user.fullName,
      });
      user.customerId = customer.id;
      await user.save();
    } else {
      customer = await stripe.customers.retrieve(user.customerId);
    }

    const subscriptionObject = {
      customer: customer.id,
      items: [
        {
          price: priceIdMap[planType][renewalPeriod],
        },
      ],
      payment_behavior: "default_incomplete",
      payment_settings: { save_default_payment_method: "on_subscription" },
      expand: ["latest_invoice.payment_intent", "pending_setup_intent"],
    };
    // Stripe's subscription api takes in the app id of a promotion code
    // so we need to check if the promotion code is correct first.
    // Stripe throws an error for invalid or empty promotion codes. Hence,
    // we only add the promotion_code field if the promotion code is valid.
    if (promoCode === process.env.STRIPE_STUDENT_PROMO_CODE) {
      subscriptionObject.promotion_code =
        process.env.STRIPE_STUDENT_PROMO_CODE_APP_ID;
    }
    const subscription = await stripe.subscriptions.create(subscriptionObject);
    res.json({
      clientSecret: subscription.latest_invoice.payment_intent.client_secret
    });
  } catch (err) {
    return res.status(400).json({
      message: `Encountered error in createSubscription: ${err.message}`,
    });
  }
};
#

What changes do I need to make in this to achieve what I want this time

#

I'm just asking for fundamental changes - not code editing haha

regal acorn
#

I'll ask again. Do you want a stripe-hosted paymetn link?

gusty pumice
#

Sure - could you explain both options: if I want a stripe-hosted payment link and if I dont

regal acorn
#

Stripe-hosted page tab at the top if you want stripe hosted

#

Custom flow tab if you want hosted on your site

#

You can pass transfer data in either scenario

gusty pumice
#

So, the code I shared with you, that's for a custom flow tab right?

regal acorn
#

Looks like it but I don't know your integration

#

Yeah it looks to be

#

You create a subscription object directly and return its client secret