Skip to content

Commit

Permalink
Add workflow template classes for contributions
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Dec 30, 2021
1 parent c75a9b6 commit baf1d7a
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 4 deletions.
3 changes: 1 addition & 2 deletions CRM/Contribute/Form/Task/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,6 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
'resourceBase' => $config->userFrameworkResourceURL,
'defaultCurrency' => $config->defaultCurrency,
'amount' => $contribution->total_amount,
'currency' => $contribution->currency,
'amountDue' => $amountDue,
'amountPaid' => $amountPaid,
'invoice_date' => $invoiceDate,
Expand Down Expand Up @@ -414,9 +413,9 @@ public static function printPDF($contribIDs, &$params, $contactIds) {
$sendTemplateParams = [
'groupName' => 'msg_tpl_workflow_contribution',
'valueName' => 'contribution_invoice_receipt',
'contactId' => $contribution->contact_id,
'tplParams' => $tplParams,
'PDFFilename' => $pdfFileName,
'tokenContext' => ['contributionId' => $contribution->id, 'contactId' => $contribution->contact_id],
];

// from email address
Expand Down
37 changes: 37 additions & 0 deletions CRM/Contribute/WorkflowMessage/ContributionInvoiceReceipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?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 Civi\WorkflowMessage\GenericWorkflowMessage;

/**
* Invoice generated when invoicing is enabled.
*
* @support template-only
* @see CRM_Contribute_Form_Task_Invoice::printPDF
*/
class CRM_Contribute_WorkflowMessage_ContributionInvoiceReceipt extends GenericWorkflowMessage {

use CRM_Contribute_WorkflowMessage_ContributionTrait;

public const WORKFLOW = 'contribution_invoice_receipt';

/**
* Specify any tokens that should be exported as smarty variables.
*
* @todo it might be that this should be moved to the trait as we
* we work through these.
*
* @param array $export
*/
protected function exportExtraTokenContext(array &$export): void {
$export['smartyTokenAlias']['currency'] = 'contribution.currency';
}
}
22 changes: 22 additions & 0 deletions CRM/Contribute/WorkflowMessage/ContributionOfflineReceipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?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 |
+--------------------------------------------------------------------+
*/

/**
* Receipt sent when confirming a back office contribution.
*
* @support template-only
* @see CRM_Contribute_Form_AdditionalInfo::emailReceipt
*/
class CRM_Contribute_WorkflowMessage_ContributionOfflineReceipt extends \Civi\WorkflowMessage\GenericWorkflowMessage {
use CRM_Contribute_WorkflowMessage_ContributionTrait;
public const WORKFLOW = 'contribution_offline_receipt';

}
29 changes: 29 additions & 0 deletions CRM/Contribute/WorkflowMessage/ContributionOnlineReceipt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?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 Civi\WorkflowMessage\GenericWorkflowMessage;

/**
* Receipt sent when confirming contribution add payment.
*
* Add payment, complete order and the front end contribution form
* result in an email send using this, unless an event is involved.
* In addition the api contribution.sendconfirmation and the search task
* call this.
*
* @support template-only
* @see CRM_Contribute_BAO_ContributionPage::sendMail
*/
class CRM_Contribute_WorkflowMessage_ContributionOnlineReceipt extends GenericWorkflowMessage {
use CRM_Contribute_WorkflowMessage_ContributionTrait;
public const WORKFLOW = 'contribution_online_receipt';

}
39 changes: 39 additions & 0 deletions CRM/Contribute/WorkflowMessage/ContributionTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

/**
* @method array getContribution()
* @method array getContributionID()
* @method $this setContributionID(array $contact)
*/
trait CRM_Contribute_WorkflowMessage_ContributionTrait {
/**
* The contribution.
*
* @var array|null
*
* @scope tokenContext as contribution
*/
public $contribution;

/**
* @var int
* @scope tokenContext as contribution_id
*/
public $contributionId;

/**
* Set contribution object.
*
* @param array $contribution
*
* @return $this
*/
public function setContribution(array $contribution): self {
$this->contribution = $contribution;
if (!empty($contribution['id'])) {
$this->contributionId = $contribution['id'];
}
return $this;
}

}
6 changes: 4 additions & 2 deletions tests/phpunit/CRM/Contribute/Form/Task/InvoiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function tearDown(): void {
* CRM-17815 - Test due date and payment advice block in generated
* invoice pdf for pending and completed contributions
*/
public function testInvoiceForDueDate() {
public function testInvoiceForDueDate(): void {
$contactIds = [];
$params = [
'output' => 'pdf_invoice',
Expand Down Expand Up @@ -86,7 +86,7 @@ public function testInvoiceForDueDate() {
*
* @throws \CRM_Core_Exception
*/
public function testInvoiceForLineItems() {
public function testInvoiceForLineItems(): void {

$this->enableTaxAndInvoicing();

Expand Down Expand Up @@ -217,6 +217,8 @@ public function testInvoiceContactFields(): void {
$expected = [
'externalIdentifier (token):::2345',
'displayName (token):::Mr. Anthony Anderson II',
'currency (token):::GBP',
'currency (smarty):::GBP',
];
foreach ($expected as $string) {
$this->assertStringContainsString($string, $invoiceHTML);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
displayName (token):::{contact.display_name}
organizationName (token):::{contact.organization_name}
externalIdentifier (token):::{contact.external_identifier}
currency (token):::{contribution.currency}
currency (smarty):::{$currency}

0 comments on commit baf1d7a

Please sign in to comment.