diff --git a/CRM/Core/Payment/Square.php b/CRM/Core/Payment/Square.php
index 54d61a0..4f29056 100644
--- a/CRM/Core/Payment/Square.php
+++ b/CRM/Core/Payment/Square.php
@@ -7,6 +7,7 @@
use Civi\Payment\Exception\PaymentProcessorException;
use Civi\Payment\PropertyBag;
use Square\SquareClient;
+use Square\Types\CustomerDetails;
use Square\Types\Money;
use Square\Types\SubscriptionSource;
use Square\Payments\Requests\CreatePaymentRequest;
@@ -20,7 +21,9 @@
*
* This processor supports:
* - One-off (non-recurring) card payments via Square Payments API
- * - Recurring contributions via Square Subscriptions API.
+ * - Recurring contributions via Square Subscriptions API
+ * - Both on CiviCRM's back-office forms too, where staff enter the
+ * payer's card (see supportsBackOffice()).
*
* Card details are never handled by CiviCRM directly. Instead, the
* Square Web Payments SDK is used in the browser to tokenize the card
@@ -124,6 +127,9 @@ public function buildForm(&$form) {
// A new card for an existing recurring contribution: saved, not
// charged (see updateSubscriptionBillingInfo()).
'isCardUpdate' => $form instanceof CRM_Contribute_Form_UpdateBilling,
+ // Staff are keying in the payer's card (MOTO), so Square must not
+ // ask them to verify as the buyer.
+ 'isBackOffice' => $this->isBackOfficeForm($form),
];
// Add hidden field for the payment token.
@@ -165,6 +171,22 @@ public function buildForm(&$form) {
return FALSE;
}
+ /**
+ * Whether staff, not the payer, enter the card on this form.
+ *
+ * CiviCRM's payment forms declare it ($form->isBackOffice: TRUE on the
+ * back-office contribution, membership, event registration and payment
+ * forms, and on the billing block they reload). For any other form, fall
+ * back to what CiviCRM told this processor (setBackOffice()).
+ *
+ * @param \CRM_Core_Form $form
+ *
+ * @return bool
+ */
+ protected function isBackOfficeForm($form): bool {
+ return (bool) ($form->isBackOffice ?? $this->isBackOffice());
+ }
+
/**
* Build a SquareClient configured for this processor (2025 SDK style).
*
@@ -513,14 +535,23 @@ protected function doOneTimePayment(&$params) {
$amountMinorUnits = CRM_Square_Currency::toMinorUnits($amount, $currency);
// 3. Idempotency key, derived from the checkout's own reference so that a
- // retried request for the same checkout can never charge twice. Every
- // CiviCRM checkout supplies one; without it a retry could not be told
- // apart from a new payment, so refuse rather than risk a second charge.
+ // retried request for the same checkout can never charge twice. Without
+ // one a retry could not be told apart from a new payment, so refuse
+ // rather than risk a second charge.
$paymentReference = $params['invoiceID'] ?? $params['invoice_id'] ?? $params['contributionID'] ?? $params['contribution_id'] ?? NULL;
- if ($paymentReference === NULL || $paymentReference === '') {
+ $idempotencyReference = $paymentReference;
+ if (($paymentReference === NULL || $paymentReference === '') && $this->isBackOffice()) {
+ // CiviCRM's back-office "Submit Credit Card Payment" form, which adds a
+ // payment to an existing contribution, passes no reference. The card
+ // token is single-use, so it identifies this checkout instead: a
+ // re-posted form carries the same token, a new payment a new one.
+ $paymentReference = 'entered by staff for contact ' . ($params['contactID'] ?? $params['contact_id'] ?? 'unknown');
+ $idempotencyReference = 'card-token:' . $token;
+ }
+ if ($idempotencyReference === NULL || $idempotencyReference === '') {
throw new \CRM_Core_Exception('Cannot take a Square payment without a CiviCRM invoice or contribution reference.');
}
- $idempotencyKey = $this->idempotencyKey('payment', (string) $paymentReference);
+ $idempotencyKey = $this->idempotencyKey('payment', (string) $idempotencyReference);
// 4. Build payload for CreatePayment.
$requestValues = [
@@ -530,6 +561,15 @@ protected function doOneTimePayment(&$params) {
'locationId' => $this->getLocationId(),
];
+ // Staff keyed in the payer's card: a Mail Order / Telephone Order (MOTO)
+ // payment, as js/square.js told Square when tokenizing it.
+ if ($this->isBackOffice()) {
+ $requestValues['customerDetails'] = new CustomerDetails([
+ 'customerInitiated' => FALSE,
+ 'sellerKeyedIn' => TRUE,
+ ]);
+ }
+
// Add customer ID if available (optional for one-off payments)
$contactId = $params['contactID'] ?? $params['contact_id'] ?? NULL;
if ($contactId) {
@@ -1191,15 +1231,19 @@ public function cancelSquareSubscription(string $subscriptionId): void {
}
/**
- * Whether processor supports back-office (admin) payments.
+ * Whether staff can take card payments with this processor on back-office forms.
*
- * For now, we only support front-end Web Payments SDK tokenization.
+ * They can: CiviCRM's back-office contribution, membership, event
+ * registration and "Submit Credit Card Payment" forms show Square's card
+ * form just as the front end does. Staff key in the payer's card, so
+ * js/square.js and doOneTimePayment() flag those payments to Square as
+ * Mail Order / Telephone Order (MOTO), and Square does not ask staff to
+ * verify as the buyer.
*
* @return bool
*/
public function supportsBackOffice() {
- // You can change this to TRUE if you later support card entry in admin UI.
- return FALSE;
+ return TRUE;
}
/**
diff --git a/CRM/Square/Subscriptions.php b/CRM/Square/Subscriptions.php
index 79687ec..ad2fd26 100644
--- a/CRM/Square/Subscriptions.php
+++ b/CRM/Square/Subscriptions.php
@@ -121,7 +121,8 @@ public function __construct(CRM_Square_Gateway $gateway) {
public function getPlanVariationIdForParams(array $params): string {
$entity = $params['component'] ?? 'contribute';
$amount = (float) ($params['amount'] ?? 0);
- $currency = $params['currency'] ?? 'USD';
+ // CiviCRM's back-office membership form passes only currencyID.
+ $currency = $params['currency'] ?? $params['currencyID'] ?? 'USD';
$intervalUnit = $params['frequency_unit'] ?? '';
$intervalStep = (int) ($params['frequency_interval'] ?? 1);
$installments = (int) ($params['installments'] ?? 0);
diff --git a/README.md b/README.md
index 8346722..a6c2185 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,7 @@ required after cloning/downloading — just enable the extension as usual
- Refunds via Square Refunds API (`/v2/refunds`), recorded in CiviCRM once Square completes them
- Subscription cancellation and amount changes synced to Square, and cancellations made in Square synced back to CiviCRM
- Donors can replace the card a recurring contribution is charged to (CiviCRM's **Update billing details**)
+- Back-office card payments: staff can take one-time and recurring payments on CiviCRM's **Submit Credit Card Contribution / Membership / Event Registration** and **Submit Credit Card Payment** forms, flagged to Square as keyed in by the seller (MOTO)
- Square Web Payments SDK for browser-side card tokenization — card details never pass through CiviCRM
- Card form ZIP/postal code kept in step with the billing address's, so Square never sees two different ones
- Card-on-file support through CiviCRM PaymentToken
@@ -150,8 +151,9 @@ deletes its mappings.
- CiviCRM native contribution pages and event registration forms
- Drupal Webform (webform_civicrm module) billing blocks, including AJAX reloads
+- CiviCRM's back-office credit card forms (contribution, membership signup and renewal, event registration, and **Submit Credit Card Payment** on an existing contribution), on a page or in a popup
-Back-office (staff-entered) card payments are not supported.
+On a back-office form staff key in the payer's card, so the payment is a Mail Order / Telephone Order (MOTO) one: `card.tokenize()` is told `customerInitiated: false` and `sellerKeyedIn: true` (Square then does not ask staff to verify as the buyer), and `CreatePayment` sends the same as its `customer_details`. CiviCRM's **Submit Credit Card Payment** form passes no invoice or contribution reference, so that payment's idempotency key is derived from its single-use card token instead; front-end checkouts without a reference are still refused. When staff switch the form to another payment processor, `square.js` stops handling the form's submit buttons, leaving them to that processor.
Key globals:
- `CRM.squarePayment` — Square's namespaced integration state
diff --git a/docs/OVERVIEW.html b/docs/OVERVIEW.html
index 357a511..a768255 100644
--- a/docs/OVERVIEW.html
+++ b/docs/OVERVIEW.html
@@ -340,7 +340,7 @@
Square Payment Processor
Overview
What this extension does
- org.civicrm.square registers Square as a CiviCRM payment processor type — the same role Stripe or PayPal extensions play — so contribution pages, event registration, and Drupal webforms can charge a Square-issued card without CiviCRM ever seeing the card number.
+ org.civicrm.square registers Square as a CiviCRM payment processor type — the same role Stripe or PayPal extensions play — so contribution pages, event registration, Drupal webforms, and staff on CiviCRM's back-office credit card forms can charge a Square-issued card without CiviCRM ever seeing the card number.
It depends on two core CiviCRM extensions, mjwshared and civi_contribute, and is built against CiviCRM 6.16 or later. Composer dependencies ship committed in vendor/, so installing it is a normal extension enable — no build step. It is developed and maintained by Skvare, distributed under AGPL-3.0-or-later.
Why it exists: Needed dues, tournament entry, and donation payments to run through Square rather than the processors CiviCRM ships with out of the box, with the same card-on-file and recurring-billing experience members already expect from CiviCRM's native processors.
@@ -444,7 +444,7 @@ Components
| CRM/Core/Payment/SquareIPN.php | Webhook filtering, signature verification, deduplication, queue persistence, processing. |
| CRM/Core/Payment/SquareDebugLogger.php | Opt-in diagnostic logging, gated by a setting so it's off by default. |
| CRM/Square/Upgrader.php | Creates square_customer_map and square_catalog_map, and drops them on uninstall. |
- | js/square.js | Mounts the Square card element and tokenizes on submit, across native and Webform forms; keeps the card form's ZIP in step with the billing address's. |
+ | js/square.js | Mounts the Square card element and tokenizes on submit, across native, Webform and back-office forms (flagging staff-keyed cards as MOTO); keeps the card form's ZIP in step with the billing address's. |
| managed/PaymentProcessorType.mgd.php | Registers "Square" as a selectable payment processor type. |
diff --git a/docs/WORKFLOWS.md b/docs/WORKFLOWS.md
index 8dbf58a..0bc7a5c 100644
--- a/docs/WORKFLOWS.md
+++ b/docs/WORKFLOWS.md
@@ -18,6 +18,15 @@ checkout: Square charges the first installment itself, within seconds.

+## Back-office payments
+
+Staff use the same two flows on CiviCRM's back-office credit card forms, keying
+in the payer's card. Square is told the payment is keyed in by the seller (MOTO),
+both when the card is tokenized and in `CreatePayment`, so it does not ask staff
+to verify as the buyer. **Submit Credit Card Payment**, which adds a payment to
+an existing contribution, has no invoice reference of its own: its idempotency
+key comes from the single-use card token instead.
+
## Subscription installment webhooks
The events Square sends for each installment, paid or declined, and how
diff --git a/js/square.js b/js/square.js
index aa0376c..b5c3506 100644
--- a/js/square.js
+++ b/js/square.js
@@ -5,7 +5,9 @@
* Supports:
* - CiviCRM native contribution pages and event registration forms
* - Drupal Webform (webform_civicrm module) billing blocks
- * - Backend contribution / event forms
+ * - Back-office contribution, membership, event registration and payment
+ * forms, on a page or in a popup, where staff key in the payer's card
+ * (flagged to Square as MOTO)
*
* Architecture mirrors Stripe (civicrmStripe.js) and AuthNet (civicrmAuthNetAccept.js):
* - CRM.squarePayment — shared form-utility object (equivalent to CRM.payment in mjwshared)
@@ -166,7 +168,11 @@
$(this).closest('div').next('div').find('input[type="checkbox"]').addClass('required');
});
$('div#priceset input[type="checkbox"], fieldset.crm-profile input[type="checkbox"], #on-behalf-block input[type="checkbox"]').each(function() {
- var name = $(this).attr('name');
+ // The original name, if an earlier call (or another processor's
+ // script) already renamed the checkbox: the billing block, and so
+ // this, is reloaded whenever the processor or amount changes.
+ var name = $(this).attr('data-name') || $(this).attr('name');
+ if (!name) return;
$(this).attr('data-name', name);
$(this).attr('name', name.replace('[' + name.split('[').pop(), ''));
});
@@ -188,6 +194,18 @@
for (var i = 0; i < this.submitButtons.length; ++i) {
this.submitButtons[i].setAttribute('disabled', true);
}
+ this.submitForm();
+ },
+
+ /**
+ * Submit the billing form, bypassing its submit event handlers.
+ *
+ * CiviCRM turns off its "You have unsaved changes" warning in a submit
+ * event handler, which form.submit() does not fire. Back-office forms
+ * warn of unsaved changes, so turn it off here, as that handler would.
+ */
+ submitForm: function() {
+ $('[data-warn-changes]').attr('data-warn-changes', 'false');
this.resetBillingFieldsRequiredForJQueryValidate();
this.form.submit();
},
@@ -342,6 +360,9 @@
cardPostalCode: '',
// The value this script last copied into the billing postal code field.
autofilledPostalCode: null,
+ // Whether this script renamed the form's checkboxes for jQuery
+ // validation (see setBillingFieldsRequiredForJQueryValidate()).
+ billingFieldsAdjusted: false,
billingPostalCodePattern: /billing_postal_code(-\d+)?\]?$/,
debugging: function(msg) {
@@ -358,6 +379,7 @@
currency: cfg.currency || 'USD',
countryIsoCodes: cfg.countryIsoCodes || {},
isCardUpdate: !!cfg.isCardUpdate,
+ isBackOffice: !!cfg.isBackOffice,
};
},
@@ -416,6 +438,10 @@
* STORE, as is a card update's. Square refuses an amount or currency for
* STORE ("The STORE intent does not support the amount field."), even an
* empty one: only CHARGE has them.
+ *
+ * On a back-office form staff key in the payer's card: a Mail Order /
+ * Telephone Order (MOTO) payment, which the payer did not initiate
+ * there. Square then does not ask staff to verify as the buyer.
*/
getVerificationDetails: function(totalAmount) {
var cfg = script.getConfig();
@@ -446,8 +472,8 @@
var details = {
billingContact: contact,
intent: script.isRecurring() ? 'STORE' : 'CHARGE',
- customerInitiated: true,
- sellerKeyedIn: false
+ customerInitiated: !cfg.isBackOffice,
+ sellerKeyedIn: cfg.isBackOffice
};
if (details.intent === 'CHARGE') {
details.amount = Number(totalAmount || 0).toFixed(2);
@@ -595,6 +621,18 @@
if (typeof CRM.vars !== 'undefined') {
delete CRM.vars.orgCivicrmSquare;
}
+ // Step aside for the processor now selected (e.g. another one in a
+ // back-office form's processor list): its own script, or CiviCRM,
+ // submits the form, with the checkboxes' own names.
+ var form = CRM.squarePayment.form;
+ if (form) {
+ $('[type=submit]', form).off('click.square click.squareWebform');
+ $(form).off('change.squarePostalCode keydown.squareWebform');
+ }
+ if (script.billingFieldsAdjusted) {
+ CRM.squarePayment.resetBillingFieldsRequiredForJQueryValidate();
+ script.billingFieldsAdjusted = false;
+ }
if (CRM.squarePayment.submitButtons) {
$(CRM.squarePayment.submitButtons).show();
}
@@ -668,6 +706,7 @@
doAfterElementsHaveLoaded: function() {
CRM.squarePayment.setBillingFieldsRequiredForJQueryValidate();
+ script.billingFieldsAdjusted = true;
CRM.squarePayment.form.dataset.submitdontprocess = 'false';
CRM.squarePayment.addHandlerNonPaymentSubmitButtons();
@@ -678,7 +717,9 @@
function submitButtonClick(clickEvent) {
if (typeof CRM.vars === 'undefined' || typeof CRM.vars.orgCivicrmSquare === 'undefined') {
- return CRM.squarePayment.doStandardFormSubmit();
+ // Square is no longer the selected processor: leave the submit
+ // to the form, or to that processor's own script.
+ return;
}
CRM.squarePayment.form.dataset.submitdontprocess = 'false';
return script.submit(clickEvent);
@@ -857,8 +898,7 @@
}
tokenField.value = result.token;
- CRM.squarePayment.resetBillingFieldsRequiredForJQueryValidate();
- CRM.squarePayment.form.submit();
+ CRM.squarePayment.submitForm();
}
catch(e) {
// Logged whatever the debug setting: otherwise nothing says what failed.
@@ -953,4 +993,15 @@
}
};
+ // Loaded with a billing block that arrived after the page did, e.g. a
+ // back-office form opened in a popup: DOMContentLoaded has fired already,
+ // and the request that brought it (such as civicrm/payment/add or
+ // civicrm/contribute/updatebilling) may not be one isAJAXPaymentForm()
+ // knows. Initialized now, as a reload is above; one that request does
+ // trigger is skipped while this one is still mounting the card form.
+ if (document.readyState !== 'loading') {
+ CRM.squarePayment.debugging(script.name, 'loaded after the page');
+ load();
+ }
+
}(CRM.$, CRM.ts('org.civicrm.square')));
diff --git a/tests/phpunit/CRM/Core/Payment/Square/RequestShapeTest.php b/tests/phpunit/CRM/Core/Payment/Square/RequestShapeTest.php
index de30f0f..642141e 100644
--- a/tests/phpunit/CRM/Core/Payment/Square/RequestShapeTest.php
+++ b/tests/phpunit/CRM/Core/Payment/Square/RequestShapeTest.php
@@ -51,12 +51,49 @@ public function testOneTimePaymentRequestShape(): void {
$this->assertSame('location-id', $captured->getLocationId());
$this->assertSame('inv-42', $captured->getReferenceId());
$this->assertNull($captured->getCustomerId(), 'No contactID was supplied, so no customer lookup/attachment should occur.');
+ $this->assertNull($captured->getCustomerDetails(), 'The payer entered the card: not a MOTO payment.');
$this->assertNotEmpty($captured->getIdempotencyKey());
$this->assertLessThanOrEqual(45, strlen($captured->getIdempotencyKey()));
$this->assertSame('pay_1', $result['trxn_id']);
}
+ public function testBackOfficePaymentIsFlaggedAsKeyedInBySeller(): void {
+ [$processor, $captured] = $this->paymentRecordingProcessor();
+ $processor->setBackOffice(TRUE);
+ $params = [
+ 'square_payment_token' => 'cnon:staff',
+ 'amount' => '20.00',
+ 'currency' => 'USD',
+ 'invoiceID' => 'inv-staff',
+ ];
+ $processor->doPayment($params);
+
+ $customerDetails = $captured[0]->getCustomerDetails();
+ $this->assertNotNull($customerDetails);
+ $this->assertFalse($customerDetails->getCustomerInitiated());
+ $this->assertTrue($customerDetails->getSellerKeyedIn());
+ }
+
+ /**
+ * CiviCRM's back-office "Submit Credit Card Payment" form passes no reference.
+ */
+ public function testBackOfficePaymentWithoutACheckoutReferenceIsKeyedOnItsCardToken(): void {
+ [$processor, $captured] = $this->paymentRecordingProcessor();
+ $processor->setBackOffice(TRUE);
+ foreach (['cnon:first', 'cnon:first', 'cnon:second'] as $token) {
+ $params = ['square_payment_token' => $token, 'amount' => '5.00', 'currency' => 'USD'];
+ $result = $processor->doPayment($params);
+ $this->assertSame('pay_' . count($captured), $result['trxn_id']);
+ }
+
+ $this->assertCount(3, $captured);
+ $this->assertSame($captured[0]->getIdempotencyKey(), $captured[1]->getIdempotencyKey(), 'A re-posted form carries the same token, so Square sees a retry.');
+ $this->assertNotSame($captured[0]->getIdempotencyKey(), $captured[2]->getIdempotencyKey(), 'A new card token is a new payment.');
+ $this->assertLessThanOrEqual(45, strlen($captured[2]->getIdempotencyKey()));
+ $this->assertNull($captured[0]->getReferenceId());
+ }
+
public function testOneTimePaymentInACurrencyWithoutCentsIsNotMultiplied(): void {
$captured = NULL;
$paymentsMock = $this->createMock(PaymentsClient::class);
@@ -89,6 +126,11 @@ public function testOneTimePaymentOmitsReferenceIdWhenNoInvoiceId(): void {
$this->assertNull($captured->getReferenceId());
}
+ /**
+ * Only back-office forms may omit it.
+ *
+ * See testBackOfficePaymentWithoutACheckoutReferenceIsKeyedOnItsCardToken().
+ */
public function testOneTimePaymentFailsClosedWithoutACheckoutReference(): void {
$paymentsMock = $this->createMock(PaymentsClient::class);
$paymentsMock->expects($this->never())->method('create');
@@ -170,6 +212,24 @@ public function testRefundIdempotencyKeyDistinguishesRepeatedRefundsOfTheSameAmo
$this->assertNotSame($first[0]->getIdempotencyKey(), $second[0]->getIdempotencyKey());
}
+ /**
+ * A processor with a mocked Square, capturing payment requests.
+ *
+ * @return array
+ * The processor, and an \ArrayObject receiving each CreatePaymentRequest
+ * sent. Square answers the Nth with COMPLETED payment pay_N.
+ */
+ private function paymentRecordingProcessor(): array {
+ $captured = new ArrayObject();
+ $paymentsMock = $this->createMock(PaymentsClient::class);
+ $paymentsMock->method('create')->willReturnCallback(function (CreatePaymentRequest $request) use ($captured) {
+ $captured[] = $request;
+ $payment = new Payment(['id' => 'pay_' . count($captured), 'status' => 'COMPLETED']);
+ return new CreatePaymentResponse(['payment' => $payment]);
+ });
+ return [$this->processorWithMockClient(['payments' => $paymentsMock]), $captured];
+ }
+
/**
* A processor with a mocked Square, capturing refund requests.
*
diff --git a/tests/phpunit/CRM/Core/Payment/Square/SubscriptionsTest.php b/tests/phpunit/CRM/Core/Payment/Square/SubscriptionsTest.php
index 0cdad5c..1444edb 100644
--- a/tests/phpunit/CRM/Core/Payment/Square/SubscriptionsTest.php
+++ b/tests/phpunit/CRM/Core/Payment/Square/SubscriptionsTest.php
@@ -56,6 +56,17 @@ public function testFiniteSubscriptionHasOnePeriodPerInstallment(): void {
$this->assertSame('USD', $phase->getPricing()->getPriceMoney()->getCurrency());
}
+ /**
+ * CiviCRM's back-office membership form names the currency currencyID.
+ */
+ public function testPlanIsPricedInCurrencyIdWhenNoCurrencyIsGiven(): void {
+ $params = $this->params(['currencyID' => 'CAD']);
+ unset($params['currency']);
+ $this->subscriptions()->getPlanVariationIdForParams($params);
+
+ $this->assertSame('CAD', $this->onlyPhase()->getPricing()->getPriceMoney()->getCurrency());
+ }
+
/**
* An open-ended one sends no periods at all (0 would mean no periods).
*
diff --git a/tests/phpunit/CRM/Core/Payment/SquareTest.php b/tests/phpunit/CRM/Core/Payment/SquareTest.php
index f94bac4..13accde 100644
--- a/tests/phpunit/CRM/Core/Payment/SquareTest.php
+++ b/tests/phpunit/CRM/Core/Payment/SquareTest.php
@@ -172,6 +172,59 @@ public function assign($name, $value) {
$this->assertSame('', json_decode($form->assigned['squareJSVarsJson'], TRUE)['locationId']);
}
+ public function testStaffCanTakeCardPaymentsOnBackOfficeForms(): void {
+ $this->assertTrue($this->processor()->supportsBackOffice());
+ }
+
+ /**
+ * The card form (js/square.js) learns whether staff key in the card.
+ *
+ * It then flags the payment to Square as keyed in by the seller (MOTO).
+ *
+ * @dataProvider backOfficeFormProvider
+ */
+ public function testBuildFormTellsTheCardFormWhetherStaffEnterTheCard(?bool $formIsBackOffice, bool $processorIsBackOffice, bool $expected): void {
+ $processor = $this->processor();
+ $processor->setBackOffice($processorIsBackOffice);
+ $form = new class() {
+
+ /**
+ * As CiviCRM's payment forms declare it; NULL for a form that does not.
+ *
+ * @var bool|null
+ */
+ public ?bool $isBackOffice = NULL;
+
+ /**
+ * @var array
+ */
+ public array $assigned = [];
+
+ public function elementExists($name) {
+ return TRUE;
+ }
+
+ public function assign($name, $value) {
+ $this->assigned[$name] = $value;
+ }
+
+ };
+ $form->isBackOffice = $formIsBackOffice;
+
+ $processor->buildForm($form);
+
+ $this->assertSame($expected, json_decode($form->assigned['squareJSVarsJson'], TRUE)['isBackOffice']);
+ }
+
+ public static function backOfficeFormProvider(): array {
+ return [
+ 'back-office form' => [TRUE, FALSE, TRUE],
+ 'front-end form' => [FALSE, TRUE, FALSE],
+ 'form that does not say, processor set for back office' => [NULL, TRUE, TRUE],
+ 'form that does not say, processor not set' => [NULL, FALSE, FALSE],
+ ];
+ }
+
/**
* A processor whose Square refund comes back with the given statuses.
*
diff --git a/tests/phpunit/bootstrap.php b/tests/phpunit/bootstrap.php
index a925f0f..55534c1 100644
--- a/tests/phpunit/bootstrap.php
+++ b/tests/phpunit/bootstrap.php
@@ -46,6 +46,31 @@ abstract class CRM_Core_Payment {
// phpcs:ignore Drupal.NamingConventions.ValidVariableName, PSR2.Classes.PropertyDeclaration.Underscore
protected $_component;
+ /**
+ * Whether staff are taking the payment on a back-office form.
+ *
+ * @var bool
+ */
+ protected $backOffice = FALSE;
+
+ /**
+ * As core's.
+ *
+ * @return bool
+ */
+ public function isBackOffice() {
+ return $this->backOffice;
+ }
+
+ /**
+ * As core's.
+ *
+ * @param bool $isBackOffice
+ */
+ public function setBackOffice($isBackOffice) {
+ $this->backOffice = $isBackOffice;
+ }
+
}
}
if (!class_exists('CRM_Core_Exception')) {