Mekey Salaria
Mekey Salaria

Reputation: 1129

One time, followed by a reoccuring charge in Stripe

I am working on Stripe payment gateway.

Here is my code:

$token = $_POST['stripeToken'];

// Create the charge on Stripe's servers - this will charge the user's card
  try {
    $charge = Stripe_Charge::create(array(
    "amount" => 700, // amount in cents, again
    "currency" => "SEK",
    "card" => $token,
    "description" => "[email protected]")
    );
     echo "<center><font color='green'>Payment Successfull!</font></center>";
} catch(Stripe_CardError $e) {
    // The card has been declined
        }

I am getting the stripeToken correctly and also able to charge 1 USD where 7 SEK = 1 USD But actually, I want to charge user 7 SEK instantly and then want to charge 399 per month after 5 days.

I did some research, and found that webhooks are something that can help me out, but I am very new to stripe and not getting much idea regarding web hooks. It would be great full if someone could help me out to solve my above condition!

Upvotes: 0

Views: 84

Answers (1)

Larry Ullman
Larry Ullman

Reputation: 2271

What you'd want to do in that case is create a Customer object in Stripe:

You'd associate the token with the customer to register the card with us. Once you've created the customer, you can then process one-off charges and/or subscribe the customer to a plan to create recurring billing.

In your specific case, what you'd want to do is create the customer, subscribed to a $3.99/month plan with a 5 day trial, then either do a one-off charge for the 7 SEK/1 USD or create an invoice item in that amount and immediately create an invoice.

With subscriptions, you'll want to use webhooks to be notified of successful or failed recurring payments.

Hope that helps! Larry

PS I work at Stripe on support.

Upvotes: 1

Related Questions