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
4a34ffa5
Commit
4a34ffa5
authored
4 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Improve user notifications during pre-authentication and confirmation
parent
d5a50f88
No related branches found
No related tags found
1 merge request
!114
6.4.1
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CRM/Stripe/AJAX.php
+9
-1
9 additions, 1 deletion
CRM/Stripe/AJAX.php
js/civicrmStripeConfirm.js
+36
-4
36 additions, 4 deletions
js/civicrmStripeConfirm.js
js/civicrm_stripe.js
+28
-29
28 additions, 29 deletions
js/civicrm_stripe.js
with
73 additions
and
34 deletions
CRM/Stripe/AJAX.php
+
9
−
1
View file @
4a34ffa5
...
...
@@ -9,6 +9,8 @@
+--------------------------------------------------------------------+
*/
use
CRM_Stripe_ExtensionUtil
as
E
;
/**
* Class CRM_Stripe_AJAX
*/
...
...
@@ -154,7 +156,13 @@ class CRM_Stripe_AJAX {
}
else
{
// Invalid status
CRM_Utils_JSON
::
output
([
'error'
=>
[
'message'
=>
'Invalid PaymentIntent status: '
.
$intent
->
status
]]);
if
(
isset
(
$intent
->
last_payment_error
->
message
))
{
$message
=
E
::
ts
(
'Payment failed: %1'
,
[
1
=>
$intent
->
last_payment_error
->
message
]);
}
else
{
$message
=
E
::
ts
(
'Payment failed.'
);
}
CRM_Utils_JSON
::
output
([
'error'
=>
[
'message'
=>
$message
]]);
}
}
...
...
This diff is collapsed.
Click to expand it.
js/civicrmStripeConfirm.js
+
36
−
4
View file @
4a34ffa5
...
...
@@ -14,6 +14,10 @@
if
(
result
.
error
)
{
// Show error from server on payment form
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
result
.
error
.
message
);
confirm
.
swalFire
({
title
:
result
.
error
.
message
,
icon
:
'
error
'
,
});
}
else
if
(
result
.
requires_action
)
{
...
...
@@ -23,6 +27,10 @@
else
{
// All good, nothing more to do
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
success - payment captured
'
);
confirm
.
swalFire
({
title
:
'
Payment successful
'
,
icon
:
'
success
'
,
});
}
},
...
...
@@ -62,6 +70,13 @@
handleCardConfirm
:
function
()
{
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
handle card confirm
'
);
confirm
.
swalFire
({
title
:
'
Please wait...
'
,
allowOutsideClick
:
false
,
onBeforeOpen
:
()
=>
{
Swal
.
showLoading
();
},
});
// Send paymentMethod.id to server
var
url
=
CRM
.
url
(
'
civicrm/stripe/confirm-payment
'
);
$
.
post
(
url
,
{
...
...
@@ -70,10 +85,15 @@
id
:
CRM
.
vars
.
stripe
.
id
,
description
:
document
.
title
,
csrfToken
:
CRM
.
vars
.
stripe
.
csrfToken
,
}).
then
(
function
(
result
)
{
// Handle server response (see Step 3)
confirm
.
handleServerResponse
(
result
);
});
})
.
done
(
function
(
result
)
{
confirm
.
swalClose
();
// Handle server response (see Step 3)
confirm
.
handleServerResponse
(
result
);
})
.
fail
(
function
()
{
confirm
.
swalClose
();
});
},
checkAndLoad
:
function
()
{
...
...
@@ -103,6 +123,18 @@
});
}
},
swalFire
:
function
(
parameters
)
{
if
(
typeof
Swal
===
'
function
'
)
{
Swal
.
fire
(
parameters
);
}
},
swalClose
:
function
()
{
if
(
typeof
Swal
===
'
function
'
)
{
Swal
.
close
();
}
}
};
if
(
typeof
CRM
.
payment
===
'
undefined
'
)
{
...
...
This diff is collapsed.
Click to expand it.
js/civicrm_stripe.js
+
28
−
29
View file @
4a34ffa5
...
...
@@ -86,7 +86,7 @@ CRM.$(function($) {
var
errorElement
=
document
.
getElementById
(
'
card-errors
'
);
errorElement
.
style
.
display
=
'
block
'
;
errorElement
.
textContent
=
errorMessage
;
form
.
dataset
.
submitted
=
false
;
form
.
dataset
.
submitted
=
'
false
'
;
if
(
typeof
submitButtons
!==
'
undefined
'
)
{
for
(
i
=
0
;
i
<
submitButtons
.
length
;
++
i
)
{
submitButtons
[
i
].
removeAttribute
(
'
disabled
'
);
...
...
@@ -152,6 +152,14 @@ CRM.$(function($) {
}
else
{
// Send paymentMethod.id to server
debugging
(
'
Waiting for pre-auth
'
);
Swal
.
fire
({
title
:
'
Please wait while we pre-authorize your card...
'
,
allowOutsideClick
:
false
,
onBeforeOpen
:
()
=>
{
Swal
.
showLoading
();
},
});
var
url
=
CRM
.
url
(
'
civicrm/stripe/confirm-payment
'
);
$
.
post
(
url
,
{
payment_method_id
:
result
.
paymentMethod
.
id
,
...
...
@@ -160,10 +168,14 @@ CRM.$(function($) {
id
:
CRM
.
vars
.
stripe
.
id
,
description
:
document
.
title
,
csrfToken
:
CRM
.
vars
.
stripe
.
csrfToken
,
}).
then
(
function
(
result
)
{
// Handle server response (see Step 3)
handleServerResponse
(
result
);
});
})
.
done
(
function
(
result
)
{
// Handle server response (see Step 3)
handleServerResponse
(
result
);
})
.
always
(
function
()
{
Swal
.
close
();
});
}
}
});
...
...
@@ -270,6 +282,7 @@ CRM.$(function($) {
dataType
:
'
script
'
,
cache
:
true
,
timeout
:
5000
,
crossDomain
:
true
,
})
.
done
(
function
(
data
)
{
stripeLoading
=
false
;
...
...
@@ -352,7 +365,7 @@ CRM.$(function($) {
// If another submit button on the form is pressed (eg. apply discount)
// add a flag that we can set to stop payment submission
form
.
dataset
.
submitdontprocess
=
false
;
form
.
dataset
.
submitdontprocess
=
'
false
'
;
// Find submit buttons which should not submit payment
var
nonPaymentSubmitButtons
=
form
.
querySelectorAll
(
'
[type="submit"][formnovalidate="1"],
'
+
...
...
@@ -365,7 +378,7 @@ CRM.$(function($) {
function
submitDontProcess
()
{
debugging
(
'
adding submitdontprocess
'
);
form
.
dataset
.
submitdontprocess
=
true
;
form
.
dataset
.
submitdontprocess
=
'
true
'
;
}
for
(
i
=
0
;
i
<
submitButtons
.
length
;
++
i
)
{
...
...
@@ -373,17 +386,13 @@ CRM.$(function($) {
}
function
submitButtonClick
(
event
)
{
if
(
form
.
dataset
.
submitted
===
true
)
{
return
;
}
form
.
dataset
.
submitted
=
true
;
// Take over the click function of the form.
if
(
typeof
CRM
.
vars
.
stripe
===
'
undefined
'
)
{
// Submit the form
return
nonStripeSubmit
();
}
debugging
(
'
clearing submitdontprocess
'
);
form
.
dataset
.
submitdontprocess
=
false
;
form
.
dataset
.
submitdontprocess
=
'
false
'
;
// Run through our own submit, that executes Stripe submission if
// appropriate for this submit.
...
...
@@ -420,6 +429,11 @@ CRM.$(function($) {
event
.
preventDefault
();
debugging
(
'
submit handler
'
);
if
(
form
.
dataset
.
submitted
===
'
true
'
)
{
return
;
}
form
.
dataset
.
submitted
=
'
true
'
;
if
((
$
(
form
).
valid
()
===
false
)
||
$
(
form
).
data
(
'
crmBillingFormValid
'
)
===
false
)
{
debugging
(
'
Form not valid
'
);
$
(
'
div#card-errors
'
).
hide
();
...
...
@@ -462,11 +476,6 @@ CRM.$(function($) {
return
true
;
}
if
(
form
.
dataset
.
submitted
===
true
)
{
debugging
(
'
form already submitted
'
);
return
false
;
}
var
stripeProcessorId
=
parseInt
(
CRM
.
vars
.
stripe
.
id
);
var
chosenProcessorId
=
null
;
...
...
@@ -510,7 +519,7 @@ CRM.$(function($) {
return
true
;
}
// Don't handle submits generated by the CiviDiscount button.
if
(
form
.
dataset
.
submitdontprocess
===
true
)
{
if
(
form
.
dataset
.
submitdontprocess
===
'
true
'
)
{
debugging
(
'
non-payment submit detected - not submitting payment
'
);
return
true
;
}
...
...
@@ -538,16 +547,6 @@ CRM.$(function($) {
return
nonStripeSubmit
();
}
// Lock to prevent multiple submissions
if
(
form
.
dataset
.
submitted
===
true
)
{
// Previously submitted - don't submit again
alert
(
'
Form already submitted. Please wait.
'
);
return
false
;
}
else
{
// Mark it so that the next submit can be ignored
form
.
dataset
.
submitted
=
true
;
}
// Disable the submit button to prevent repeated clicks
for
(
i
=
0
;
i
<
submitButtons
.
length
;
++
i
)
{
submitButtons
[
i
].
setAttribute
(
'
disabled
'
,
true
);
...
...
@@ -723,7 +722,7 @@ CRM.$(function($) {
if
(
event
.
code
===
'
Enter
'
)
{
event
.
preventDefault
();
debugging
(
'
adding submitdontprocess
'
);
form
.
dataset
.
submitdontprocess
=
true
;
form
.
dataset
.
submitdontprocess
=
'
true
'
;
}
};
...
...
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