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
7277706a
Commit
7277706a
authored
4 years ago
by
mattwire
Committed by
mattwire
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Refactor and fix error handling in response to StripePaymentintent.Process API
parent
e18e0edc
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!152
6.6 to master
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/v3/StripePaymentintent.php
+3
-3
3 additions, 3 deletions
api/v3/StripePaymentintent.php
js/civicrmStripeConfirm.js
+2
-2
2 additions, 2 deletions
js/civicrmStripeConfirm.js
js/civicrm_stripe.js
+54
-47
54 additions, 47 deletions
js/civicrm_stripe.js
with
59 additions
and
52 deletions
api/v3/StripePaymentintent.php
+
3
−
3
View file @
7277706a
...
...
@@ -215,7 +215,7 @@ function civicrm_api3_stripe_paymentintent_process($params) {
elseif
(
$e
instanceof
\Stripe\Exception\InvalidRequestException
)
{
$message
=
'Invalid request'
;
}
return
civicrm_api3_create_error
(
[
'message'
=>
$message
]
);
return
civicrm_api3_create_error
(
$message
);
}
}
...
...
@@ -236,7 +236,7 @@ function civicrm_api3_stripe_paymentintent_process($params) {
// Tell the client to handle the action
return
civicrm_api3_create_success
([
'requires_action'
=>
true
,
'payment
i
ntent
_c
lient
_s
ecret'
=>
$intent
->
client_secret
,
'payment
I
ntent
C
lient
S
ecret'
=>
$intent
->
client_secret
,
]);
}
elseif
((
$intent
->
status
===
'requires_capture'
)
||
(
$intent
->
status
===
'requires_confirmation'
))
{
...
...
@@ -257,7 +257,7 @@ function civicrm_api3_stripe_paymentintent_process($params) {
elseif
(
$intent
->
status
===
'requires_payment_method'
)
{
return
civicrm_api3_create_success
([
'requires_payment_method'
=>
true
,
'payment
i
ntent
_c
lient
_s
ecret'
=>
$intent
->
client_secret
,
'payment
I
ntent
C
lient
S
ecret'
=>
$intent
->
client_secret
,
]);
}
else
{
...
...
This diff is collapsed.
Click to expand it.
js/civicrmStripeConfirm.js
+
2
−
2
View file @
7277706a
...
...
@@ -51,7 +51,7 @@
handlePaymentIntentAction
:
function
(
response
)
{
switch
(
CRM
.
vars
.
stripe
.
paymentIntentMethod
)
{
case
'
automatic
'
:
confirm
.
stripe
.
handleCardPayment
(
response
.
payment
_i
ntent
_c
lient
_s
ecret
)
confirm
.
stripe
.
handleCardPayment
(
response
.
payment
I
ntent
C
lient
S
ecret
)
.
then
(
function
(
result
)
{
if
(
result
.
error
)
{
// Show error in payment form
...
...
@@ -66,7 +66,7 @@
break
;
case
'
manual
'
:
confirm
.
stripe
.
handleCardAction
(
response
.
payment
_i
ntent
_c
lient
_s
ecret
)
confirm
.
stripe
.
handleCardAction
(
response
.
payment
I
ntent
C
lient
S
ecret
)
.
then
(
function
(
result
)
{
if
(
result
.
error
)
{
// Show error in payment form
...
...
This diff is collapsed.
Click to expand it.
js/civicrm_stripe.js
+
54
−
47
View file @
7277706a
...
...
@@ -131,6 +131,7 @@
}
triggerEvent
(
'
crmBillingFormNotValid
'
);
if
(
notify
)
{
swalClose
();
swalFire
({
icon
:
'
error
'
,
text
:
errorMessage
,
...
...
@@ -233,7 +234,7 @@
}
},
''
,
false
);
CRM
.
api3
(
'
StripePaymentintent
'
,
'
Process
'
,
{
payment_method_id
:
r
esult
.
paymentMethod
.
id
,
payment_method_id
:
createPaymentMethodR
esult
.
paymentMethod
.
id
,
amount
:
CRM
.
payment
.
getTotalAmount
().
toFixed
(
2
),
currency
:
CRM
.
payment
.
getCurrency
(
CRM
.
vars
.
stripe
.
currency
),
id
:
CRM
.
vars
.
stripe
.
id
,
...
...
@@ -241,14 +242,43 @@
csrfToken
:
CRM
.
vars
.
stripe
.
csrfToken
,
extra_data
:
CRM
.
payment
.
getBillingEmail
()
+
CRM
.
payment
.
getBillingName
()
})
.
done
(
function
(
result
)
{
// Handle server response (see Step 3)
.
done
(
function
(
paymentIntentProcessResponse
)
{
swalClose
();
handleServerResponse
(
result
);
debugging
(
'
StripePaymentintent.Process done
'
);
if
(
paymentIntentProcessResponse
.
is_error
)
{
// Triggered for api3_create_error or Exception
displayError
(
paymentIntentProcessResponse
.
error_message
,
true
);
}
else
{
paymentIntentProcessResponse
=
paymentIntentProcessResponse
.
values
;
if
(
paymentIntentProcessResponse
.
requires_action
)
{
// Use Stripe.js to handle a pending card action (eg. 3d-secure)
paymentData
.
clientSecret
=
paymentIntentProcessResponse
.
paymentIntentClientSecret
;
stripe
.
handleCardAction
(
paymentData
.
clientSecret
)
.
then
(
function
(
cardActionResult
)
{
if
(
cardActionResult
.
error
)
{
// Show error in payment form
displayError
(
cardActionResult
.
error
.
message
,
true
);
}
else
{
// The card action has been handled
// The PaymentIntent can be confirmed again on the server
successHandler
(
'
paymentIntentID
'
,
cardActionResult
.
paymentIntent
);
}
});
}
else
{
// All good, we can submit the form
successHandler
(
'
paymentIntentID
'
,
paymentIntentProcessResponse
.
paymentIntent
);
}
}
})
.
fail
(
function
()
{
swalClose
();
displayError
(
'
Unknown error
'
,
true
);
.
fail
(
function
(
object
)
{
// Triggered when http code !== 200 (eg. 400 Bad request)
var
error
=
'
Unknown error
'
;
if
(
object
.
hasOwnProperty
(
'
statusText
'
))
{
error
=
object
.
statusText
;
}
displayError
(
error
,
true
);
});
}
}
...
...
@@ -274,55 +304,32 @@
id
:
CRM
.
vars
.
stripe
.
id
,
description
:
document
.
title
,
csrfToken
:
CRM
.
vars
.
stripe
.
csrfToken
//metadata: {integration_check: accept_a_payment}
})
.
done
(
function
(
result
)
{
// Handle server response (see Step 3)
.
done
(
function
(
paymentIntentProcessResponse
)
{
swalClose
();
// Trigger the paymentRequest dialog
paymentData
.
clientSecret
=
result
.
values
.
payment_intent_client_secret
;
paymentData
.
paymentRequest
.
show
();
// From here the on 'paymentmethod' of the paymentRequest handles completion/failure
debugging
(
'
StripePaymentintent.Process done
'
);
if
(
paymentIntentProcessResponse
.
is_error
)
{
// Triggered for api3_create_error or Exception
displayError
(
paymentIntentProcessResponse
.
error_message
,
true
);
}
else
{
paymentIntentProcessResponse
=
paymentIntentProcessResponse
.
values
;
// Trigger the paymentRequest dialog
paymentData
.
clientSecret
=
paymentIntentProcessResponse
.
paymentIntentClientSecret
;
paymentData
.
paymentRequest
.
show
();
// From here the on 'paymentmethod' of the paymentRequest handles completion/failure
}
})
.
fail
(
function
(
result
)
{
.
fail
(
function
(
object
)
{
// Triggered when http code !== 200 (eg. 400 Bad request)
var
error
=
'
Unknown error
'
;
if
(
resul
t
.
hasOwnProperty
(
'
statusText
'
))
{
error
=
resul
t
.
statusText
;
if
(
objec
t
.
hasOwnProperty
(
'
statusText
'
))
{
error
=
objec
t
.
statusText
;
}
swalClose
();
displayError
(
error
,
true
);
});
}
function
handleServerResponse
(
result
)
{
debugging
(
'
handleServerResponse
'
);
if
(
result
.
error
)
{
// Show error from server on payment form
displayError
(
result
.
error
.
message
,
true
);
}
else
if
(
result
.
requires_action
)
{
// Use Stripe.js to handle required card action
handleAction
(
result
);
}
else
{
// All good, we can submit the form
successHandler
(
'
paymentIntentID
'
,
result
.
paymentIntent
);
}
}
function
handleAction
(
result
)
{
paymentData
.
clientSecret
=
result
.
payment_intent_client_secret
;
stripe
.
handleCardAction
(
paymentData
.
clientSecret
)
.
then
(
function
(
cardActionResult
)
{
if
(
cardActionResult
.
error
)
{
// Show error in payment form
displayError
(
cardActionResult
.
error
.
message
,
true
);
}
else
{
// The card action has been handled
// The PaymentIntent can be confirmed again on the server
successHandler
(
'
paymentIntentID
'
,
cardActionResult
.
paymentIntent
);
}
});
}
/**
* Payment processor is not Stripe - cleanup
*/
...
...
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