Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stripe
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Extensions
Stripe
Commits
30771385
Commit
30771385
authored
10 years ago
by
Joshua Walker
Browse files
Options
Downloads
Plain Diff
Merge pull request
#61
from Swingline0/js-cleanup
Revised JS logic
parents
cef53da7
0e383545
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/civicrm_stripe.js
+25
-29
25 additions, 29 deletions
js/civicrm_stripe.js
stripe.php
+2
-2
2 additions, 2 deletions
stripe.php
with
27 additions
and
31 deletions
js/civicrm_stripe.js
+
25
−
29
View file @
30771385
...
...
@@ -3,9 +3,11 @@
* JS Integration between CiviCRM & Stripe.
*/
(
function
(
$
)
{
var
$form
,
$submit
,
buttonText
;
// Response from Stripe.createToken.
function
stripeResponseHandler
(
status
,
response
)
{
var
submitButton
=
$
(
"
form.stripe-payment-form input[type='submit']:last
"
);
if
(
response
.
error
)
{
$
(
'
html, body
'
).
animate
({
scrollTop
:
0
},
300
);
// Show the errors on the form.
...
...
@@ -13,22 +15,23 @@
$
(
"
.messages.crm-error.stripe-message
"
).
slideUp
();
$
(
"
.messages.crm-error.stripe-message:first
"
).
remove
();
}
$
(
"
form.
stripe-payment-form
"
).
prepend
(
'
<div class="messages crm-error stripe-message">
'
$form
.
prepend
(
'
<div class="messages crm-error stripe-message">
'
+
'
<strong>Payment Error Response:</strong>
'
+
'
<ul id="errorList">
'
+
'
<li>Error:
'
+
response
.
error
.
message
+
'
</li>
'
+
'
</ul>
'
+
'
</div>
'
);
submitButton
.
prop
(
'
disabled
'
,
false
);
$submit
.
removeAttr
(
'
disabled
'
).
attr
(
'
value
'
,
buttonText
);
}
else
{
var
token
=
response
[
'
id
'
];
// Update form with the token & submit.
$
(
"
input#stripe-token
"
).
val
(
token
);
submitButton
.
prop
(
'
disabled
'
,
false
)
;
$
(
"
form.
stripe-payment-form
"
).
get
(
0
).
submit
();
$
form
.
find
(
"
input#stripe-token
"
).
val
(
token
);
$submit
.
prop
(
'
disabled
'
,
false
);
window
.
onbeforeunload
=
null
;
$form
.
get
(
0
).
submit
();
}
}
...
...
@@ -38,28 +41,21 @@
Stripe
.
setPublishableKey
(
$
(
'
#stripe-pub-key
'
).
val
());
});
/*
* Identify the payment form.
* Don't reference by form#id since it changes between payment pages
* (Contribution / Event / etc).
*/
//Patch - remove direct child selector and account for dialog forms
$
(
'
#billing-payment-block
'
).
closest
(
'
form
'
).
addClass
(
'
stripe-payment-form
'
);
$
(
'
#crm-container form
'
).
addClass
(
'
stripe-payment-form
'
);
if
(
$
(
'
#crm-ajax-dialog-1 form
'
).
length
)
{
$
(
'
#crm-ajax-dialog-1 form
'
).
addClass
(
'
stripe-payment-form
'
);
}
$form
=
$
(
'
form.stripe-payment-form
'
);
$submit
=
$form
.
find
(
'
[type="submit"]
'
);
$submit
.
removeAttr
(
'
onclick
'
);
$
(
"
form.
stripe-payment-form
"
).
unbind
(
'
submit
'
);
$form
.
unbind
(
'
submit
'
);
// Intercept form submission.
$
(
"
form.
stripe-payment-form
"
).
submit
(
function
(
event
)
{
$form
.
submit
(
function
(
event
)
{
event
.
preventDefault
();
event
.
stopPropagation
();
var
$form
=
$
(
this
);
// Disable the submit button to prevent repeated clicks.
$
form
.
find
(
"
input[type='submit']:last
"
).
prop
(
'
disabled
'
,
true
);
// Disable the submit button to prevent repeated clicks, cache button text, restore if Stripe returns error
buttonText
=
$submit
.
attr
(
'
value
'
);
$
submit
.
prop
(
'
disabled
'
,
true
).
attr
(
'
value
'
,
'
Processing
'
);
if
(
$form
.
find
(
"
#priceset input[type='radio']:checked
"
).
data
(
'
amount
'
)
==
0
)
{
return
true
;
...
...
@@ -87,12 +83,12 @@
var
cc_year
=
$form
.
find
(
'
#credit_card_exp_date
\\
[Y
\\
]
'
).
val
();
}
Stripe
.
card
.
createToken
({
name
:
$
(
'
#billing_first_name
'
).
val
()
+
'
'
+
$
(
'
#billing_last_name
'
).
val
(),
address_zip
:
$
(
"
#billing_postal_code-5
"
).
val
(),
number
:
$
(
'
#credit_card_number
'
).
val
(),
cvc
:
$
(
'
#cvv2
'
).
val
(),
exp_month
:
cc_month
,
exp_year
:
cc_year
name
:
$form
.
find
(
'
#billing_first_name
'
).
val
()
+
'
'
+
$
form
.
find
(
'
#billing_last_name
'
).
val
(),
address_zip
:
$
form
.
find
(
'
#billing_postal_code-5
'
).
val
(),
number
:
$form
.
find
(
'
#credit_card_number
'
).
val
(),
cvc
:
$form
.
find
(
'
#cvv2
'
).
val
(),
exp_month
:
cc_month
,
exp_year
:
cc_year
},
stripeResponseHandler
);
return
false
;
...
...
This diff is collapsed.
Click to expand it.
stripe.php
+
2
−
2
View file @
30771385
...
...
@@ -119,12 +119,11 @@ function stripe_civicrm_buildForm($formName, &$form) {
&&
$form
->
_paymentProcessor
[
'payment_processor_type'
]
==
'Stripe'
)
{
if
(
!
stristr
(
$formName
,
'_Confirm'
)
&&
!
stristr
(
$formName
,
'_ThankYou'
))
{
//if (empty($_GET['type'])) {
if
(
!
isset
(
$form
->
_elementIndex
[
'stripe_token'
]))
{
$form
->
_attributes
[
'class'
]
.
=
" stripe-payment-form"
;
$form
->
addElement
(
'hidden'
,
'stripe_token'
,
NULL
,
array
(
'id'
=>
'stripe-token'
));
stripe_add_stripe_js
(
$form
);
}
//}
}
}
...
...
@@ -136,6 +135,7 @@ function stripe_civicrm_buildForm($formName, &$form) {
);
if
(
in_array
(
$formName
,
$backendForms
)
&&
!
empty
(
$form
->
_processors
))
{
if
(
!
isset
(
$form
->
_elementIndex
[
'stripe_token'
]))
{
$form
->
_attributes
[
'class'
]
.
=
" stripe-payment-form"
;
$form
->
addElement
(
'hidden'
,
'stripe_token'
,
NULL
,
array
(
'id'
=>
'stripe-token'
));
stripe_add_stripe_js
(
$form
);
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment