Skip to content

Commit

Permalink
debug
Browse files Browse the repository at this point in the history
  • Loading branch information
mattwire committed Jan 31, 2022
1 parent 6061edc commit 8cd29dd
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions src/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -695,29 +695,30 @@ function wf_civicrm_api3_contribution_transact($params) {
}

$order = civicrm_api3('Order', 'create', $params);
try {
//try {
// Use the Payment Processor to attempt to take the actual payment. You may
// pass in other params here, too.
$propertyBag = new \Civi\Payment\PropertyBag();
$propertyBag->mergeLegacyInputParams($params);
$propertyBag->setContributionID($order['id']);
$propertyBag->setAmount($params['total_amount']);


/* @var \CRM_Core_Payment $paymentProcessor */
$paymentProcessor = \Civi\Payment\System::singleton()->getById($params['payment_processor_id']);
$payResult = $paymentProcessor->doPayment($propertyBag);

// payment_status is not yet returned by some paymentprocessors so set it if not.
// See https://lab.civicrm.org/dev/financial/-/issues/141
if (!isset($payResult['payment_status']) && isset($payResult['payment_status_id'])) {
$payResult['payment_status'] = \CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $payResult['payment_status_id']);
}
//if (!isset($payResult['payment_status']) && isset($payResult['payment_status_id'])) {
// $payResult['payment_status'] = \CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $payResult['payment_status_id']);
// }

// webform_civicrm sends out receipts using Contribution.send_confirmation API if the contribution page is has is_email_receipt = TRUE.
// We allow this to be overridden here but default to FALSE.
$params['is_email_receipt'] = $params['is_email_receipt'] ?? FALSE;

if ($payResult['payment_status'] === 'Completed') {
//if ($payResult['payment_status'] === 'Completed') {
// Assuming the payment was taken, record it which will mark the Contribution
// as Completed and update related entities.
civicrm_api3('Payment', 'create', [
Expand All @@ -730,20 +731,24 @@ function wf_civicrm_api3_contribution_transact($params) {
'is_send_contribution_notification' => $params['is_email_receipt'],
'trxn_id' => $payResult['trxn_id'] ?? NULL,
]);
}
}
catch (\Exception $e) {
// }
//}
/*catch (\Exception $e) {
// Payment failed - update the Contribution status in CiviCRM to "Failed"
\Civi\Api4\Contribution::update(FALSE)
->addWhere('id', '=', $order['id'])
->addValue('contribution_status_id:name', 'Failed')
->execute();
return ['error_message' => $e->getMessage()];
}
}*/

$contribution = civicrm_api3('Contribution', 'getsingle', ['id' => $order['id']]);
$contribution['payment_status_id'] = $contribution['contribution_status_id'];
return $contribution;

// Contribution.transact is expected to return an API3 result containing the contribution
// eg. [ 'id' => X, 'values' => [ X => [ contribution details ] ]
return civicrm_api3('Contribution', 'get', ['id' => $order['id']]);
//return civicrm_api3('Contribution', 'get', ['id' => $order['id']]);
}

/**
Expand Down

0 comments on commit 8cd29dd

Please sign in to comment.