A bunch of the comments in stripe.admin.inc module expressed a desire to abstract out some of the necessary elements of the Stripe process. This patch makes a number of changes:
It adds two new functions in stripe.module that take care of the necessary additions to $form:
/**
* Returns the stripe pubkey.
*/
function stripe_get_pubkey()
/**
* Returns an array to add to $form['#attached']['js'].
*
* @param $pubkey
* A Stripe pubkey returned from stripe_get_pubkey().
* @param $selector
* A jQuery (xpath) selector to the <form> tag.
*/
function stripe_attached_js($pubkey, $selector = '.stripe-form')
I made a number of changes to stripe.js so that it works with any generic form that matches $selector (rather than just working for #stripe-admin-test).
It also adds a generic function to process transactions with some basic error logic:
/**
* Process a stripe transaction.
*
* This takes into account all submissions to this webform. The output of this
* function will be displayed under the "Results" tab then "Analysis".
*
* @param $amount
* The transaction amount, in dollars (if the currency is usd).
* @param $token
* The Stripe token from the stripe.js call.
* @param $description
* The transaction description for Stripe.
* @param $error_messages
* BOOL. Should we print error messages"
* @return
* The stripe response, or FALSE if there was an error.
*/
function stripe_transaction($amount, $token, $currency = 'usd', $description = NULL, $error_messages = TRUE)
I used the changes from this patch to build the Stripe Webform module. You can see in work with the changes to stripe.admin.inc in this patch.
Comment | File | Size | Author |
---|---|---|---|
#4 | stripe_form_element-2001856-2.patch | 26.91 KB | mmilano |
#2 | stripe-abstract-api-2.patch | 9.12 KB | jlyon |
#1 | stripe-abstract-api.patch | 9.12 KB | jlyon |
Comments
Comment #1
jlyon CreditAttribution: jlyon commentedHere's the patch.
Comment #2
jlyon CreditAttribution: jlyon commentedForgot to add a * 100 to stripe.js to convert dollars into cents. This patch fixes it.
Comment #3
pbuyle CreditAttribution: pbuyle commentedI dont see the value of the
stripe_transaction()
function or, more generally, of an additional non-standard functional layer on top of the Stripe API. The Stripe API is already simple and complete. To ease key management, the module already provide (now) thestripe_initialize()
function, which could be replaced by a post-load callback if the module use the Libraries module (see #1967094: Integration with the Libraries API).Instead of
stripe_attached_js()
, the Stripe module could implementhook_library
with an rewriten JS Behavior that does not require a JS Setting to detect the form to be processed (as done in my suggested patch for #1971058: Provide payment form element through hook_element_info()).stripe_get_pubkey()
is useful and could be generalized to allow retrieving of both keys from both set (ie. status). Something likeComment #4
mmilano CreditAttribution: mmilano commentedMongolito404's sandbox included the libraries integration and stripe form element support. The libraries integration has been committed, and this is a patch of the extracted form element work that will be going in.
Comment #5
mmilano CreditAttribution: mmilano commentedComment #6
mmilano CreditAttribution: mmilano commentedSorry, had 3 similar issues open.
Comment #6.0
mmilano CreditAttribution: mmilano commentedfix php code