Reputation: 729
I am trying to implement payment through stripe and i had it working a few weeks ago but now it doesn't seem to work.
I'm using php to implement:
payment.php
require('stripe/lib/Stripe.php');
$stripe = array(
'secret_key' => 'sk_test_???',
'publishable_key' => 'pk_test_???'
);
Stripe::setApiKey($stripe['secret_key']);
try{
$customer = Stripe_Customer::create(array(
'card' => $_POST['stripeToken'],
'email' => $_POST['email'],
'name' => $_POST['name']
));
$charge = Stripe_Charge::create(array(
'card' => $_POST['stripeToken'],
'amount' => 2500,
'currency' => 'usd',
"description" => "Charge for ..."
));
} catch (Stripe_ApiConnectionError $e) {
$errors[] = 'Network problem, perhaps try again.';
} catch (Stripe_InvalidRequestError $e) {
$errors[] = 'You screwed up in your programming. Shouldnt happen!';
} catch (Stripe_ApiError $e) {
$errors[] = 'Stripe servers are down!';
} catch (Stripe_CardError $e) {
$errors[] = 'Card was declined.';
}
echo "<p>You have paid!</p>";
register.php
<form id="payment-form" action="" method="POST">
<script
src="https://checkout.stripe.com/v2/checkout.js" class="stripe-button"
data-key="pk_test_???"
data-amount="2500"
data-name="Purtrainer"
data-description="Monthly Subscription ($25.00)"
</script>
<div id="payment-errors">
<? print_r($errors); ?>
</div>
</form>
In register.php i have a few text inputs for email, name, password, etc...
When i click the "pay with card" button stripe provides in the js code and i will in the test credit card info, my user gets inputted into my database with al the info from the text inputs, but Strip neither creates the customer nor the charge.
Any help?
Something else to note - going to my payment.php file directly in the URL gives me an error saying there was a problem requiring the stripe file. It says no file exists, even though it does :)
Upvotes: 2
Views: 3589
Reputation: 316
A few things come to mind:
The action of the form in register.php is local, no to payment.php.
data-key="pk_test_???"
should be $stripe['publishable_key']
As mentioned in the comments SSL is required in live mode, but not in test mode.
Check the permissions on all of the files recursively, for testing chmod -R 777 /path/to/stripe
would be a solid test.
Download a fresh copy of the stripe PHP api files.
Upvotes: 3