Subscriptions

!! IMPORTANT !!

NOTE: this has been deprecated in favor of intents with scheduled reauth.

  • Old setup, using subscriptions.
  1. create a product/price
        product = stripe_client.v1.products.create(
            params={
                "name": f"Dare {dare_id}",
                "description": f"flipdare dare with id {dare_id}",
                "tax_code": "txcd_10402300",
            }
        )

        price = stripe_client.v1.prices.create(
            params={
                "product": product_id,
                "unit_amount": amount,
                "currency": currency,
                "tax_behavior": "inclusive", # account is responsible for tax.
                "recurring": {
                    "interval": "year",
                    "interval_count": 1,
                },
            }
        )

        subscription = stripe_client.subscription_schedules.create({
            "customer": customer_id,
            "start_date": start_date_timestamp,  # Start billing in 45 days
            "end_behavior": "release",  # rel. subscription after phases complete
             "default_settings": {
                 "on_behalf_of": account_id,  # Bill on behalf of connected account
                   "application_fee_percent": app_fee,  # Apply application fee percentage
                   "automatic_tax": {
                   "enabled": False,
                   "liability": None,
                   },
                    "transfer_data": {
                        "destination": account_id,  # Funds go to connected account
                    },
             },
            "phases": [
                {
                    "items": [{"price": price_id, "quantity": 1}],
                    "end_date": end_date_timestamp,  # Define explicit end date instead of iterations
                    "proration_behavior": "none",
                    "currency": currency,
                },
            ],
        })
  1. For User A, a Customer, SetupIntent and a EphemeralKey, is created:

        intent = stripe_client.v1.setup_intents.create(
            params={
                "customer": customer_id,
                "usage": "off_session",
                "payment_method_types": ["card"],
            }
        )

        ephemeral_key = stripe_client.v1.ephemeral_keys.create(
            params={
                "customer": customer_id,
            }
        )
  1. then a PaymentSheet is shown to the user to confirm the user has a credit card.
      await Stripe.instance.initPaymentSheet(
        paymentSheetParameters: SetupPaymentSheetParameters(
          setupIntentClientSecret: clientSecret,
          merchantDisplayName: 'Flipdare',
          customerId: customerId,
          customerEphemeralKeySecret: ephemeralKey,
          style: ThemeMode.dark,
        ),
      );

Drawbacks

  • Since a setup intent does not have an amount, its difficult to show the user what amount will actually be charged.
  • Since a SetupIntent is used, automatic currency conversion (like what is available in a PaymentIntent), is not able to be performed.