Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • extensions/mjwshared
  • jitendra/mjwshared
  • scardinius/mjwshared
  • artfulrobot/mjwshared
  • capo/mjwshared
  • agilewarefj/mjwshared
  • JonGold/mjwshared
  • aaron/mjwshared
  • sluc23/mjwshared
  • marsh/mjwshared
  • konadave/mjwshared
  • wmortada/mjwshared
  • jtwyman/mjwshared
  • pradeep/mjwshared
  • AllenShaw/mjwshared
  • jamie/mjwshared
  • JKingsnorth/mjwshared
  • ufundo/mjwshared
  • DaveD/mjwshared
19 results
Show changes
Showing
with 1578 additions and 506 deletions
docs/images/refundui-membership.png

39.2 KiB

docs/images/refundui.png

25.2 KiB

# Payment Shared library
This library is used by all payment processors by MJW Consulting and other extensions.
This library is used by all payment processors by MJW and other extensions.
It provides multiple functions such as APIs, refund UI, shared code and a compatibility layer to support multiple versions of CiviCRM without requiring explicit support in the payment processor.
The main "goals" of this extension are:
- Provide an abstraction layer between CiviCRM core and payment extensions so
that we don't have to write and maintain the same code in every extension.
- Provide a compatibility layer between CiviCRM core and payment extensions so
that we don't force sites to upgrade CiviCRM core versions just to keep their Payment Processor working.
(Generally we target a minimum CiviCRM core version based on the last security release).
- Provide a "staging" environment for proving new APIs / interfaces that should eventually become
a standard part of CiviCRM core.
- Provide a rapid way of fixing bugs in Payment Processing without forcing a CiviCRM core update
(eg. we can issue a new release of "Payment Shared" containing a workaround for bugs in specific versions
of CiviCRM core).
## Setup
#### Job.process_paymentprocessor_webhooks
This job processes new webhook events in the `civicrm_paymentprocessor_webhook` table.
* Run: Always
* Domain-specific: YES. This job MUST be run on every domain you have setup if using multisite/multidomain.
## Support and Maintenance
This extension is supported and maintained by:
[![MJW Consulting](images/mjwconsulting.jpg)](https://www.mjwconsult.co.uk)
......
# Payment Processor Implementation
This library provides two helper "traits":
- `CRM_Core_Payment_MJWTrait` - helpers to implement your `CRM_Core_Payment_Xx` class.
- `CRM_Core_Payment_MJWIPNTrait` - helpers to implement IPN/webhook processing for your payment processor.
## The Payment Processor
### doPayment()
```php
public function doPayment(&$params, $component = 'contribute') {
/* @var \Civi\Payment\PropertyBag $propertyBag */
$propertyBag = $this->beginDoPayment($params);
// Set payment pending
$this->setStatusPaymentPending($propertyBag)
// ... Handle the actual payment / communicate with external servers etc.
// Payment succeeded?
$this->setStatusPaymentCompleted($propertyBag)
return $this->endDoPayment($propertyBag);
}
```
## changeSubscriptionAmount() (Edit recurring contribution)
```php
public function changeSubscriptionAmount(&$message = '', $params = []) {
$propertyBag = $this->beginChangeSubscriptionAmount($params);
// ... Handle update subscription / communicate with external servers.
// On error throw exception
return TRUE;
}
```
## updateSubscriptionBillingInfo() (Update payment info + address)
```php
public function updateSubscriptionBillingInfo(&$message = '', $params = []) {
$propertyBag = $this->beginUpdateSubscriptionBillingInfo($params);
// ... Handle update billing info / communicate with external servers.
// On error throw exception
return TRUE;
}
```
## doCancelRecurring() (Cancel recurring contribution)
```php
public function doCancelRecurring(PropertyBag $propertyBag) {
// By default we always notify the processor and we don't give the user the option
// because supportsCancelRecurringNotifyOptional() = FALSE
if (!$propertyBag->has('isNotifyProcessorOnCancelRecur')) {
// If isNotifyProcessorOnCancelRecur is NOT set then we set our default
$propertyBag->setIsNotifyProcessorOnCancelRecur(TRUE);
}
$notifyProcessor = $propertyBag->getIsNotifyProcessorOnCancelRecur();
if (!$notifyProcessor) {
return ['message' => E::ts('Successfully cancelled the subscription in CiviCRM ONLY.')];
}
if (!$propertyBag->has('recurProcessorID')) {
$errorMessage = E::ts('The recurring contribution cannot be cancelled (No reference (contribution_recur.processor_id) found).');
\Civi::log()->error($errorMessage);
throw new \Civi\Payment\Exception\PaymentProcessorException($errorMessage);
}
// ... Handle cancel recurring / communicate with external servers.
// If we failed to cancel
if ($failed) {
throw new \Civi\Payment\Exception\PaymentProcessorException($this->handleError(NULL, 'Failed to cancel'));
}
return ['message' => E::ts('Successfully cancelled the subscription at XYZ.net.')];
}
```
## doRefund() (Refund full or partial contribution)
```php
/**
* Submit a refund payment
*
* @param array $params
* Assoc array of input parameters for this transaction.
*
* @return array
* @throws \Civi\Payment\Exception\PaymentProcessorException
*/
public function doRefund(&$params): array {
$propertyBag = $this->beginDoRefund($params);
if (!$propertyBag->has('transactionID') || !$propertyBag->has('amount')) {
$errorMessage = $this->getLogPrefix() . 'doRefund: Missing mandatory parameters: transactionID, amount';
$this->logger->logError($errorMessage);
throw new PaymentProcessorException($errorMessage);
}
// Implement code to prepare request and communicate with Payment Processor
// ...
// Set $refundTransactionID based on response from Payment Processor
if ($refundFailed) {
throw new PaymentProcessorException('Refund failed: ' . $failureMessage);
}
// If we didn't throw an exception then refund succeeded.
$refundParams = [
'refund_trxn_id' => $refundTransactionID,
'refund_status' => 'Completed',
'fee_amount' => 0,
];
return $refundParams;
}
```
# Refunds UI (experimental)
There is a refunds UI available for payments:
![Refund UI](images/refundui.png)
To access the refund click the "undo" icon by the payment:
![Refund icon](images/refundpaymenticon.png)
# Refunds UI
If supported by the payment processor (eg. Stripe) you can issue a full or partial refund from within CiviCRM.
It is enabled by default via the setting `mjwshared_refundpaymentui` which can be found at
*Administer->CiviContribute->Stripe Settings: Enable refund payment via UI?*
*Administer->CiviContribute->Payment Shared Settings: Enable refund payment via UI?*
It allows you to issue refunds for `Completed` payments if the payment processor supports it (eg. Stripe).
It allows you to issue refunds for `Completed` payments.
It also allows you to choose whether to cancel the **event registration** if there are any linked to the contribution (via line-items).
To access the refunds UI you must have **edit contributions** permission.
## Support for cancelling memberships
1. Click the "arrow" to expand the contribution and show payments.
2. To access the refund form click the "undo" icon by the payment:
![Refund icon](images/refundpaymenticon.png)
You will see a refund form.
If the contribution was used to pay for a membership you can optionally cancel the membership:
![Refund UI - memberships](images/refundui-membership.png)
If you'd like to see support for cancelling memberships when issuing a refund please <a href="https://www.mjwconsult.co.uk/en/civicrm/pcp/info/?reset=1&id=6">contribute via this page</a>.
If the contribution was used to pay for an event you can optionally cancel the event registration:
![Refund UI - events](images/refundui-events.png)
......@@ -9,6 +9,231 @@ Releases use the following numbering system:
* **[BC]**: Items marked with [BC] indicate a breaking change that will require updates to your code if you are using that code in your extension.
## Release 1.3.4 (2025-02-26)
* Make sure we always activate customdata from managed entities
* Add civicrm-ext type to composer.json
## Release 1.3.3 (2025-01-06)
* Change ManagedEntity to update policy always (prevents conflicts with other extensions and fixes issues with them disappearing in certain circumstances).
* Fix regression on required checkbox fields.
* Fix JS crash if name is undefined.
## Release 1.3.2 (2024-10-13)
* Add check for webhooks stuck in processing status - if this is triggered something probably needs fixing manually.
* Replace deprecated exception.
* Switch to entity framework v2.
* Switch to mgd files to define cg_extend_objects - used to allow custom fields on "FinancialTrxn" entity. Added in a way that doesn't conflict with other extensions.
## Release 1.3.1 (2024-08-26)
* [!46](https://lab.civicrm.org/extensions/mjwshared/-/merge_requests/46) Ensure autorenew works with memberships.
## Release 1.3 (2024-07-17)
* Add new API4 functions:
* ContributionRecur.updateAmountOnRecurMJW
* Membership.LinkToRecurMJW
* Membership.UnlinkFromRecurMJW
* PriceFieldValue.GetDefaultPriceFieldValueForContributionMJW
* PriceFieldValue.GetDefaultPriceFieldValueForMembershipMJW
* PaymentMJW.create
See [API docs](api.md) for more information.
* Add search identifier and raw data options to Payment Processor Webhooks UI.
## Release 1.2.22 (2024-03-09)
* Fix message display on PaymentProcessorWebhook UI when message is NULL.
* Add generic Logger class `\Civi\MJW\Logger` - use this to standardise/simplify log messages.
* Update getDefaultCurrencyForForm() to use standard form functions where available.
* Update some functions to use API4 internally.
* Replace deprecated `CiviCRM_API3_Exception`.
* More robust `error_url` handling.
* Fix currency shown on refund form.
## Release 1.2.21 (2024-02-09)
* Switch Payment processor webhooks menu entry to managed entity.
* Add a settings page (Administer->CiviContribute->Payment Shared Settings).
* [!44](https://lab.civicrm.org/extensions/mjwshared/-/merge_requests/44) Ensure email confirm is sent for events when using stripe checkout (Fixes extensions/stripe#456).
* Add feature to disable (hide) core 'Record Refund' link on edit contribution.
* Add handling for billingCountry on update subscription.
## Release 1.2.20 (2023-12-16)
* Fix CustomField params for Mjwpayment.create_payment.
* Fix setting of recur ID for changeSubscriptionAmount.
## Release 1.2.19 (2023-12-15)
* Add CustomFields to API3 MJWPayment.create spec - makes the custom fields "discoverable" via the API3 explorer.
* Update beginChangeSubscriptionAmount() function - for Payment Processors that allow you to update the subscription amount it should now be slightly more reliable.
## Release 1.2.18 (2023-11-21)
* [!42](https://lab.civicrm.org/extensions/mjwshared/-/merge_requests/42) avoid extra redirect; correctly show auth.net errors on failed transaction.
## Release 1.2.17 (2023-10-16)
**You MUST update to this version if running CiviCRM 5.66 otherwise webhooks will stop working**
* Fix message field should not be required (CiviCRM core enforces required fields for API4 from 5.66).
* Cleanup custom fields.
## Release 1.2.16 (2023-10-16)
**Do not use this release**
It was released with a broken upgrader.
## Release 1.2.15 (2023-09-10)
* Fix [civicrm-core/#4553](https://lab.civicrm.org/dev/core/-/issues/4553) getBillingEmail() function causes fatal error when email is not passed in correctly.
## Release 1.2.14 (2023-08-14)
* [!41](https://lab.civicrm.org/extensions/mjwshared/-/merge_requests/41) The extension fails to install or upgrade if the option value for cg extends already present in the database (fix compatibility with extensions that use custom fields on financial transactions).
## Release 1.2.13 (2023-06-26)
* smartyv2-1.0.1 does not work on 5.59 because of https://github.com/civicrm/civicrm-core/commit/7168793c03ef57c06bbfe45f5ff873ebb3657806
so we set minimum version to 5.58 which triggers civix to ship as an extension mixin.
## Release 1.2.12 (2023-06-25)
* Add Payment_details custom field group and allow custom fields to be saved via API3 `Mjwpayment.create`.
* Pass through custom params in `updateContributionCompleted()`.
* Convert some internals to API4.
* Refactor API call to fix payment processor name issue.
* Use getter for `_paymentProcessor`.
## Release 1.2.11 (2023-01-30)
* Remove our version of CRM_Core_Payment::getAmount() as it was merged into core in 5.37.
* Fix undefined variable basePage on frontend formbuilder pages.
## Release 1.2.10 (2022-11-22)
* Make sure calculateTaxAmount always returns a valid float.
* Stop recommending installation of minifier extension (it can cause problems with some angularjs scripts).
* Check both frontend/backend URL for AJAX requests.
* Add indexes to civicrm_paymentprocessor_webhook - see [Stripe#395](https://lab.civicrm.org/extensions/stripe/-/issues/395).
* Fix translation [!31](https://lab.civicrm.org/extensions/mjwshared/-/merge_requests/31).
## Release 1.2.9 (2022-10-14)
* Add psr0 classloader to info.xml.
* Don't update (set update to never) Paymentprocessorwebhooks managed job (stops it re-enabling automatically).
* Upgrade civix.
* Fix [#18](https://lab.civicrm.org/extensions/mjwshared/-/issues/18) Don't add refund link if no payment processor.
## Release 1.2.8 (2022-08-19)
* Multiple participants: Handle 100% discount. Fix [Stripe#372](https://lab.civicrm.org/extensions/stripe/-/issues/372) etc. when additional participant amount is more than first participant.
* Convert getTokenParameter() to use propertyBag.
* Fix [!35](https://lab.civicrm.org/extensions/mjwshared/-/merge_requests/35) style issues with Greenwich; also nicer formatting of raw data.
## Release 1.2.7 (2022-07-20)
* Minimum supported version of Stripe extension is now 6.7.
* Add `\Civi\Paymentshared\WebhookEventIgnoredException` for use by payment processors.
* Fix deprecated API4 join.
## Release 1.2.6 (2022-06-14)
* Add support for percentagepricesetfield/extrafee extensions (was previously supported but broke in 1.2.3).
* Support partial refunds.
* Fix [#8](https://lab.civicrm.org/extensions/mjwshared/-/issues/8) Support cancelling memberships when issuing refunds.
## Release 1.2.5 (2022-05-19)
* Separate `trxn_id` and `order_reference` params and prefer `trxn_id` in return values from `doPayment()`. This means that both are now available for use.
* Refunds: Add a lock around recording refund payment in `MJWIPNTrait::updateContributionRefund()`. This means we should not record a duplicate refund if both UI and IPN are processed at the same time.
* Update return params from `doRefund()`.
* [!33](https://lab.civicrm.org/extensions/mjwshared/-/merge_requests/33) Add processor filter to webhooks list page.
## Release 1.2.4
* Fix [!30](https://lab.civicrm.org/extensions/mjwshared/-/merge_requests/30) Pledges are also recurring.
* Set `civicrm_contribution_recur.processor_id` if still using `trxn_id`.
## Release 1.2.3
* [!29](https://lab.civicrm.org/extensions/mjwshared/-/merge_requests/29) Throw exception on error (when using handleError() function).
* Fix [#10](https://lab.civicrm.org/extensions/mjwshared/-/issues/10) Replace .prop() with .attr() when selecting BillingFormID.
* Improve `CRM.payment.getIsRecur()` so it returns early if recur is not supported.
* `Mjwpayment.get_contribution` API supports contribution_id - update spec.
* Replace core `calculateTotalFee()` javascript function with our own. This makes us independent of core changes - eg. see https://github.com/civicrm/civicrm-core/pull/22759.
* Calculate the total amount for multiple event participants when calling `CRM.payment.getTotalAmount()`.
## Release 1.2.2
* Add result parameter to webhookEventNotMatched and update example.
* Add getter/setter for contributionRecurID in IPN trait.
* Add link to example hook implementation for webhookEventNotMatched (https://github.com/mjwconsult/civicrm-stripewebhookrules).
* Enable js debugging for drupal webform.
## Release 1.2.1
* Fix display of 'Error' status on webhook UI.
* More helpful error messages when IPN processing fails.
* Job.process_paymentprocessor_webhooks needs to be domain-specific (setup to run on each domain).
* Add event_id and queue_limit to Job.process_paymentprocessor_webhooks.
* Add deleted count to Job.process_paymentprocessor_webhooks.
* Only delete old webhook entries for our domain (when multiple domains configured).
* Add system check to make sure that scheduled jobs are setup on all domains.
## Release 1.2
**Thanks to [ArtfulRobot](https://artfulrobot.uk) this release improves the webhook queueing system
and adds a user interface to view/manage webhooks.**
* Implement `processWebhookEvent()` - This receives and processes the row from `civicrm_paymentprocessor_webhook` (from `PaymentprocessorWebhook`).
* Update schema and add indexes to `civicrm_paymentprocessor_webhooks` table.
* Improve api3 `Job.ProcessPaymentprocessorWebhooks` return data and add time.
* Add angular app to view/manage webhooks.
* Fully remove support for CiviCRM older that 5.35.
## Release 1.1
**This release *should* be compatible with payment processors that require 1.0 or higher.
But make sure you test before upgrading.**
* Add multiple functions to CRM.payment (that were previously in civicrmStripe.js):
* resetBillingFieldsRequiredForJQueryValidate
* setBillingFieldsRequiredForJQueryValidate
* addDrupalWebformActionElement
* doStandardFormSubmit
* validateReCaptcha
* addSupportForCiviDiscount
* displayError
* swalFire
* swalClose
* triggerEvent
* Minor (backwards-compatible) fixes/changes to existing functions (eg. setting class variables directly instead of relying on return values).
* Refactor checks class, move checks from Stripe to mjwshared:
* Check for Sweetalert extension.
* Check for "Separate Membership Payment" is enabled.
* Support X.X-dev versioning for system checks - display a warning if dev version, version check no longer fails if eg. using 1.1-dev and minimum requirement is 1.1.
* Return a fixed set of params from `doPayment()` - see [dev/financial/issues#141](https://lab.civicrm.org/dev/financial/-/issues/141).
* Move cast to PropertyBag to beginDoPayment (reduce lines of code required in doPayment).
* Automatically handle deprecated `trxn_id` on `civicrm_contribution_recur` (copy from `processor_id` and add deprecated warnings).
* Add `beginUpdateSubscriptionBillingInfo()` and `beginChangeSubscriptionAmount()` methods - see [Payment Processor](paymentprocessor.md).
* Convert internal method `getContactID()` to require propertyBag.
* Define contributionRecur property on IPN class.
* Add new [hook `webhookEventNotMatched`](hooks.md).
* Add handling for multiple js payment processors and delayed crmBillingFormReloadComplete event trigger.
* Fix invalid currency on some event registration forms.
* Fix for non-default Wordpress basepage and AJAX reload of payment elements.
## Release 1.0.1
* Fix [!22](https://lab.civicrm.org/extensions/mjwshared/-/merge_requests/22) Handle deprecated API4 joins in PaymentProcessorwebhook API.
## Release 1.0
* Add PaymentprocessorWebhook entity, API and scheduled job that allows for queueing and scheduling of webhooks - see [Webhook Queue](webhookqueue.md)
......
This diff is collapsed.
......@@ -10,20 +10,34 @@
</maintainer>
<urls>
<url desc="Main Extension Page">https://lab.civicrm.org/extensions/mjwshared</url>
<url desc="Documentation">https://lab.civicrm.org/extensions/mjwshared/-/blob/master/README.md</url>
<url desc="Support">https://mjw.pt/support/mjwshared</url>
<url desc="Release Notes">https://lab.civicrm.org/extensions/mjwshared/-/blob/master/docs/releasenotes.md</url>
<url desc="Licensing">http://www.gnu.org/licenses/agpl-3.0.html</url>
</urls>
<releaseDate>2021-05-17</releaseDate>
<version>1.0</version>
<releaseDate>2025-02-26</releaseDate>
<version>1.3.4</version>
<develStage>stable</develStage>
<compatibility>
<ver>5.35</ver>
<ver>5.74</ver>
</compatibility>
<classloader>
<psr0 prefix="CRM_" path="."/>
<psr4 prefix="Civi\" path="Civi"/>
</classloader>
<civix>
<namespace>CRM/Mjwshared</namespace>
<format>25.01.1</format>
</civix>
<mixins>
<mixin>ang-php@1.0.0</mixin>
<mixin>menu-xml@1.0.0</mixin>
<mixin>mgd-php@1.0.0</mixin>
<mixin>setting-php@1.0.0</mixin>
<mixin>setting-admin@1.0.1</mixin>
<mixin>scan-classes@1.0.0</mixin>
<mixin>entity-types-php@2.0.0</mixin>
<mixin>smarty@1.0.3</mixin>
</mixins>
<upgrader>CiviMix\Schema\Mjwshared\AutomaticUpgrader</upgrader>
</extension>
This diff is collapsed.
<?php
use CRM_Mjwshared_ExtensionUtil as E;
return [
[
'name' => 'Navigation_afsearchPaymentProcessorWebhooks',
'entity' => 'Navigation',
'cleanup' => 'unused',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'label' => E::ts('Payment Processor Webhooks'),
'name' => 'afsearchPaymentProcessorWebhooks',
'url' => 'civicrm/paymentprocessorwebhooks',
'icon' => 'crm-i fa-list-alt',
'permission' => [
'edit contributions',
],
'permission_operator' => 'AND',
'parent_id.name' => 'CiviContribute',
'weight' => 19,
],
'match' => ['name', 'domain_id'],
],
],
];
<?php
use CRM_Mjwshared_ExtensionUtil as E;
return [
[
'name' => 'ProcessPaymentProcessorWebhooks',
'entity' => 'Job',
'cleanup' => 'always',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'name' => 'Process PaymentProcessor Webhooks',
'description' => E::ts('Process incomplete payment processor webhooks'),
'run_frequency' => 'Always',
'api_entity' => 'Job',
'api_action' => 'process_paymentprocessor_webhooks',
'parameters' => 'delete_old=-3 month',
],
'match' => [
'name',
],
],
],
];
This diff is collapsed.
This diff is collapsed.
<?php
return [
[
'name' => 'cg_extend_objects:FinancialTrxn',
'entity' => 'OptionValue',
'cleanup' => 'unused',
'update' => 'always',
'params' => [
'version' => 4,
'values' => [
'option_group_id.name' => 'cg_extend_objects',
'label' => ts('Financial Transaction (Payment)'),
'value' => 'FinancialTrxn',
'name' => 'civicrm_financial_trxn',
'is_reserved' => TRUE,
'is_active' => TRUE,
],
'match' => ['option_group_id', 'name'],
],
],
];
\ No newline at end of file
<?php
use CRM_Mjwshared_ExtensionUtil as E;
// This enables custom fields for FinancialTrxn entities
return [
[
'name' => 'CustomGroup_Payment_details',
'entity' => 'CustomGroup',
'cleanup' => 'unused',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'name' => 'Payment_details',
'title' => E::ts('Payment details'),
'extends' => 'FinancialTrxn',
'style' => 'Inline',
'help_pre' => '',
'help_post' => '',
'weight' => 8,
'collapse_adv_display' => TRUE,
'icon' => '',
'is_active' => TRUE,
],
'match' => [
'name',
],
],
],
];
This diff is collapsed.
File added
This diff is collapsed.
This diff is collapsed.
......@@ -19,5 +19,7 @@ nav:
- Overview: index.md
- Release Notes: releasenotes.md
- API: api.md
- Hooks: hooks.md
- How to implement a payment processor: paymentprocessor.md
- Refund UI: refunds.md
- Webhook Queue: webhookqueue.md