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 trialJ.C. Hiatt
9,393 Points404 Error When Executing Stripe Payment PHP Script
Hello,
I've been attempting to integrate Stripe Checkout into a custom WordPress theme for a client. However, when the 'Pay' button is clicked, I get a 404 page for /charge.php. Ive been following along the guide in Stripe's documentation here: https://stripe.com/docs/checkout/guides/php
This is my current code:
At the top of my header.php file:
<?php require_once('config.php'); ?>
Custom Modal code
<div class="modal" id="download-modal">
<div class="close-button" data-icon=""></div>
<h2>Purchase</h2>
<form id="download">
<div class="download-amount">
<h6>Choose any amount of money in USD</h6>
<div class="download-amount-options">
<input type="radio" id="a1" name="value" value="100">
<label>$100</label>
<input type="radio" id="a2" name="value" value="50">
<label>$50</label>
<input type="radio" id="a3" name="value" value="25" checked>
<label>$25</label>
<input type="radio" id="a4" name="value" value="10">
<label>$10</label>
</div><!-- // .download-amount-options -->
</div><!-- // .download-amount -->
<div class="download-divide">
<h6>Choose how you would like to divide up the amount</h6>
<ul class="split-options">
<li class="selected">Default split</li>
<li>All to charity</li>
<li>All to artist</li>
<li>Customize</li>
</ul><!-- // .split-options -->
<div class="slider-container">
<div class="slider-title">Charity</div>
<div class="slider-charity slider"></div>
<div class="slider-value-charity slider-value">$0.00</div>
</div><!-- // .slider-container -->
<div class="slider-container">
<div class="slider-title">Artist</div>
<div class="slider-artist slider"></div>
<div class="slider-value-artist slider-value">$0.00</div>
</div><!-- // .slider-container -->
<div class="slider-container">
<div class="slider-title">IndieBundles</div>
<div class="slider-ib slider"></div>
<div class="slider-value-ib slider-value">$0.00</div>
</div><!-- // .slider-container -->
</div><!-- // .download-divide -->
<div class="download-email">
<h6>Enter your email address</h6>
<input type="text" id="download-email" placeholder="example@gmail.com">
<input type="checkbox" id="download-notify">
<label id="download-notify-label">Sign me up for the newsletter</label>
<!-- Change this area if logged in for faster checkout? -->
</div><!-- // .download-email -->
<div class="download-promo">
<h6>Promo Code</h6>
<input type="text" id="download-promocode" placeholder="0000">
</div><!-- // .download-promo -->
<!-- <button type="submit" value="Submit" name="signup-submit" class="pay-button">Pay</button>
--> </form><!-- // #download -->
<form action="charge.php" method="POST">
<script src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
data-key="<?php echo $stripe['publishable_key']; ?>"
data-amount="5000" data-description="One year's subscription"></script>
</form>
</div><!-- // #download-modal -->
7 Answers
Zac Gordon
Treehouse Guest TeacherTwo more thoughts:
- If you write this as a plugin it will be easier to call the functions you want.
- Try checking out the code in this plugin: http://wordpress.org/plugins/wp-stripe. It's pretty clean and clear
Hope that helps!
Andy Crofford
9,959 PointsWhere is charge.php in relation to the config file?
You may try:
<form action="/charge.php" methos="POST">
J.C. Hiatt
9,393 PointsIt's being referenced properly.. I think this has something to do with WordPress and the .htaccess file. I think Zac Gordon should check this out. :)
Zac Gordon
Treehouse Guest TeacherTry the following and see if it makes a difference.
- Turn off pretty URL in permalinks
- Place the charge.php file in the root directory
Possibly not a final solution, but could help with troubleshooting.
Zac Gordon
Treehouse Guest TeacherThe permalinks change allows WordPress to access non WordPress files.
Template files are reserved f
Zac Gordon
Treehouse Guest TeacherTemplate files are reserved for actual template files and programmatic files are general migrated into the functions.php file.
If you have to get it done ASAP I would suggest using a Stripe plugin.
J.C. Hiatt
9,393 PointsWP Stripe did not work. At this point I am willing to pay someone to get Stripe working for this website.
Zac Gordon
Treehouse Guest TeacherHey man,
Sorry this isn't working for you :-/ are there some other plugins that might solve the solution for you in time? Let us know how it goes!
Isaac Henry
15,541 Pointszack gorden im stuck
J.C. Hiatt
9,393 PointsJ.C. Hiatt
9,393 PointsHey Zac Gordon,
Your suggestion to turn off permalinks and move the files to the root of the website worked. Why is that?
Also, I'm very new to developing for WordPress (I've done everything for this project based on watching your videos), so I'm not sure if I am capable of developing a plugin...however, this project has to be done today and I have been trying for 5 days to get Stripe to work with this website.
Do you have any pointers or suggestions of anything I can read that will help me get Stripe working ASAP?
Thanks! J.C.