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
74db267e
Commit
74db267e
authored
4 years ago
by
mattwire
Committed by
mattwire
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Simplify Stripe.Ipn API
parent
7277706a
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!152
6.6 to master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
api/v3/Stripe/Ipn.php
+26
-54
26 additions, 54 deletions
api/v3/Stripe/Ipn.php
with
26 additions
and
54 deletions
api/v3/Stripe/Ipn.php
+
26
−
54
View file @
74db267e
...
...
@@ -45,79 +45,51 @@ function _civicrm_api3_stripe_Ipn_spec(&$spec) {
* @throws \CiviCRM_API3_Exception
*/
function
civicrm_api3_stripe_Ipn
(
$params
)
{
$object
=
NULL
;
$ppid
=
NULL
;
$stripeObject
=
NULL
;
$paymentProcessorID
=
NULL
;
if
(
array_key_exists
(
'id'
,
$params
))
{
// Read from civicrm SystemLog
$data
=
civicrm_api3
(
'SystemLog'
,
'getsingle'
,
[
'id'
=>
$params
[
'id'
],
'return'
=>
[
'message'
,
'context'
]]);
if
(
empty
(
$data
))
{
throw
new
API_Exception
(
'Failed to find that entry in the system log'
,
3234
);
}
$
o
bject
=
json_decode
(
$data
[
'context'
]);
if
(
preg_match
(
'/processor_id=([0-9]+)$/'
,
$
o
bject
[
'message'
],
$matches
))
{
$p
pid
=
$matches
[
1
];
$
stripeO
bject
=
json_decode
(
$data
[
'context'
]);
if
(
preg_match
(
'/processor_id=([0-9]+)$/'
,
$
stripeO
bject
[
'message'
],
$matches
))
{
$p
aymentProcessorID
=
$matches
[
1
];
}
else
{
throw
new
API_Exception
(
'Failed to find payment processor id in system log'
,
3235
);
}
}
elseif
(
array_key_exists
(
'evtid'
,
$params
))
{
// Read directly from Stripe using event_id
if
(
!
array_key_exists
(
'ppid'
,
$params
))
{
throw
new
API_Exception
(
'Please pass the payment processor id (ppid) if using evtid.'
,
3236
);
}
$p
pid
=
$params
[
'ppid'
];
$paymentProcessor
=
new
CRM_Core_Payment_Stripe
(
''
,
civicrm_api3
(
'PaymentProcessor'
,
'getsingle'
,
[
'id'
=>
$ppid
])
);
$p
aymentProcessorID
=
$params
[
'ppid'
];
$paymentProcessor
=
\Civi\Payment\System
::
singleton
()
->
getById
(
$paymentProcessorID
);
$paymentProcessor
->
setAPIParams
();
$object
=
\Stripe\Event
::
retrieve
(
$params
[
'evtid'
]);
$stripeObject
=
\Stripe\Event
::
retrieve
(
$params
[
'evtid'
]);
}
// See if we've already processed the IPN (do we have a contribution not in pending state?)
if
(
$object
->
data
->
object
->
object
===
'charge'
)
{
// For a charge event we get the ID here
$trxnID
=
$object
->
data
->
object
->
id
;
}
else
{
// I'm not sure if this is still used for any events?
$trxnID
=
$object
->
data
->
object
->
charge
;
}
if
(
empty
(
$trxnID
))
{
throw
new
API_Exception
(
'Could not get Charge ID from event.'
);
// By default, set emailReceipt to NULL so the default receipt setting
// will kick in.
$emailReceipt
=
NULL
;
if
(
$params
[
'suppressreceipt'
]
==
1
)
{
// Override, do not send receipt.
$emailReceipt
=
0
;
}
try
{
$contribution
=
civicrm_api3
(
'Contribution'
,
'getsingle'
,
[
'trxn_id'
=>
$trxnID
,
]);
if
(
$contribution
[
'contribution_status_id'
]
!==
CRM_Core_PseudoConstant
::
getKey
(
'CRM_Contribute_BAO_Contribution'
,
'contribution_status_id'
,
'Pending'
)
)
{
return
civicrm_api3_create_error
(
"Ipn already processed."
);
}
$processPaymentNotificationResult
=
$paymentProcessor
::
processPaymentNotification
(
$paymentProcessorID
,
json_encode
(
$stripeObject
),
FALSE
,
$emailReceipt
);
}
catch
(
Throwable
$e
)
{
return
civicrm_api3_create_error
(
$e
->
getMessage
());
}
catch
(
Exception
$e
)
{
// No existing contribution so we process IPN
}
if
(
class_exists
(
'CRM_Core_Payment_StripeIPN'
))
{
// By default, set emailReceipt to NULL so the default receipt setting
// will kick in.
$emailReceipt
=
NULL
;
if
(
$params
[
'suppressreceipt'
]
==
1
)
{
// Override, do not send receipt.
$emailReceipt
=
0
;
}
try
{
$paymentProcessor
->
processPaymentNotification
(
$ppid
,
json_encode
(
$object
),
FALSE
,
$emailReceipt
);
}
catch
(
Throwable
$e
)
{
return
civicrm_api3_create_error
(
$e
->
getMessage
());
}
}
else
{
trigger_error
(
"The api depends on CRM_Core_Payment_StripeIPN"
);
}
return
civicrm_api3_create_success
([]);
return
civicrm_api3_create_success
(
$processPaymentNotificationResult
,
$params
);
}
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