I am trying to create a simple 'add monthly Subscriptions(Monthly payments) button' custom plugin for a clients Wordpress website. My current issue is how am I to include Stripe's PHP library in the plugin? I have Stripe operational running it through Composer (autoload.php) locally. But adding it to Wordpress....
I have added the basic code from Stripe's website below: https://stripe.com/docs/recipes/subscription-signup
<form action="/create_subscription.php" method="POST">
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="pk_test_mlHAlLZMWfb2URJZIvb6Qntd"
data-image="/images/marketplace.png"
data-name="Emma's Farm CSA"
data-description="Subscription for 1 weekly box"
data-amount="2000"
data-label="Sign Me Up!">
</script>
</form>
This is the PHP.
<?php // Create a customer using a Stripe token
// If you're using Composer, use Composer's autoload:
require_once('vendor/autoload.php');
// Be sure to replace this with your actual test API key
// (switch to the live key later)
\Stripe\Stripe::setApiKey("sk_test_000000000000");
try
{
$customer = \Stripe\Customer::create(array(
'email' => $_POST['stripeEmail'],
'source' => $_POST['stripeToken'],
'plan' => 'weekly_box'
));
header('Location: thankyou.html');
exit;
}
catch(Exception $e)
{
header('Location:oops.html');
error_log("unable to sign up customer:" . $_POST['stripeEmail'].
", error:" . $e->getMessage());
}
Any help would be appreciated!