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
a449d079
Commit
a449d079
authored
7 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Remove re-use token
parent
26f94f67
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CRM/Core/Payment/Stripe.php
+3
-14
3 additions, 14 deletions
CRM/Core/Payment/Stripe.php
js/civicrm_stripe.js
+27
-27
27 additions, 27 deletions
js/civicrm_stripe.js
with
30 additions
and
41 deletions
CRM/Core/Payment/Stripe.php
+
3
−
14
View file @
a449d079
...
...
@@ -216,18 +216,6 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$stripe_key
=
self
::
stripe_get_key
(
$stripe_ppid
);
$form
->
addElement
(
'hidden'
,
'stripe_pub_key'
,
$stripe_key
,
array
(
'id'
=>
'stripe-pub-key'
));
$params
=
$form
->
get
(
'params'
);
// Contrib forms store this in $params, Event forms in $params[0].
if
(
!
empty
(
$params
[
0
][
'stripe_token'
]))
{
$params
=
$params
[
0
];
}
$stripeToken
=
(
empty
(
$params
[
'stripetoken'
])
?
NULL
:
$params
[
'stripetoken'
]);
// Add some hidden fields for Stripe.
if
(
!
empty
(
$stripeToken
)
&&
!
$form
->
elementExists
(
'stripetoken'
))
{
$form
->
addElement
(
'hidden'
,
'stripetoken'
,
$stripeToken
,
array
(
'id'
=>
'stripe-token'
));
}
// Add email field as it would usually be found on donation forms.
if
(
!
isset
(
$form
->
_elementIndex
[
'email'
])
&&
!
empty
(
$form
->
userEmail
))
{
$form
->
addElement
(
'hidden'
,
'email'
,
$form
->
userEmail
,
array
(
'id'
=>
'user-email'
));
...
...
@@ -302,8 +290,9 @@ class CRM_Core_Payment_Stripe extends CRM_Core_Payment {
$amount
=
(
int
)
preg_replace
(
'/[^\d]/'
,
''
,
strval
(
$amount
));
// Use Stripe.js instead of raw card details.
if
(
!
empty
(
$params
[
'credit_card_number'
])
&&
(
substr
(
$params
[
'credit_card_number'
],
0
,
4
)
===
'tok_'
))
{
$card_details
=
$params
[
'credit_card_number'
];
// Token is appended after nulled credit card number
if
(
!
empty
(
$params
[
'credit_card_number'
])
&&
(
substr
(
$params
[
'credit_card_number'
],
16
,
4
)
===
'tok_'
))
{
$card_details
=
substr
(
$params
[
'credit_card_number'
],
16
);
$params
[
'credit_card_number'
]
=
''
;
}
else
{
...
...
This diff is collapsed.
Click to expand it.
js/civicrm_stripe.js
+
27
−
27
View file @
a449d079
...
...
@@ -28,10 +28,12 @@
else
{
var
token
=
response
[
'
id
'
];
// Update form with the token & submit.
copyCCDetails
(
$form
);
removeCCDetails
(
$form
);
// We use the credit_card_number field to pass token as this is reliable.
// Inserting an input field is unreliable on ajax forms and often gets missed from POST request for some reason.
$form
.
find
(
"
input#credit_card_number
"
).
val
(
token
);
var
ccNum
=
$form
.
find
(
"
input#credit_card_number
"
).
val
();
$form
.
find
(
"
input#credit_card_number
"
).
val
(
ccNum
+
token
);
// Disable unload event handler
window
.
onbeforeunload
=
null
;
...
...
@@ -114,23 +116,9 @@
var
webformPrevious
=
$
(
'
input.webform-previous
'
).
first
().
val
();
}
else
{
// CiviCRM form
// If we already have a token hide CC details
if
(
$form
.
find
(
"
input#credit_card_number
"
).
val
())
{
$
(
'
.credit_card_info-group
'
).
hide
();
$
(
'
#billing-payment-block
'
).
append
(
'
<input type="button" value="Edit CC details" id="ccButton" />
'
);
$
(
'
#ccButton
'
).
click
(
function
()
{
// Clear token and show CC details if edit button was clicked
// As we use credit_card_number to pass token, make sure it is empty when shown
$form
.
find
(
"
input#credit_card_number
"
).
val
(
''
);
$
(
'
.credit_card_info-group
'
).
show
();
$
(
'
#ccButton
'
).
hide
();
});
}
else
{
// As we use credit_card_number to pass token, make sure it is empty when shown
$form
.
find
(
"
input#credit_card_number
"
).
val
(
''
);
}
// As we use credit_card_number to pass token, make sure it is empty when shown
$form
.
find
(
"
input#credit_card_number
"
).
val
(
''
);
$form
.
find
(
"
input#cvv2
"
).
val
(
''
);
}
$submit
.
removeAttr
(
'
onclick
'
);
...
...
@@ -194,13 +182,6 @@
debugging
(
'
debug: Stripe is the selected payprocessor
'
);
}
// Handle reuse of existing token
if
(
$form
.
find
(
"
input#credit_card_number
"
).
val
())
{
removeCCDetails
(
$form
);
debugging
(
'
debug: Re-using Stripe token
'
);
return
true
;
}
// If there's no credit card field, no use in continuing (probably wrong
// context anyway)
if
(
!
$form
.
find
(
'
#credit_card_number
'
).
length
)
{
...
...
@@ -228,8 +209,27 @@
function
removeCCDetails
(
$form
)
{
// Remove the "name" attribute so params are not submitted
$form
.
find
(
"
input#credit_card_number
"
).
val
(
'
0000000000000000
'
);
$form
.
find
(
"
input#cvv2
"
).
val
(
'
000
'
);
var
ccNumElement
=
$form
.
find
(
"
input#credit_card_number
"
);
var
cvv2Element
=
$form
.
find
(
"
input#cvv2
"
);
var
last4digits
=
ccNumElement
.
val
().
substr
(
12
,
16
);
ccNumElement
.
val
(
'
000000000000
'
+
last4digits
);
cvv2Element
.
val
(
'
000
'
);
}
function
copyCCDetails
(
$form
)
{
// Remove the "name" attribute so params are not submitted
var
ccNumElement
=
$form
.
find
(
"
input#credit_card_number
"
);
var
cvv2Element
=
$form
.
find
(
"
input#cvv2
"
);
var
ccNum
=
ccNumElement
.
val
();
var
cvv2Num
=
cvv2Element
.
val
();
var
ccDummyElement
=
ccNumElement
.
clone
();
var
cvv2DummyElement
=
cvv2Element
.
clone
();
ccNumElement
.
css
(
'
display
'
,
'
none
'
);
cvv2Element
.
css
(
'
display
'
,
'
none
'
);
ccDummyElement
.
removeAttr
(
'
name
'
).
removeAttr
(
'
id
'
);
cvv2DummyElement
.
removeAttr
(
'
name
'
).
removeAttr
(
'
id
'
);
ccDummyElement
.
insertAfter
(
ccNumElement
);
cvv2DummyElement
.
insertAfter
(
cvv2Element
);
}
function
debugging
(
errorCode
)
{
...
...
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