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
4abd559e
Commit
4abd559e
authored
6 years ago
by
mattwire
Browse files
Options
Downloads
Patches
Plain Diff
Move shared IPN functions to a trait
parent
148b4b43
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/StripeIPN.php
+2
-15
2 additions, 15 deletions
CRM/Core/Payment/StripeIPN.php
CRM/Core/Payment/StripeIPNTrait.php
+108
-0
108 additions, 0 deletions
CRM/Core/Payment/StripeIPNTrait.php
with
110 additions
and
15 deletions
CRM/Core/Payment/StripeIPN.php
+
2
−
15
View file @
4abd559e
...
...
@@ -6,7 +6,7 @@
class
CRM_Core_Payment_StripeIPN
extends
CRM_Core_Payment_BaseIPN
{
protected
$_paymentProcessor
;
use
CRM_Core_Payment_StripeIPNTrait
;
/**
* Transaction ID is the contribution in the redirect flow and a random number in the on-site->POST flow
...
...
@@ -77,20 +77,7 @@ class CRM_Core_Payment_StripeIPN extends CRM_Core_Payment_BaseIPN {
// Determine the proper Stripe Processor ID so we can get the secret key
// and initialize Stripe.
// The $_GET['processor_id'] value is set by CRM_Core_Payment::handlePaymentMethod.
$paymentProcessorId
=
(
int
)
CRM_Utils_Array
::
value
(
'processor_id'
,
$_GET
);
if
(
empty
(
$paymentProcessorId
))
{
$this
->
exception
(
'Cannot determine payment processor id'
);
}
// Get the Stripe secret key.
try
{
$this
->
_paymentProcessor
=
\Civi\Payment\System
::
singleton
()
->
getById
(
$paymentProcessorId
)
->
getPaymentProcessor
();
}
catch
(
Exception
$e
)
{
$this
->
exception
(
'Failed to get Stripe secret key'
);
}
$this
->
getPaymentProcessor
();
// Now re-retrieve the data from Stripe to ensure it's legit.
\Stripe\Stripe
::
setApiKey
(
$this
->
_paymentProcessor
[
'user_name'
]);
...
...
This diff is collapsed.
Click to expand it.
CRM/Core/Payment/StripeIPNTrait.php
0 → 100644
+
108
−
0
View file @
4abd559e
<?php
/**
* Shared payment IPN functions that should one day be migrated to CiviCRM core
* Version: 20190304
*/
trait
CRM_Core_Payment_StripeIPNTrait
{
/**
* @var array Payment processor
*/
private
$_paymentProcessor
;
/**
* Get the payment processor
* The $_GET['processor_id'] value is set by CRM_Core_Payment::handlePaymentMethod.
*/
protected
function
getPaymentProcessor
()
{
$paymentProcessorId
=
(
int
)
CRM_Utils_Array
::
value
(
'processor_id'
,
$_GET
);
if
(
empty
(
$paymentProcessorId
))
{
$this
->
exception
(
'Failed to get payment processor id'
);
}
try
{
$this
->
_paymentProcessor
=
\Civi\Payment\System
::
singleton
()
->
getById
(
$paymentProcessorId
)
->
getPaymentProcessor
();
}
catch
(
Exception
$e
)
{
$this
->
exception
(
'Failed to get payment processor'
);
}
}
/**
* Mark a contribution as cancelled and update related entities
*
* @param array $params [ 'id' -> contribution_id, 'payment_processor_id' -> payment_processor_id]
*
* @return bool
* @throws \CiviCRM_API3_Exception
*/
protected
function
canceltransaction
(
$params
)
{
return
$this
->
incompletetransaction
(
$params
,
'cancel'
);
}
/**
* Mark a contribution as failed and update related entities
*
* @param array $params [ 'id' -> contribution_id, 'payment_processor_id' -> payment_processor_id]
*
* @return bool
* @throws \CiviCRM_API3_Exception
*/
protected
function
failtransaction
(
$params
)
{
return
$this
->
incompletetransaction
(
$params
,
'fail'
);
}
/**
* Handler for failtransaction and canceltransaction - do not call directly
*
* @param array $params
* @param string $mode
*
* @return bool
* @throws \CiviCRM_API3_Exception
*/
protected
function
incompletetransaction
(
$params
,
$mode
)
{
$requiredParams
=
[
'id'
,
'payment_processor_id'
];
foreach
(
$requiredParams
as
$required
)
{
if
(
!
isset
(
$params
[
$required
]))
{
$this
->
exception
(
'canceltransaction: Missing mandatory parameter: '
.
$required
);
}
}
if
(
isset
(
$params
[
'payment_processor_id'
]))
{
$input
[
'payment_processor_id'
]
=
$params
[
'payment_processor_id'
];
}
$contribution
=
new
CRM_Contribute_BAO_Contribution
();
$contribution
->
id
=
$params
[
'id'
];
if
(
!
$contribution
->
find
(
TRUE
))
{
throw
new
CiviCRM_API3_Exception
(
'A valid contribution ID is required'
,
'invalid_data'
);
}
if
(
!
$contribution
->
loadRelatedObjects
(
$input
,
$ids
,
TRUE
))
{
throw
new
CiviCRM_API3_Exception
(
'failed to load related objects'
);
}
$input
[
'trxn_id'
]
=
!
empty
(
$params
[
'trxn_id'
])
?
$params
[
'trxn_id'
]
:
$contribution
->
trxn_id
;
if
(
!
empty
(
$params
[
'fee_amount'
]))
{
$input
[
'fee_amount'
]
=
$params
[
'fee_amount'
];
}
$objects
[
'contribution'
]
=
&
$contribution
;
$objects
=
array_merge
(
$objects
,
$contribution
->
_relatedObjects
);
$transaction
=
new
CRM_Core_Transaction
();
switch
(
$mode
)
{
case
'cancel'
:
return
$this
->
cancelled
(
$objects
,
$transaction
);
case
'fail'
:
return
$this
->
failed
(
$objects
,
$transaction
);
default
:
throw
new
CiviCRM_API3_Exception
(
'Unknown incomplete transaction type: '
.
$mode
);
}
}
}
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