#stripe

/

      • khuntley has quit
      • Meowtown
        okay I think i'm close
      • khuntley joined the channel
      • codergeek joined the channel
      • khuntley has quit
      • is there an easy to pass the charge amount?
      • tokenid: token.id, email: token.email, pass just fine
      • tr12
        Meowtown: generally, you want to calculate the charge amount on your server
      • unless you explicitly want the client to be able to pick their own price
      • Meowtown
        well
      • tr12
        ie: you don't care if they tamper with the form parameters, since they're allowed to pick them anyway
      • Meowtown
        hm yeah
      • Cognit has quit
      • it'd be nice if i could pull the charge mount from the click function that launches the checkout form
      • name: 'Stripe.com',
      • description: '2 widgets',
      • amount: 2000
      • tr12
        you can do this, by setting amount in whatever form post thing you're doing to submit the stripeToken
      • unless you're talking about how to feed the value through to the callback?
      • generally, the way to do that would be to define the callback function at the callsite, so the `amount` variable you're using when you call `open` is in-scope
      • codergeek has quit
      • Meowtown
        well
      • he's getting $donation = $_POST['donationAmt'];
      • stuwest has quit
      • T1m0thy joined the channel
      • however, i'm not sure what donationAmt vs just a regular charge amount would be
      • tr12
        to be explicit, though: do you want the client to be able to pick their own price?
      • or donation amount, or whatever?
      • Meowtown
        i'm not doing donations, and no, just based on the the custom stripe checkout defines
      • tr12
        if you don't want the client to be able to pick their own price, you need to calculate the value on the server
      • Meowtown
        $('.button-credit-card').on('click', function(e) {
      • // Open Checkout with further options:
      • handler.open({
      • name: 'redacted',
      • description: 'redacted',
      • allowRememberMe: false,
      • currency: "USD",
      • amount: 2000
      • });
      • e.preventDefault();
      • });
      • tr12
        if you get the price from a parameter passed from the client, the client can pass whatever they want
      • (to be clear, the `amount` parameter in checkout is just for display)
      • Meowtown
        ahh
      • tr12
        it doesn't actually control the amount charged
      • Meowtown
        i see
      • tr12
        the point of truth for *that* is the `amount` parameter that you pass when you actually create the charge
      • Meowtown
        alright
      • and I suppose I shouldn't use that amount because someone could just change it to a dollar and still get the success charge result
      • tr12
        the amount on the client side? yes
      • Meowtown
        makes sense
      • tr12
        if you're reading in a request parameter sent to your server, and taking that as the amount, the amount is fundamentally user-controlled
      • khuntley joined the channel
      • khuntley has quit
      • greengob2 has quit
      • V28 joined the channel
      • khuntley joined the channel
      • ftknox joined the channel
      • Meowtown
        right
      • okay, i've got a fixed amount
      • seems something's actually happening
      • specifically referring to that stackoverflow answer again, are you familiar with what the console.log("Success Error!"); is actually referring too?
      • i used a test card of 4242 4242 4242 4242 so I believe it should have charged successfully
      • V28 has quit
      • tr12
        that's somewhat confusingly named, but I assume that the expectation is that the response from the server ought to be just the text "success" if it works
      • and then if it's not that, it means that you were able to talk to your server, and your server wasn't able to make the charge
      • "success error" isn't the best name for this condition :P
      • tbh, the error handling here isn't fantastic, since it lumps any sort of failure into the same case
      • Digitalbil joined the channel
      • Meowtown
        yeah
      • tr12
        whereas in a real production app, you'll probably want to distinguish between a card error, and something else going totally off the rails
      • Meowtown
        well, it's going to be a production app
      • however, I don't have the means to really do anything better
      • adrian joined the channel
      • again, I'm not a php developer, strictly frontend
      • adrian is now known as Guest88447
      • so to confirm, that charge for some reason didn't work, correct?
      • Guest88447 has quit
      • tr12
        Meowtown: what are you seeing in the dashboard logs?
      • Meowtown
        nada
      • tr12
        (yes, if you created a charge with the 4242 card, it should have worked)
      • designer1234556 joined the channel
      • anything in the php error log?
      • designer1234556
        is there documentation anywere about customising the css for the stripe-button
      • koopajah has quit
      • tr12
        designer1234556: to do that, you'd use the custom checkout integration, then provide your own button to use to open the modal
      • Meowtown
        or you can just use css and target the elements
      • it's not an iframe, so regular css works on it
      • tr12
        sure, though this is not documented, or considered part of the public api
      • so it's possible that the way the css styling is done for the simple button changes at some point, and breaks your own styling rules that apply to the button
      • Meowtown
        true
      • designer1234556
        id prefer not to be overiding styles
      • tr12
        it's safer to just provide your own button
      • designer1234556
        ok thanks for that
      • tr12
        yw!
      • designer1234556 has quit
      • Meowtown
        i can't find any php error logs
      • s3shs has quit
      • tr12
        Meowtown: you may need to enable php error logging on your server: https://stackoverflow.com/questions/845021/how-...
      • cdbattags has quit
      • ftknox has quit
      • Meowtown
        alright
      • Fatal error: Class 'Stripe' not found in /home/simplewhmcs/public_html/php/charge.php on line 9
      • tr12
        how are you including the stripe lib, and what does your code look like?
      • stuwest joined the channel
      • ugh
      • so, that SO post is pretty old, and uses a pretty old version of the stripe-php lib
      • stuwest is now known as stuwest-away
      • stuwest-away is now known as stuwest
      • Meowtown
      • Meld052015 has quit
      • tr12
        yeah, so the modern equivalents for those calls are:
      • \Stripe\Stripe::setApiKey(...)
      • \Stripe\Charge::create(...)
      • \Stripe\Error\Card
      • that code is for stripe-php 1.x.x, whereas the current version of stripe-php is 3.14.1
      • Meld052015 joined the channel
      • Meld052015 has quit
      • Meowtown
        okay
      • lemme give that a shot
      • that look right to you?
      • tr12
        this looks correct, yeah
      • Meowtown
        alright i'll try a charge, fingers crossed
      • shucks
      • Parse error: syntax error, unexpected 'Stripe' (T_STRING) in /home/simplewhmcs/public_html/php/charge.php on line 7
      • tr12
        ah, you're missing a semicolon after the require_once
      • Meowtown
        herp
      • i need sleep
      • okay, this one's weird
      • Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW) in /home/simplewhmcs/public_html/php/charge.php on line 16
      • edrocks joined the channel
      • tr12
        ah
      • that ought to be create(array("amount" => 2000, ...))
      • Meowtown
        it's alive! :D
      • thanks so much for your help man
      • edrocks has quit
      • tr12
        ah nice!
      • np!
      • Meowtown
        just out of curiosity, is there anything I could easily add to that charge.php to better handle errors or is that a major undertaking
      • tr12
        usually what I like to do is return json from an internal api like this
      • not just unformatted text
      • levubn joined the channel
      • so like json_encode(array("error_type" => $error_type, "message" => $msg));
      • levubn
        Hi
      • Meowtown
        right
      • that makes sense