#nsad_api
1 messages ¡ Page 1 of 1 (latest)
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.
- nsad_api, 2 hours ago, 16 messages
đ Welcome to your new thread!
â˛ď¸ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
âąď¸ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
đ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1237425989596745748
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
The endpoint and parameters for creating a Transfer can be found in our API ref:
https://docs.stripe.com/api/transfers/create
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
Hello toby, my ideia is create a system affiliate from my subscription, so in this case, i wanna implement in checkout, just one time, example: when user buy a subscription and have affiliate, need to make a transfer to affiliate
so i need source_transaction to make transfer
how i can get this?
its possible create payment_intent inside this:
checkout_session = stripe.checkout.Session.create(
payment_method_types=['card'],
locale='pt-BR',
line_items=[{
'price': id,
'quantity': 1,
}],
metadata={
'user_id': request.user.pk,
'product_id': product_id,
'price_id': price_id,
},
mode='subscription',
success_url=success_url,
cancel_url=cancel_url,
customer_email=request.user.email
)
source_transaction is an optional parameter, but is very useful as it allows you to schedule Transfers that will occur automatically when the payment completes. You can get the ID of the Charge, to pass to source_transaction from the Payment Intent that is created. Since you're creating Subscriptions, that would be the Charge associated with the Payment Intent belonging to the Subscription's first Invoice.
yes, but in my country is necessary
How i can get CHARGE_ID?
subscription_stripe = stripe.Subscription.retrieve(id=stripe_subscription_id)
stripe_subscription_item_id = subscription_stripe['items']['data'][0]['id']
subscription = user_has_subscription(user)
try:
with transaction.atomic():
subscription.status = "canceled"
subscription.save()
Subscription.objects.create(
user=user,
product=product,
price=price,
stripe_customer_id=stripe_customer_id,
stripe_subscription_id=stripe_subscription_id,
stripe_subscription_item_id=stripe_subscription_item_id,
status="active"
)
transfer_amount = int(price.unit_amount * 0.10) # 10% do valor da assinatura
stripe.Transfer.create(
amount=transfer_amount,
currency="brl",
destination="acct_1PCsw7OQ47ZChuLng",
source_transaction=charge_id,
)
When you retrieve the Subscription, use expand to expand and include latest_invoice.payment_intent:
https://docs.stripe.com/api/expanding_objects
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
That should nest the associated Invoice and Payment Intent directly in the response you receive, so you can pull out the Charge ID via latest_invoice.payment_intent.latest_charge