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
6f3fce33
Commit
6f3fce33
authored
2 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Support CiviCRM 5.51 for update email address
parent
c93529d3
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!209
6.8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CRM/Stripe/BAO/StripeCustomer.php
+19
-5
19 additions, 5 deletions
CRM/Stripe/BAO/StripeCustomer.php
api/v3/StripeCustomer.php
+1
-1
1 addition, 1 deletion
api/v3/StripeCustomer.php
stripe.php
+28
-7
28 additions, 7 deletions
stripe.php
with
48 additions
and
13 deletions
CRM/Stripe/BAO/StripeCustomer.php
+
19
−
5
View file @
6f3fce33
...
...
@@ -18,11 +18,25 @@ class CRM_Stripe_BAO_StripeCustomer extends CRM_Stripe_DAO_StripeCustomer {
* @throws \Civi\API\Exception\UnauthorizedException
*/
public
static
function
getStripeCustomerMetadata
(
int
$contactID
,
?string
$email
=
NULL
,
array
$invoiceSettings
=
[],
?string
$description
=
NULL
)
{
$contact
DisplayName
=
Contact
::
get
(
FALSE
)
$contact
=
Contact
::
get
(
FALSE
)
->
addSelect
(
'display_name'
,
'email_primary.email'
,
'email_billing.email'
)
->
addWhere
(
'id'
,
'='
,
$contactID
)
->
execute
()
->
first
()[
'display_name'
];
->
first
();
if
(
version_compare
(
\CRM_Utils_System
::
version
(),
'5.53.0'
,
'<'
))
{
// @todo: Remove when we drop support for CiviCRM < 5.53
// APIv4 - Read & write contact primary and billing locations as implicit joins
// https://github.com/civicrm/civicrm-core/pull/23972 was added in 5.53
$email
=
\Civi\Api4\Email
::
get
(
FALSE
)
->
addOrderBy
(
'is_primary'
,
'DESC'
)
->
addOrderBy
(
'is_billing'
,
'DESC'
)
->
execute
()
->
first
();
if
(
!
empty
(
$email
[
'email'
]))
{
$contact
[
'email_primary.email'
]
=
$email
[
'email'
];
}
}
$extVersion
=
Extension
::
get
(
FALSE
)
->
addWhere
(
'file'
,
'='
,
E
::
SHORT_NAME
)
...
...
@@ -30,17 +44,17 @@ class CRM_Stripe_BAO_StripeCustomer extends CRM_Stripe_DAO_StripeCustomer {
->
first
()[
'version'
];
$stripeCustomerParams
=
[
'name'
=>
$contact
D
isplay
N
ame
,
'name'
=>
$contact
[
'd
isplay
_n
ame
'
]
,
// Stripe does not include the Customer Name when exporting payments, just the customer
// description, so we stick the name in the description.
'description'
=>
$description
??
$contact
D
isplay
N
ame
.
' (CiviCRM)'
,
'description'
=>
$description
??
$contact
[
'd
isplay
_n
ame
'
]
.
' (CiviCRM)'
,
'metadata'
=>
[
'CiviCRM Contact ID'
=>
$contactID
,
'CiviCRM URL'
=>
CRM_Utils_System
::
url
(
'civicrm/contact/view'
,
"reset=1&cid=
{
$contactID
}
"
,
TRUE
,
NULL
,
FALSE
,
FALSE
,
TRUE
),
'CiviCRM Version'
=>
CRM_Utils_System
::
version
()
.
' '
.
$extVersion
,
],
];
$email
=
$email
??
$contact
DisplayName
[
'email_primary.email'
]
??
$contact
DisplayName
[
'email_billing.email'
]
??
NULL
;
$email
=
$email
??
$contact
[
'email_primary.email'
]
??
$contact
[
'email_billing.email'
]
??
NULL
;
if
(
$email
)
{
$stripeCustomerParams
[
'email'
]
=
$email
;
}
...
...
This diff is collapsed.
Click to expand it.
api/v3/StripeCustomer.php
+
1
−
1
View file @
6f3fce33
...
...
@@ -135,7 +135,7 @@ function civicrm_api3_stripe_customer_updatestripemetadata($params) {
if
(
!
isset
(
$params
[
'dryrun'
]))
{
throw
new
CRM_Core_Exception
(
'Missing required parameter dryrun'
);
}
$customers
=
\Civi\Api4\StripeCustomer
::
get
();
$customers
=
\Civi\Api4\StripeCustomer
::
get
(
FALSE
);
if
(
isset
(
$params
[
'options'
][
'limit'
]))
{
$customers
=
$customers
->
setLimit
(
$params
[
'options'
][
'limit'
]);
}
...
...
This diff is collapsed.
Click to expand it.
stripe.php
+
28
−
7
View file @
6f3fce33
...
...
@@ -262,14 +262,35 @@ function stripe_civicrm_permission(&$permissions) {
function
stripe_civicrm_post
(
$op
,
$objectName
,
$objectId
,
&
$objectRef
)
{
switch
(
$objectName
)
{
case
'Contact'
:
if
(
$op
===
'merge'
)
{
try
{
CRM_Stripe_BAO_StripeCustomer
::
updateMetadataForContact
(
$objectId
);
}
catch
(
Exception
$e
)
{
\Civi
::
log
(
E
::
SHORT_NAME
)
->
error
(
'Stripe Contact Merge failed: '
.
$e
->
getMessage
());
}
case
'Individual'
:
switch
(
$op
)
{
case
'merge'
:
try
{
CRM_Stripe_BAO_StripeCustomer
::
updateMetadataForContact
(
$objectId
);
}
catch
(
Exception
$e
)
{
\Civi
::
log
(
E
::
SHORT_NAME
)
->
error
(
'Stripe Contact Merge failed: '
.
$e
->
getMessage
());
}
break
;
case
'edit'
:
try
{
// Does the contact have a Stripe customer record?
$stripeCustomers
=
\Civi\Api4\StripeCustomer
::
get
(
FALSE
)
->
addWhere
(
'contact_id'
,
'='
,
$objectId
)
->
execute
();
// Update the contact details at Stripe for each customer associated with this contact
foreach
(
$stripeCustomers
as
$stripeCustomer
)
{
\Civi\Api4\StripeCustomer
::
updateStripe
(
FALSE
)
->
setCustomerID
(
$stripeCustomer
[
'customer_id'
])
->
execute
();
}
}
catch
(
Exception
$e
)
{
\Civi
::
log
(
E
::
SHORT_NAME
)
->
error
(
'Stripe Contact update failed: '
.
$e
->
getMessage
());
}
}
case
'Email'
:
if
(
in_array
(
$op
,
[
'create'
,
'edit'
])
&&
((
int
)
$objectRef
->
is_primary
===
1
))
{
try
{
...
...
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