Stripe Api

Docs: https://stripe.com/docs/api#create_customer

20 flashcards · Programming Languages · by lakesare

  1. When would you want to create a customer object? stripe.Customer.create()

    Customer object allows you to perform recurring charges, and to track multiple charges, that are associated with the same customer.

  2. What is: customer.sources?

    The customer’s payment sources, if any.

  3. When must you provide a source on customer creation? stripe.Customer.create( source="tok_visa" # obtained with Stripe.js )

    When we create stripe.Subscription for a stripe.Plan that is not free, we must either: provide a source on stripe.Subscription.create(source=...) (this will make this source customer's default source automatically. ) have the customer that already has a valid source attached Passing source will create a new source object, make it the customer default source, and delete the old customer default if one exists.

  4. stripe.Subscription vs stripe.Plan?

    stripe.Plan gives amount and interval of payments. stripe.Subscription connects stripe.Plan and stripe.Customer: stripe.Subscription.create( customer="cus_D9K8kGjwVfhBnm", items=[ { "plan": "sapphire-freelance-950", }, ] )

  5. What can be customer's source (3 options)? import stripe stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2" stripe.Customer.create( source=??? )

    The source can be: stripeToken (taken from a Js library) stripe.Source object dictionary with user’s credit card details. You must provide a source if the customer does not already have a valid source attached, and you are subscribing the customer to be charged automatically for a plan that is not free.Passing source will create a new source object, make it the customer default source, and delete the old customer default if one exists. If you want to add an additional source, instead use the ca…

  6. What will happen if we update stripe.Customer with a new source?

    It will become the default payment method, used automatically when we make a charge using this customer's id. Updating a Customer object that has a default source automatically detaches the existing source and adds the provided source as the new default. To add a source without replacing the existing default, use the attach method.The default source is automatically selected if you make a charge request using the customer parameter without specifying a source.

  7. After the creation of the stripe.Subscription - when will the stripe.Customer be charged?

    Immediately! stripe_subscription = stripe.Subscription.create( customer=stripe_customer.id, plan=small_plan.id ) self.assertEqual(self.our_balance() - initial_balance, 48.25)

  8. What does stripe.Subscription.create(quantity=....) argument does?

    The quantity of the plan to which the customer should be subscribed. For example, if your plan is $10/user/month, and your customer has 5 users, you could pass 5 as the quantity to have the customer charged $50 (5 x $10) monthly.

  9. What is the difference between Stripe Checkout and Stripe Elements?

    Stripe Checkout (all ready, but can't customuze much): <form action="your-server-side-code" method="POST"> <script src="https://checkout.stripe.com/checkout.js" class="stripe-button" data-key="pk_test_g6do5S237ekq10r65BnxO6S0" data-amount="999" data-name="Stripe.com" data-description="Example charge" data-locale="auto" data-zip-code="true"> </script> </form> Stripe Elements (entirely customizable, but can use validations etc): <form action="/charge" method="post" id="payment-form"> <div class="…

  10. How to create a one-time charge?

    # Token is created using Checkout or Elements! # Get the payment token ID submitted by the form: token = request.form['stripeToken'] # Using Flask charge = stripe.Charge.create( amount=999, currency='usd', description='Example charge', source=token, ) Once you’ve securely collected and tokenized your customer’s credit card using Checkout or Elements, you can charge the card immediately or save it for later. Unlike tokenization, which occurs in the browser, charge attempts are made from your ser…

  11. When you subscribe a customer to a plan, the API call immediately:

    Creates an invoice Attempts to pay the invoice Closes the invoice

  12. What is a billing cycle anchor?

    Date of the billing.

  13. How is stripe.Subscription's billing_cycle_anchor determined?

    defaults to when the subscription was created or if a trial period is used, the trial end set explicitly at creation

  14. Subscription invoices are prebilled, meaning customers pay at the start of a billing cycle. (https://stripe.com/docs/billing/invoices/subscription) Consequently, an invoice always reflects the cost of the subscription for the upcoming billing period plus any invoice items from the previous billing period. Invoice items are not prorated when a customer’s subscription is changed. The first invoice on a subscription is effectively closed from the moment it’s created. If the payment succeeds or no…

  15. What is the difference between stripe.Charge and stripe.Invoice?

    The Invoice Object: for subscriptions. Invoices are statements of what a customer owes for a particular billing period, including subscriptions, invoice items, and any automatic proration adjustments if necessary. The Charge Object: for one-time payments. For example when you create an invoice or sale on a one time credit or debit card charge

  16. We just created a new stripe customer, and subscribed them to the 50-dollar subscription plan. What invoice items will stripe.Invoice.create( customer="cus_DjXaOTLSPSXFz4" ) include?

    None! stripe.Invoice.create() will only list (and .pay() for) pending items (for example it would list proration costs if they existed), without the next-month bill! stripe.Invoice.upcoming() though, on the other hand, will include BOTH proration costs, and the next-month billing.

  17. By default, stripe prorates subscription charges. If a customer signs up on May 1 for a $100 plan, she'll be billed $100 immediately. If on May 15 she switches to a $200 plan, what will she be billed on June 1st?

    $250 ($200 for a renewal of her subscription, plus a $50 prorating adjustment for half of the previous month's $100 difference).

  18. What does invoice.closed signify?

    It's not open to modifications via the invoice items. This time, the invoice’s closed attribute is false, which means it’s open for modification via invoice items.

  19. What does customer pay if stripe.Subscription.prorate=false?

    Customer is moved to the new plan, BUT rates stay the same for the current and next month. With proration disabled, the customer is billed the full amount for the new plan when the next invoice is generated. The customer is still moved to the new plan immediately, however, even though they don’t pay for the new plan until the next billing cycle.

  20. Suppose you retrieved an invoice. How to know when payment for it will be attempted?

    invoice.next_payment_attempt The invoice also has a next_payment_attempt attribute that tells you the next time (as a Unix timestamp) payment for the invoice will be automatically attempted.