-
-
Save bkrausz/a76f9d7a9b446337d470 to your computer and use it in GitHub Desktop.
// Please see https://stripe.com/docs/checkout/php for updated code examples |
Why is this all hard coded? Why isn't there any error handling for declined cards? This is very misleading...
For those of you looking for something with some error handling for declined cards just surround it in a try catch...
try {
\Stripe\Stripe::setApiKey("....");
// Charge the user's card:
$charge = \Stripe\Charge::create(array(
"amount" => $Request->Get('amount'),
"currency" => "usd",
"description" => $Request->Get('description'),
"source" => $Request->Get('charge_id'),
));
} catch (Exception $e) {
//TODO: Error Handeling logic.
}
Someone at Stripe should update the charge.php source code and then reply to the comments.
- Add Error handling
- Change $5 to $50
- Use 'email' => $_POST['stripeEmail'], instead of 'email' => 'customer@example.com',
I added the following to charge.php to help show what was returned:
echo "post: <pre>"; print_r($_POST) ; echo "</pre>";
echo "customer: <pre>"; print_r($customer) ; echo "</pre>";
echo "charge: <pre>"; print_r($charge) ; echo "</pre>";
The documentation for config.php should be changed to show that you can use init.php instead of autoload.php for those that don't use or know how to use composer.
The piece of code:
$customer = \Stripe\Customer::create(array(
'email' => 'customer@example.com',
should actually be:
$customer = \Stripe\Customer::create(array(
'email' => $_POST['stripeEmail'],
as that is the same email as submitted by the customer, and gets posted back with "stripeToken" and "stripeTokenType".
Someone needs to update the example. Having problems with the charge amount this does NOT work. I have tried both, what is the element name to capture?
$charge = \Stripe\Charge::create(array( 'customer' => $customer->id, 'amount' => $_POST['stripeAmount'] or $_POST['data-amount'], 'currency' => 'usd' ));
This example does not work! 'card' is the wrong parameter, it should be 'source'
inside charge.php:
this:
$customer = \Stripe\Customer::create(array(
'email' => 'customer@example.com',
'card' => $token
));
should be:
$customer = \Stripe\Customer::create(array(
'email' => 'customer@example.com',
'source' => $token
));
I am getting this error {"error":"No such token: card_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx(invalid_request_error)"}
Hi Stripe Bitcoin team,
I need to charge the amount that varies dynamically each time how to manage that data-amount="5000"
<script
src="https://checkout.stripe.com/checkout.js" class="stripe-button"
data-key="<?php echo $stripe_code['publishable_key']; ?>"
data-amount="<?php echo $price; ?>"
data-name="OfficeBnb"
data-description="2 widgets (<?php echo $this->session->userdata('currency_s').($price); ?>) Cents"
data-image="images/logo/<?php echo $this->config->item('logo_image');?>"
data-label="Pay with Card or Bitcoin"
data-locale="auto"
data-currency="<?php echo $this->session->userdata('currency_type'); ?>"
data-bitcoin="true">
</script>
Same comment as @Bhlowe back in April ... updates to the examples are overdue.
Same comment as @JoysonAnto needs to be an option to get a variable amount. Can't use this with a store -- unless attached directly to products that can only be purchased individually at a set price.
Same for the Requirement to add "Composer" ..."assumes you’ve installed the Stripe PHP library via Composer. ..." which also assumes quite a bit.
For what is touted as "super simple" the implementation seems to be much more complicated than it should need to be. Granted, I'm not an expert, my skills are ok. For those of us who might want to use Stripe but don't live and breathe code every day the claim of "as little as one line of client side code" is seriously misleading. There's quite a bit more required to implement than "one line of client side code."
This is really awesome. Straight to the point. I love it.
How can I get the confirmation number or transaction number of the payment ?
5000 cents is $50. The commenter mspivak pointed out that on the last line in charge.php it says $5, not $50. This was apparently misunderstood by subsequent commenters, who got it turned around. And the incorrect amount is still there as "Successfully charged $5" in the charge.php example.