Stripe app: custom charge handler and webhooks handler

Comments

The custom charge handler gets notified by the Stripe app when a charge has been made, so you can act on the charge itself (e.g., deliver the goods). It receives a Stripe_Charge object with this info, as well as a stripe\Payment object which is an Elefant model.

The webhooks handler gets passed event notifications that Stripe sends for any account activity, which can include other actions like refunds, new account creations, subscription payment failures, etc. This receives a more general Stripe_Event object instead.

Thanks. Do you have suggestions for how to test the charge handler? We can test the webhooks handler from the stripe control panel, which sends a sample event. Is there a way to do the same for the charge handler?

Also, in the readme file there is this code for a sample subscription form:

Technically, you could implement some of the same logic in the webhooks handler, since it receives events for all of these too, except that it happens outside of the current request. So things like sending a confirmation email will work fine, but responding to the current user will not be possible there.

The charge handler is actually just tied to the stripe/button handler, so it doesn't get called when you implement your own handler with stripe/payment. The embeddable button is okay for simple tasks, but generally I find I use stripe/payment and a custom callback for anything more complex.

Thanks. Another question: is there a flag in either the $customer or $payment object that indicates success or failure?

Or more broadly, what's the best way to implement error handling? For instance, if I put in an expiration year of, say, 2013, the app handles it nicely by reloading the form with the message that "Your card's expiration year is invalid" However, if I use the credit card number that stripe has designated for testing "card declined" responses, the form doesn't reload and just gives the message "Unable to save customer info at this time. Please try again later. " The error log does report "Error calling Stripe_Customer::create(): Your card was declined" but the form doesn't reload or give a helpful message to the customer.

It looks like error handling could be improved, to be honest. Right now it just returns the error you see. A better approach would probably be to pass an 'error' parameter as an additional callback, and only fall back on the default handling that's there now if no 'error' parameter is set.

I like the way the form displays the error messages for, e.g., invalid expiration year. How would I go about getting it to display the other messages (like "credit card declined"). I'm looking through handlers/payment.php but I don't see where they're handled differently.

Those messages are returned from Stripe.createToken in js/payment.js. For the handler to display an error message like that, you would have to set an error parameter and re-render the form. On line 180 you could try this:

When the form reloads with a createToken error the fields remain filled in. Would it be a security risk (or are there other reasons not) to add, e.g., name="cc_number" value="{{ cc_number }}" to the input fields in the view?