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
788c831b
Commit
788c831b
authored
2 years ago
by
ayduns
Committed by
mattwire
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Update StripeCustomer.updatestripemetadata to use API4 and consistent metadata
parent
9d1131cf
No related branches found
Branches containing commit
No related tags found
1 merge request
!209
6.8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CRM/Stripe/Customer.php
+3
-3
3 additions, 3 deletions
CRM/Stripe/Customer.php
CRM/Stripe/Upgrader.php
+2
-1
2 additions, 1 deletion
CRM/Stripe/Upgrader.php
api/v3/StripeCustomer.php
+25
-24
25 additions, 24 deletions
api/v3/StripeCustomer.php
with
30 additions
and
28 deletions
CRM/Stripe/Customer.php
+
3
−
3
View file @
788c831b
...
...
@@ -164,7 +164,7 @@ class CRM_Stripe_Customer {
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
p
rivate
static
function
getStripeCustomerMetadata
(
$params
)
{
p
ublic
static
function
getStripeCustomerMetadata
(
$params
)
{
$contactDisplayName
=
Contact
::
get
(
FALSE
)
->
addSelect
(
'display_name'
)
->
addWhere
(
'id'
,
'='
,
$params
[
'contact_id'
])
...
...
@@ -181,7 +181,7 @@ class CRM_Stripe_Customer {
'email'
=>
$params
[
'email'
]
??
''
,
'metadata'
=>
[
'CiviCRM Contact ID'
=>
$params
[
'contact_id'
],
'CiviCRM URL'
=>
CRM_Utils_System
::
url
(
'civicrm/contact/view'
,
"reset=1&cid=
{
$params
[
'contact_id'
]
}
"
,
TRUE
,
NULL
,
TRU
E
,
FALSE
,
TRUE
),
'CiviCRM URL'
=>
CRM_Utils_System
::
url
(
'civicrm/contact/view'
,
"reset=1&cid=
{
$params
[
'contact_id'
]
}
"
,
TRUE
,
NULL
,
FALS
E
,
FALSE
,
TRUE
),
'CiviCRM Version'
=>
CRM_Utils_System
::
version
()
.
' '
.
$extVersion
,
],
];
...
...
@@ -239,7 +239,7 @@ class CRM_Stripe_Customer {
// Could be multiple customer_id's and/or stripe processors
foreach
(
$customers
as
$customer
)
{
$stripe
=
new
CRM_Core_Payment_Stripe
(
NULL
,
$customer
[
'processor_id'
]);
$stripe
=
\Civi\Payment\System
::
singleton
()
->
getById
(
$customer
[
'processor_id'
]);
CRM_Stripe_Customer
::
updateMetadata
(
[
'contact_id'
=>
$contactId
,
'processor_id'
=>
$customer
[
'processor_id'
]],
$stripe
,
...
...
This diff is collapsed.
Click to expand it.
CRM/Stripe/Upgrader.php
+
2
−
1
View file @
788c831b
...
...
@@ -422,7 +422,8 @@ class CRM_Stripe_Upgrader extends CRM_Stripe_Upgrader_Base {
public
function
upgrade_6803
()
{
$this
->
ctx
->
log
->
info
(
'Applying Stripe update 5028. In civicrm_stripe_customers database table, rename id to customer_id, add new id column'
);
if
(
!
CRM_Core_BAO_SchemaHandler
::
checkIfFieldExists
(
'civicrm_stripe_customers'
,
'customer_id'
))
{
CRM_Core_DAO
::
executeQuery
(
"ALTER TABLE civicrm_stripe_customers RENAME COLUMN id TO customer_id"
);
// ALTER TABLE ... RENAME COLUMN only in MySQL8+
CRM_Core_DAO
::
executeQuery
(
"ALTER TABLE civicrm_stripe_customers CHANGE COLUMN id customer_id varchar(255) COMMENT 'Stripe Customer ID'"
);
if
(
CRM_Core_BAO_SchemaHandler
::
checkIfIndexExists
(
'civicrm_stripe_customers'
,
'id'
))
{
CRM_Core_DAO
::
executeQuery
(
"ALTER TABLE civicrm_stripe_customers RENAME INDEX id TO customer_id"
);
}
...
...
This diff is collapsed.
Click to expand it.
api/v3/StripeCustomer.php
+
25
−
24
View file @
788c831b
...
...
@@ -135,50 +135,51 @@ function civicrm_api3_stripe_customer_updatestripemetadata($params) {
if
(
!
isset
(
$params
[
'dryrun'
]))
{
throw
new
CiviCRM_API3_Exception
(
'Missing required parameter dryrun'
);
}
// Check params
if
(
empty
(
$params
[
'id'
]))
{
$customers
=
\Civi\Api4\StripeCustomer
::
get
();
if
(
isset
(
$params
[
'options'
][
'limit'
]))
{
$customers
=
$customers
->
setLimit
(
$params
[
'options'
][
'limit'
]);
}
if
(
isset
(
$params
[
'options'
][
'offset'
]))
{
$customers
=
$customers
->
setOffset
(
$params
[
'options'
][
'offset'
]);
}
if
(
$params
[
'customer_id'
])
{
$customers
=
$customers
->
addWhere
(
'customer_id'
,
'='
,
$params
[
'customer_id'
]);
}
else
{
// We're doing an update on all stripe customers
if
(
!
isset
(
$params
[
'processor_id'
]))
{
throw
new
CiviCRM_API3_Exception
(
'Missing required parameters processor_id when using without a customer id'
);
}
$customerIds
=
CRM_Stripe_Customer
::
getAll
(
$params
[
'processor_id'
],
$params
[
'options'
]);
}
else
{
$customerIds
=
[
$params
[
'id'
]];
else
{
$customers
=
$customers
->
addWhere
(
'processor_id'
,
'='
,
$params
[
'processor_id'
]);
}
}
foreach
(
$customerIds
as
$customerId
)
{
$customerParams
=
CRM_Stripe_Customer
::
getParamsForCustomerId
(
$customerId
);
if
(
empty
(
$customerParams
[
'contact_id'
]))
{
throw
new
CiviCRM_API3_Exception
(
'Could not find contact ID for stripe customer: '
.
$customerId
);
$customers
=
$customers
->
execute
();
foreach
(
$customers
as
$customer
)
{
if
(
!
$customer
[
'contact_id'
])
{
throw
new
CiviCRM_API3_Exception
(
'Could not find contact ID for stripe customer: '
.
$customer
[
'customer_id'
]);
}
/** @var \CRM_Core_Payment_Stripe $paymentProcessor */
$paymentProcessor
=
\Civi\Payment\System
::
singleton
()
->
getById
(
$customer
Params
[
'processor_id'
]);
$paymentProcessor
=
\Civi\Payment\System
::
singleton
()
->
getById
(
$customer
[
'processor_id'
]);
// Get the stripe customer from stripe
try
{
$paymentProcessor
->
stripeClient
->
customers
->
retrieve
(
$customer
Id
);
$paymentProcessor
->
stripeClient
->
customers
->
retrieve
(
$customer
[
'customer_id'
]
);
}
catch
(
Exception
$e
)
{
$err
=
CRM_Core_Payment_Stripe
::
parseStripeException
(
'retrieve_customer'
,
$e
);
throw
new
PaymentProcessorException
(
'Failed to retrieve Stripe Customer: '
.
$err
[
'code'
]);
}
// Get the contact display name
$contactDisplayName
=
civicrm_api3
(
'Contact'
,
'getvalue'
,
[
'return'
=>
'display_name'
,
'id'
=>
$customerParams
[
'contact_id'
],
]);
// Currently we set the description and metadata
$stripeCustomerParams
=
[
'description'
=>
$contactDisplayName
.
' (CiviCRM)'
,
'metadata'
=>
[
'civicrm_contact_id'
=>
$customerParams
[
'contact_id'
]],
];
$stripeCustomerParams
=
CRM_Stripe_Customer
::
getStripeCustomerMetadata
(
$customer
);
// Update the stripe customer object at stripe
if
(
!
$params
[
'dryrun'
])
{
$paymentProcessor
->
stripeClient
->
customers
->
update
(
$customer
Id
,
$stripeCustomerParams
);
$paymentProcessor
->
stripeClient
->
customers
->
update
(
$customer
[
'customer_id'
]
,
$stripeCustomerParams
);
$results
[]
=
$stripeCustomerParams
;
}
else
{
...
...
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