Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why should i create a customer object before charging in stripe?

Hi i have seen the code for stripe payment as below. First create a customer object

$customer = \Stripe\Customer::create(array(
          "card" => $token,
          "description" => "Product Purchase for Book",
          "email" => "[email protected]"
 ));

Then charge by using that customer object

  \Stripe\Charge::create(array(
         "amount" => $amount, # amount in cents, again
         "currency" => 'usd',
         "customer" => $customer->id)
   );

But below is the code which can be used to charge the user directly without creating any customer object.

\Stripe\Charge::create(array(
       "amount" => 3000,
       "currency" => "eur",
       "card" => $_POST['stripeToken'],
       "description" => $_POST['email'],
       "metadata" => array("order_id" => "6735", "userid" => '1111')
));

So can you please explain me below things

  1. Which one is better?
  2. What is the benefit of creating a customer object?
  3. Can use store and use that customer object to charge that user any any time say recurring payment?

Thanks in advance

like image 956
pkk Avatar asked Sep 09 '16 05:09

pkk


People also ask

When you charge your customers Stripe?

You can charge your customers at any time and for any amount once you have saved the customer's card in Stripe. If you have certain action-based criteria which you want to trigger a charge, you can set that logic up on your back end and directing it to charge the card associated with the customer ID.

How do I deal with failed subscription payments on Stripe?

If a payment fails for a subscription invoice, your customers can use the Stripe-hosted page to: View the details and amounts for the failed invoice and the associated subscription. Add a new card payment method for their subscription for the payment that's due and for future subscription payments.

What is payment intent in Stripe?

The PaymentIntent encapsulates details about the transaction, such as the supported payment methods, the amount to collect, and the desired currency.


1 Answers

There are several benefits to creating the customer object first:

  1. You can charge multiple items to the same user, thus providing both you and the customer a billing history. This is valuable to you as a store owner (e.g. offering deals to repeat customers) and valuable to the customer to quickly pull up their purchase history.

  2. Fraud prevention

  3. Trends and analytics

  4. As you've already stated, subscriptions

A footnote: I personally maintain my own user-base and update both the Stripe customer object and my user data when a transaction occurs. This allows me to extend the Stripe customer with my own custom data and run complex analytics to discover trends.

like image 57
brandonscript Avatar answered Oct 05 '22 23:10

brandonscript