Commit 83b17326 authored by mattwire's avatar mattwire

Merge branch '0.6' into 'master'

0.6

See merge request !4
parents aa2941cf a4238049
......@@ -94,24 +94,66 @@ trait CRM_Core_Payment_MJWIPNTrait {
}
/**
* Record a refunded contribution
* This function ONLY supports full refunds
* Record a refund on a contribution
* This wraps around the payment.create API to support earlier releases than features were available
*
* Examples:
* $result = civicrm_api3('Payment', 'create', [
* 'contribution_id' => 590,
* 'total_amount' => -3,
* 'trxn_date' => 20191105200300,
* 'trxn_result_code' => "Test a refund with fees",
* 'fee_amount' => -0.25,
* 'trxn_id' => "abctx123",
* 'order_reference' => "abcor123",
* ]);
*
* Returns:
* "is_error": 0,
* "version": 3,
* "count": 1,
* "id": 465,
* "values": {
* "465": {
* "id": "465",
* "from_financial_account_id": "7",
* "to_financial_account_id": "6",
* "trxn_date": "20191105200300",
* "total_amount": "-3",
* "fee_amount": "-0.25",
* "net_amount": "",
* "currency": "USD",
* "is_payment": "1",
* "trxn_id": "abctx123",
* "trxn_result_code": "Test a refund with fees",
* "status_id": "7",
* "payment_processor_id": ""
* }
* }
*
* @param array $params
*
* @throws \CiviCRM_API3_Exception
*/
protected function updateContributionRefund($params) {
$this->checkRequiredParams('updateContributionRefund', ['id', 'payment_trxn_id'], $params);
if (empty($params['cancel_date'])) {
$params['cancel_date'] = date('YmdHis');
}
$params['contribution_status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Refunded');
$this->checkRequiredParams('updateContributionRefund', ['contribution_id', 'total_amount'], $params);
civicrm_api3('Contribution', 'create', $params);
$financialTrxn = civicrm_api3('Payment', 'create', $params);
$this->updatePaymentTrxnID($params['id'], $params['payment_trxn_id']);
// order_reference field was introduced in 5.20 but support was not available to save it via Payment.Create
if (version_compare(\CRM_Utils_System::version(), '5.20', '<')) {
// Order reference field not available so we do nothing with it.
}
else {
// @fixme We are on 5.20 or above, so have order_reference field available. But it's not yet updated by Payment.Create API
if (!empty($params['order_reference'])) {
civicrm_api3('FinancialTrxn', 'create', [
'id' => $financialTrxn['id'],
'trxn_id' => $params['trxn_id'],
'order_reference' => $params['order_reference'] ?? '',
]);
}
}
}
/**
......@@ -245,10 +287,11 @@ trait CRM_Core_Payment_MJWIPNTrait {
* Update the payment record so the trxn_id matches the actual transaction from the payment processor as we may have multiple transactions for a single payment (eg. failures, then success).
* @param int $contributionID
* @param string $trxnID
* @param string $orderReference
*
* @throws \CiviCRM_API3_Exception
*/
private function updatePaymentTrxnID($contributionID, $trxnID) {
private function updatePaymentTrxnID($contributionID, $trxnID, $orderReference = '') {
// @fixme: There needs to be a better way to do this!!
// Contribution trxn_id = invoice_id, payment trxn_id = charge_id
// but calling completetransaction does not allow us to do that.
......@@ -264,6 +307,7 @@ trait CRM_Core_Payment_MJWIPNTrait {
civicrm_api3('FinancialTrxn', 'create', [
'id' => $paymentID,
'trxn_id' => $trxnID,
'order_reference' => $orderReference,
]);
}
......
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
use CRM_Mjwshared_ExtensionUtil as E;
/**
* Class CRM_Mjwshared_Check
*/
class CRM_Mjwshared_Check {
public static function checkRequirements(&$messages) {
$extensions = civicrm_api3('Extension', 'get', [
'full_name' => 'uk.co.nfpservice.onlineworldpay',
]);
if (empty($extensions['id']) || ($extensions['values'][$extensions['id']]['status'] === 'installed')) {
$messages[] = new CRM_Utils_Check_Message(
'mjwshared_incompatible',
E::ts('You have the uk.co.nfpservice.onlineworldpay extension installed.
There are multiple versions of this extension on various sites and the source code has not been released.
It is known to be cause issues with other payment processors and should be disabled'),
E::ts('Incompatible Extension: uk.co.nfpservice.onlineworldpay'),
\Psr\Log\LogLevel::WARNING,
'fa-money'
);
}
}
}
<?php
/**
* https://civicrm.org/licensing
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
* Class CRM_Mjwshared_Utils
*/
class CRM_Mjwshared_Utils {
/**********************
* MJW_Utils: 20190822
*********************/
/**
* Return the field ID for $fieldName custom field
......@@ -38,4 +47,3 @@ class CRM_Mjwshared_Utils {
}
}
......@@ -8,8 +8,8 @@ The extension is licensed under [AGPL-3.0](LICENSE.txt).
## Requirements
* PHP v7.x+
* CiviCRM 5.13+
* PHP v7.1+
* CiviCRM 5.19+
## Installation
......
......@@ -11,8 +11,8 @@
function civicrm_api3_contribution_getbalance($params) {
$result['id'] = $params['id'];
$result['total'] = (float) CRM_Price_BAO_LineItem::getLineTotal($params['id']);
$result['balance'] = CRM_Contribute_BAO_Contribution::getContributionBalance($params['id']);
$result['paid'] = $result['total'] - $result['balance'];
$result['paid'] = (float) CRM_Core_BAO_FinancialTrxn::getTotalPayments($params['id'], TRUE) ?: 0;
$result['balance'] = $result['total'] - $result['paid'];
$result['currency'] = civicrm_api3('Contribution', 'getvalue', [
'return' => 'currency',
'id' => $params['id'],
......
......@@ -8,6 +8,12 @@ Where:
* minor: Breaking change in some circumstances, or a new feature. Read carefully and make sure you understand the impact of the change.
* incremental: A "safe" change / improvement. Should *always* be safe to upgrade.
## Release 0.6
* Improve updateContributionRefund() function to handle new `order_reference` field and use `Payment.create` API.
* Simply calls in Contribution.getbalance to improve performance.
* Add check to warn if nfp worldpay extension is installed as it breaks things!
## Release 0.5.1
* Fix getBillingEmail() to work in more circumstances and add tests
......@@ -19,7 +25,7 @@ Where:
## Release 0.4.6
* Fix missing return array on getTokenParameter.
## Release 0.4.5
* Remove setTokenParameter, modify getTokenParameter as we're now using pre_approval_parameters in Stripe 6.2
......@@ -39,12 +45,12 @@ Where:
## Release 0.4.1
* Fix 'is not boolean' error on IPNs. `getIsTestMode()` was returning TRUE/FALSE but the API requires 1/0.
* Fix 'is not boolean' error on IPNs. `getIsTestMode()` was returning TRUE/FALSE but the API requires 1/0.
## Release 0.4
* Fix issue with non-default currency on form when you can choose from more than one payment processor on the form.
* Add `getTokenParameter()`/`setTokenParameter()` functions to MJWTrait which should be used when setting parameters
* Add `getTokenParameter()`/`setTokenParameter()` functions to MJWTrait which should be used when setting parameters
via javascript (eg. Stripe `paymentIntentID`) which are required when the payment is actually processed (via `doPayment()`).
## Release 0.3
......
......@@ -13,9 +13,9 @@
<url desc="Support">https://www.mjwconsult.co.uk</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2019-11-01</releaseDate>
<version>0.5.1</version>
<develStage>stable</develStage>
<releaseDate>2019-12-22</releaseDate>
<version>0.6.beta2</version>
<develStage>beta</develStage>
<compatibility>
<ver>5.13</ver>
</compatibility>
......
......@@ -148,3 +148,12 @@ function mjwshared_civicrm_buildForm($formName, &$form) {
]);
}
}
/**
* Implements hook_civicrm_check().
*
* @throws \CiviCRM_API3_Exception
*/
function mjwshared_civicrm_check(&$messages) {
CRM_Mjwshared_Check::checkRequirements($messages);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment