#TheUchi007-SCT
1 messages · Page 1 of 1 (latest)
So, I have the following flow:
- Send a user to a checkout page(custom, made by me)
- When he gets in, he gets a customer created in Stripe
- Once he has a customer ID, I create a subscription with the status "incomplete"
- I then present the CC form using PaymentElement component in React
- User submits the form and the payment goes through
Up to that point, it works well, but I am integrating a referral system, so I want to send a commission to their account. The way I am doing it, I am not sure where I can handle the transfer function for the commission.
The way I am doing it, I am using:
stripe.subscriptions.create
to create the subscription, and I am passing the parameter:
expand: ["latest_invoice.payment_intent"].
This allows me to get a payment_intent object that gives me a client_secret. I use that client_secret to process payment of subscription, using stripe.confirmCardPayment
On that whole process, I am not sure where I can do the transfer part
is the commission transferred every invoice payment, or only the first time?
So, the way we want it is:
- A user signs up with a referral code. Said user buys a membership. Every time the membership renews, the referrer will get a commission
Also, we have another scenario.
- The user sells products on the site. For every sale, we get a commission from the full price.
So to answer your question, every invoice payment
you should probably make use of this parameter instead : https://stripe.com/docs/api/subscriptions/create#create_subscription-transfer_data
it'll automatically transfer a percentage of the payment to the connected account upon successful payment
instead of you implementing the logic to do it every invoice payment
Ah, that does look like what I am looking for, thanks! I do have one last question. What if I want to add a third party? So, going back to the second scenario:
- The user sells products on the site. For every sale, we get a commission from the full price. If there is a referral code present, we want to send a commission from our commission to the referrer
Yes
So in other words, transfer to 2 connect accounts
The link I posted does that, but I dont know how to implement it
if that's the case, then you have no choice but to use a separate transfer in that case. I would still recommend that you use the transfer_data parameter. But subsequently, upon receipt of invoice.paid or alternatively, invoice.payment_succeeded, make a separate transfer for the referral
to make a Transfer, use https://stripe.com/docs/api/transfers#transfers
Awesome, I will try that. Thank you so much!
Oh, I do have a question. How can I pass a parameter on the payment_intent client_secret when I create a subscription?
That way, I can pass the ID of the account(s) that I will make the transfer to
you would want to pass it when creating the subscription : https://stripe.com/docs/api/subscriptions/create#create_subscription-metadata. But unfortunately, the metadata on the subscription is not passed on to the Invoice or the corresponding PaymentIntent. What i'd suggest that you do is to either save the subscription's referral detail to your own database (upon successful subscription creation payment), or every time you get a successful invoice payment event, make a request to Stripe to retrieve the subscription to get the subscription's metadata
Ah ok, I will try that. Thanks
So hypothetically speaking, I could save metadata as “referrer 1”, and “referrer 2”. And then retrieve that data, correct?
I mean, if I add those when I create the sub
metadata is a key-value format
but yes, you could save those data when creating the sub and then retrieve it
Nvm, I just tried it. This flow works! Thank you for pointing me on the right direction!