oscarychen/drf-stripe-subscription

react native stripe element implementation?

Closed this issue · 2 comments

Hey there, I've been trying to following this guide i have also created the custom Checkout, i am getting data null in payment_intent and setup_intent is there any option i am missing?

Custom Serializer

class CustomCheckoutRequestSerializer(CheckoutRequestSerializer):
    """Handle creation of a custom checkout session where parameters are customized."""

    def validate(self, attrs):
        stripe_user = get_or_create_stripe_user(user_id=self.context['request'].user.id)
        try:
            checkout_session = stripe_api_create_checkout_session(
                customer_id=stripe_user.customer_id,
                price_id=attrs['price_id'],
                trial_end='auto' if stripe_user.subscription_items.count() == 0 else None,
                payment_method_types=["card"],
                checkout_mode="subscription",
            )
            print(checkout_session)
            attrs['session_id'] = checkout_session['id']
            attrs['customer_id'] = checkout_session['customer']
            attrs['payment_intent'] = checkout_session['payment_intent']
            attrs['url'] = checkout_session['url']
        except StripeError as e:
            raise ValidationError(e.error)
        return attrs

SETTING

DRF_STRIPE = {
    "STRIPE_API_SECRET": env('STRIPE_API', default=''),
    "STRIPE_WEBHOOK_SECRET": "*",
    "NEW_USER_FREE_TRIAL_DAYS": 7,
}

I suspect it has to with the mode, payment intent might not be always populated: https://stackoverflow.com/questions/66545866/payment-intent-is-null-in-a-subscription-checkout-session

i see thanks i guess ill have to go for url