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
e465606c
Commit
e465606c
authored
4 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Refactor civicrmStripeConfirm.js to exist at CRM.payment.stripeConfirm
parent
35eadf83
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!114
6.4.1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
js/civicrmStripeConfirm.js
+106
-99
106 additions, 99 deletions
js/civicrmStripeConfirm.js
stripe.php
+1
-1
1 addition, 1 deletion
stripe.php
with
107 additions
and
100 deletions
js/civicrmStripeConfirm.js
+
106
−
99
View file @
e465606c
/**
/**
* This handles confirmation actions on the "Thankyou" pages for contribution/event workflows.
* This handles confirmation actions on the "Thankyou" pages for
* contribution/event workflows.
*/
*/
CRM
.
$
(
function
(
$
)
{
(
function
(
$
,
CRM
,
_
,
undefined
)
{
debugging
(
"
civicrmStripeConfirm loaded
"
);
if
(
typeof
CRM
.
vars
.
stripe
===
'
undefined
'
)
{
var
confirm
=
{
debugging
(
'
CRM.vars.stripe not defined! Not a Stripe processor?
'
);
scriptName
:
'
stripeconfirm
'
,
return
;
stripe
:
null
,
}
stripeLoading
:
false
,
switch
(
CRM
.
vars
.
stripe
.
paymentIntentStatus
)
{
case
'
succeeded
'
:
case
'
cancelled
'
:
debugging
(
'
paymentIntent:
'
+
CRM
.
vars
.
stripe
.
paymentIntentStatus
);
return
;
}
checkAndLoad
();
handleServerResponse
:
function
(
result
)
{
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
handleServerResponse
'
);
if
(
result
.
error
)
{
// Show error from server on payment form
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
result
.
error
.
message
);
}
else
if
(
result
.
requires_action
)
{
// Use Stripe.js to handle required card action
confirm
.
handleAction
(
result
);
}
else
{
// All good, nothing more to do
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
success - payment captured
'
);
}
},
if
(
typeof
stripe
===
'
undefined
'
)
{
handleAction
:
function
(
response
)
{
stripe
=
Stripe
(
CRM
.
vars
.
stripe
.
publishableKey
);
switch
(
CRM
.
vars
.
stripe
.
paymentIntentMethod
)
{
}
case
'
automatic
'
:
confirm
.
stripe
.
handleCardPayment
(
response
.
payment_intent_client_secret
)
.
then
(
function
(
result
)
{
if
(
result
.
error
)
{
// Show error in payment form
confirm
.
handleCardConfirm
();
}
else
{
// The card action has been handled
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
card payment success
'
);
confirm
.
handleCardConfirm
();
}
});
break
;
handleCardConfirm
();
case
'
manual
'
:
confirm
.
stripe
.
handleCardAction
(
response
.
payment_intent_client_secret
)
.
then
(
function
(
result
)
{
if
(
result
.
error
)
{
// Show error in payment form
confirm
.
handleCardConfirm
();
}
else
{
// The card action has been handled
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
card action success
'
);
confirm
.
handleCardConfirm
();
}
});
break
;
}
},
// On initial load...
handleCardConfirm
:
function
()
{
var
stripe
;
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
handle card confirm
'
);
var
stripeLoading
=
false
;
// Send paymentMethod.id to server
var
url
=
CRM
.
url
(
'
civicrm/stripe/confirm-payment
'
);
$
.
post
(
url
,
{
payment_intent_id
:
CRM
.
vars
.
stripe
.
paymentIntentID
,
capture
:
true
,
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
);
});
},
// Disable the browser "Leave Page Alert" which is triggered because we mess with the form submit function.
checkAndLoad
:
function
()
{
window
.
onbeforeunload
=
null
;
if
(
typeof
Stripe
===
'
undefined
'
)
{
if
(
confirm
.
stripeLoading
)
{
return
;
}
confirm
.
stripeLoading
=
true
;
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
Stripe.js is not loaded!
'
);
function
handleServerResponse
(
result
)
{
$
.
getScript
(
"
https://js.stripe.com/v3
"
,
function
()
{
debugging
(
'
handleServerResponse
'
);
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
Script loaded and executed.
'
);
if
(
result
.
error
)
{
confirm
.
stripeLoading
=
false
;
// Show error from server on payment form
// displayError(result);
}
else
if
(
result
.
requires_action
)
{
// Use Stripe.js to handle required card action
handleAction
(
result
);
}
else
{
// All good, nothing more to do
debugging
(
'
success - payment captured
'
);
}
}
function
handleAction
(
response
)
{
if
(
confirm
.
stripe
===
null
)
{
switch
(
CRM
.
vars
.
stripe
.
paymentIntentMethod
)
{
confirm
.
stripe
=
Stripe
(
CRM
.
vars
.
stripe
.
publishableKey
);
case
'
automatic
'
:
}
stripe
.
handleCardPayment
(
response
.
payment_intent_client_secret
)
});
.
then
(
function
(
result
)
{
}
if
(
result
.
error
)
{
},
// Show error in payment form
};
handleCardConfirm
();
}
else
{
// The card action has been handled
debugging
(
'
card payment success
'
);
handleCardConfirm
();
}
});
break
;
case
'
manual
'
:
if
(
typeof
CRM
.
payment
===
'
undefined
'
)
{
stripe
.
handleCardAction
(
response
.
payment_intent_client_secret
)
CRM
.
payment
=
{};
.
then
(
function
(
result
)
{
if
(
result
.
error
)
{
// Show error in payment form
handleCardConfirm
();
}
else
{
// The card action has been handled
debugging
(
'
card action success
'
);
handleCardConfirm
();
}
});
break
;
}
}
}
function
handleCardConfirm
()
{
CRM
.
payment
.
stripeConfirm
=
confirm
;
debugging
(
'
handle card confirm
'
);
// Send paymentMethod.id to server
var
url
=
CRM
.
url
(
'
civicrm/stripe/confirm-payment
'
);
$
.
post
(
url
,
{
payment_intent_id
:
CRM
.
vars
.
stripe
.
paymentIntentID
,
capture
:
true
,
id
:
CRM
.
vars
.
stripe
.
id
,
}).
then
(
function
(
result
)
{
// Handle server response (see Step 3)
handleServerResponse
(
result
);
});
}
function
checkAndLoad
()
{
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
civicrmStripeConfirm loaded
'
);
if
(
typeof
Stripe
===
'
undefined
'
)
{
if
(
stripeLoading
)
{
return
;
}
stripeLoading
=
true
;
debugging
(
'
Stripe.js is not loaded!
'
);
$
.
getScript
(
"
https://js.stripe.com/v3
"
,
function
()
{
if
(
typeof
CRM
.
vars
.
stripe
===
'
undefined
'
)
{
debugging
(
"
Script loaded and executed.
"
);
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
CRM.vars.stripe not defined! Not a Stripe processor?
'
);
stripeLoading
=
false
;
return
;
});
}
}
}
switch
(
CRM
.
vars
.
stripe
.
paymentIntentStatus
)
{
function
debugging
(
errorCode
)
{
case
'
succeeded
'
:
// Uncomment the following to debug unexpected returns.
case
'
cancelled
'
:
if
((
typeof
(
CRM
.
vars
.
stripe
)
===
'
undefined
'
)
||
(
Boolean
(
CRM
.
vars
.
stripe
.
jsDebug
)
===
true
))
{
CRM
.
payment
.
debugging
(
confirm
.
scriptName
,
'
paymentIntent:
'
+
CRM
.
vars
.
stripe
.
paymentIntentStatus
);
console
.
log
(
new
Date
().
toISOString
()
+
'
civicrm_stripe.js:
'
+
errorCode
);
return
;
}
}
}
});
confirm
.
checkAndLoad
();
confirm
.
handleCardConfirm
();
// Disable the browser "Leave Page Alert" which is triggered because we mess with the form submit function.
window
.
onbeforeunload
=
null
;
}(
jQuery
,
CRM
,
_
));
This diff is collapsed.
Click to expand it.
stripe.php
+
1
−
1
View file @
e465606c
...
@@ -162,7 +162,7 @@ function stripe_civicrm_buildForm($formName, &$form) {
...
@@ -162,7 +162,7 @@ function stripe_civicrm_buildForm($formName, &$form) {
'path'
=>
\Civi
::
resources
()
->
getPath
(
E
::
LONG_NAME
,
'js/civicrmStripeConfirm.js'
),
'path'
=>
\Civi
::
resources
()
->
getPath
(
E
::
LONG_NAME
,
'js/civicrmStripeConfirm.js'
),
'mimetype'
=>
'application/javascript'
,
'mimetype'
=>
'application/javascript'
,
]
]
));
)
,
-
1000
);
// This is a fairly nasty way of matching and retrieving our paymentIntent as it is no longer available.
// This is a fairly nasty way of matching and retrieving our paymentIntent as it is no longer available.
$qfKey
=
CRM_Utils_Request
::
retrieve
(
'qfKey'
,
'String'
);
$qfKey
=
CRM_Utils_Request
::
retrieve
(
'qfKey'
,
'String'
);
...
...
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