0

I want to create the stripe recurring payment with stripe checkout session. I do not want to create subscription manually on stripe payment subscription but I want to create new subscription every time when user donate with subscription any help in this regards will be highly appreciated.

My HTML Form.

<form action="/create-checkout-session-subscription.php" method="POST">
  <input type="hidden" name="subscription" value="month">
  <input type="hidden" name="subscriptionPrice" value="20">
  <input type="hidden" name="cause">
  <button type="submit">
    Donate
  </button>
</form>

My PHP Code

require 'vendor/autoload.php';
$stripe_secret_key = "MY_SECRET_KEY";

$stripe = new \Stripe\StripeClient($stripe_secret_key);

$checkout_session = $stripe->checkout->sessions->create([
  'line_items' => [[
    'price_data' => [
      'currency' => 'usd',
      'product_data' => [
        'name' => $_POST['oneTimeCause'],
      ],
      'unit_amount' => $_POST['oneTimePrice'] * 100,
    ],
    'quantity' => 1,
  ]],
  'mode' => 'payment',
  'success_url' => 'https://mywebsite/?success',
  'cancel_url' => 'https://mywebsite/?cancel',
]);

header("HTTP/1.1 303 See Other");
header("Location: " . $checkout_session->url);
shaz3e
  • 316
  • 2
  • 14

0 Answers0