#nsad_api

1 messages ¡ Page 1 of 1 (latest)

low kilnBOT
knotty prairieBOT
#

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.

low kilnBOT
#

👋 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.

knotty prairieBOT
twilit dove
light lodge
#

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
        )
twilit dove
#

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.

light lodge
#

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,
                )
twilit dove
#

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

low kilnBOT
light lodge
#

Ok thanks Toby!

#

I will verify here!