Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialStripeot tanulok
33 PointsHow to create a Stripe subscription?
Can someone help me how can I create a Stripe subscription button in PHP?
At this moment I'm only able to create a single payment button in PHP.
Thank you very much! :)
3 Answers
thomascawthorn
22,986 PointsYo! How are you getting on with this?
Stripeot tanulok
33 PointsUntil this moment I've successfully implemented Stripe via PHP, and I also did the subscription part. :) My only problem now, that when I create a custom payment button like this: https://stripe.com/docs/checkout#integration-custom
```<script src="https://checkout.stripe.com/checkout.js"></script>
<button id="customButton">Purchase</button>
<script>
var handler = StripeCheckout.configure({
key: 'pk_test_4SC4KhPwJNWX5o5Qirk0DMji',
image: '/img/documentation/checkout/marketplace.png',
token: function(token) {
// Use the token to create the charge with a server-side script.
// You can access the token ID with token.id
}
});
$('#customButton').on('click', function(e) { // Open Checkout with further options handler.open({ name: 'Demo Site', description: '2 widgets', currency: "eur", amount: 2000 }); e.preventDefault(); });
// Close Checkout on page navigation $(window).on('popstate', function() { handler.close(); }); </script>```
after I did a payment it doesn't redirect me to the charge.php file.
On the other hand this code is now working (but it's not a custom button):
<form action="charge.php" method="post">
<script src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-amount="5000" data-description="One year's subscription"></script>
</form>
Can you help me please, how can I merge these two codes together? So I have a custom payment button and it also redirects me to charge.php?
Thank you :)
Ayat Turar
227 PointsDoes anyone know can the stripe button support several subscription plans ? For example, when user clicks on a stripe button, he can choose several plans to subscribe.
S Alexander
18,962 PointsS Alexander
18,962 PointsHi, Stripeot.
I would start by checking out the Stripe API Reference on creating subscriptions.
With that in mind, we can be more helpful with more info. What have you tried?