2 namespace Civi\Payment
;
4 use InvalidArgumentException
;
6 use CRM_Core_PseudoConstant
;
11 * This class provides getters and setters for arguments needed by CRM_Core_Payment methods.
13 * The setters know how to validate each setting that they are responsible for.
15 * Different methods need different settings and the concept is that by passing
16 * in a property bag we can encapsulate the params needed for a particular
17 * method call, rather than setting arguments for different methods on the main
18 * CRM_Core_Payment object.
20 * This class is also supposed to help with transition away from array key naming nightmares.
23 class PropertyBag
implements \ArrayAccess
{
25 protected $props = ['default' => []];
27 protected static $propMap = [
28 'billingStreetAddress' => TRUE,
29 'billingSupplementalAddress1' => TRUE,
30 'billingSupplementalAddress2' => TRUE,
31 'billingSupplementalAddress3' => TRUE,
32 'billingCity' => TRUE,
33 'billingPostalCode' => TRUE,
34 'billingCounty' => TRUE,
35 'billingCountry' => TRUE,
37 'contact_id' => 'contactID',
38 'contributionID' => TRUE,
39 'contribution_id' => 'contributionID',
40 'contributionRecurID' => TRUE,
41 'contribution_recur_id' => 'contributionRecurID',
43 'currencyID' => 'currency',
44 'description' => TRUE,
47 'fee_amount' => 'feeAmount',
48 'first_name' => 'firstName',
51 'invoice_id' => 'invoiceID',
52 'isBackOffice' => TRUE,
53 'is_back_office' => 'isBackOffice',
55 'is_recur' => 'isRecur',
56 'last_name' => 'lastName',
58 'paymentToken' => TRUE,
59 'payment_token' => 'paymentToken',
61 'recurFrequencyInterval' => TRUE,
62 'frequency_interval' => 'recurFrequencyInterval',
63 'recurFrequencyUnit' => TRUE,
64 'frequency_unit' => 'recurFrequencyUnit',
65 'subscriptionId' => 'recurProcessorID',
66 'recurProcessorID' => TRUE,
67 'transactionID' => TRUE,
68 'transaction_id' => 'transactionID',
69 'trxnResultCode' => TRUE,
70 'isNotifyProcessorOnCancelRecur' => TRUE,
76 * Temporary, internal variable to help ease transition to PropertyBag.
77 * Used by cast() to suppress legacy warnings.
79 protected $suppressLegacyWarnings = FALSE;
82 * Get the property bag.
84 * This allows us to swap a 'might be an array might be a property bag'
85 * variable for a known PropertyBag.
87 * @param \Civi\Payment\PropertyBag|array $params
89 * @return \Civi\Payment\PropertyBag
91 public static function cast($params) {
92 if ($params instanceof self
) {
95 $propertyBag = new self();
96 $propertyBag->mergeLegacyInputParams($params);
101 * Just for unit testing.
108 * Implements ArrayAccess::offsetExists
110 * @param mixed $offset
111 * @return bool TRUE if we have that value (on our default store)
113 public function offsetExists ($offset): bool {
114 $prop = $this->handleLegacyPropNames($offset, TRUE);
115 // If there's no prop, assume it's a custom property.
116 $prop = $prop ??
$offset;
117 return array_key_exists($prop, $this->props
['default']);
121 * Implements ArrayAccess::offsetGet
123 * @param mixed $offset
126 public function offsetGet($offset) {
128 $prop = $this->handleLegacyPropNames($offset);
130 catch (InvalidArgumentException
$e) {
132 CRM_Core_Error
::deprecatedFunctionWarning(
133 "proper getCustomProperty('$offset') for non-core properties. "
135 "PropertyBag array access to get '$offset'"
139 return $this->getCustomProperty($offset, 'default');
141 catch (BadMethodCallException
$e) {
142 CRM_Core_Error
::deprecatedFunctionWarning(
143 "proper setCustomProperty('$offset', \$value) to store the value (since it is not a core value), then access it with getCustomProperty('$offset'). NULL is returned but in future an exception will be thrown."
145 "PropertyBag array access to get unset property '$offset'"
151 CRM_Core_Error
::deprecatedFunctionWarning(
152 "get" . ucfirst($offset) . "()",
153 "PropertyBag array access for core property '$offset'"
155 return $this->get($prop, 'default');
159 * Implements ArrayAccess::offsetSet
161 * @param mixed $offset
162 * @param mixed $value
164 public function offsetSet($offset, $value) {
166 $prop = $this->handleLegacyPropNames($offset);
168 catch (InvalidArgumentException
$e) {
169 // We need to make a lot of noise here, we're being asked to merge in
170 // something we can't validate because we don't know what this property is.
171 // This is fine if it's something particular to a payment processor
172 // (which should be using setCustomProperty) however it could also lead to
173 // things like 'my_weirly_named_contact_id'.
175 // From 5.28 we suppress this when using PropertyBag::cast() to ease transition.
176 if (!$this->suppressLegacyWarnings
) {
177 CRM_Core_Error
::deprecatedFunctionWarning(
178 "proper setCustomProperty('$offset', \$value) for non-core properties. "
180 "PropertyBag array access to set '$offset'"
183 $this->setCustomProperty($offset, $value, 'default');
187 // Coerce legacy values that were in use but shouldn't be in our new way of doing things.
188 if ($prop === 'feeAmount' && $value === '') {
189 // At least the following classes pass in ZLS for feeAmount.
190 // CRM_Core_Payment_AuthorizeNetTest::testCreateSingleNowDated
191 // CRM_Core_Payment_AuthorizeNetTest::testCreateSinglePostDated
195 // These lines are here (and not in try block) because the catch must only
196 // catch the case when the prop is custom.
197 $setter = 'set' . ucfirst($prop);
198 if (!$this->suppressLegacyWarnings
) {
199 CRM_Core_Error
::deprecatedFunctionWarning(
201 "PropertyBag array access to set core property '$offset'"
204 $this->$setter($value, 'default');
208 * Implements ArrayAccess::offsetUnset
210 * @param mixed $offset
212 public function offsetUnset ($offset) {
213 $prop = $this->handleLegacyPropNames($offset);
214 unset($this->props
['default'][$prop]);
218 * @param string $prop
219 * @param bool $silent if TRUE return NULL instead of throwing an exception. This is because offsetExists should be safe and not throw exceptions.
220 * @return string canonical name.
221 * @throws \InvalidArgumentException if prop name not known.
223 protected function handleLegacyPropNames($prop, $silent = FALSE) {
224 $newName = static::$propMap[$prop] ??
NULL;
225 if ($newName === TRUE) {
226 // Good, modern name.
229 // Handling for legacy addition of billing details.
230 if ($newName === NULL && substr($prop, -2) === '-' . \CRM_Core_BAO_LocationType
::getBilling()
231 && isset(static::$propMap[substr($prop, 0, -2)])
233 $newName = substr($prop, 0, -2);
236 if ($newName === NULL) {
238 // Only for use by offsetExists
241 throw new \
InvalidArgumentException("Unknown property '$prop'.");
243 // Remaining case is legacy name that's been translated.
244 if (!$this->suppressLegacyWarnings
) {
245 CRM_Core_Error
::deprecatedFunctionWarning("Canonical property name '$newName'", "Legacy property name '$prop'");
254 * @param mixed $prop Valid property name
255 * @param string $label e.g. 'default'
259 protected function get($prop, $label) {
260 if (array_key_exists($prop, $this->props
[$label] ??
[])) {
261 return $this->props
[$label][$prop];
263 throw new \
BadMethodCallException("Property '$prop' has not been set.");
269 * @param mixed $prop Valid property name
270 * @param string $label e.g. 'default'
271 * @param mixed $value
273 * @return PropertyBag $this object so you can chain set setters.
275 protected function set($prop, $label = 'default', $value) {
276 $this->props
[$label][$prop] = $value;
283 protected function coercePseudoConstantStringToInt(string $baoName, string $field, $input) {
284 if (is_numeric($input)) {
285 // We've been given a numeric ID.
288 elseif (is_string($input)) {
289 // We've been given a named instrument.
290 $_ = (int) CRM_Core_PseudoConstant
::getKey($baoName, $field, $input);
293 throw new InvalidArgumentException("Expected an integer ID or a String name for $field.");
296 throw new InvalidArgumentException("Expected an integer greater than 0 for $field.");
303 public function has($prop, $label = 'default') {
304 // We do NOT translate legacy prop names since only new code should be
305 // using this method, and new code should be using canonical names.
306 // $prop = $this->handleLegacyPropNames($prop);
307 return isset($this->props
[$label][$prop]);
311 * This is used to merge values from an array.
312 * It's a transitional, internal function and should not be used!
316 public function mergeLegacyInputParams($data) {
317 // Suppress legacy warnings for merging an array of data as this
318 // suits our migration plan at this moment. Future behaviour may differ.
319 // @see https://github.com/civicrm/civicrm-core/pull/17643
320 $this->suppressLegacyWarnings
= TRUE;
321 foreach ($data as $key => $value) {
322 if ($value !== NULL && $value !== '') {
323 $this->offsetSet($key, $value);
326 $this->suppressLegacyWarnings
= FALSE;
330 * Throw an exception if any of the props is unset.
332 * @param array $props Array of proper property names (no legacy aliases allowed).
334 * @return PropertyBag
336 public function require(array $props) {
338 foreach ($props as $prop) {
339 if (!isset($this->props
['default'][$prop])) {
344 throw new \
InvalidArgumentException("Required properties missing: " . implode(', ', $missing));
349 // Public getters, setters.
352 * Get a property by its name (but still using its getter).
354 * @param string $prop valid property name, like contactID
355 * @param bool $allowUnset If TRUE, return the default value if the property is
356 * not set - normal behaviour would be to throw an exception.
357 * @param mixed $default
358 * @param string $label e.g. 'default' or 'old' or 'new'
362 public function getter($prop, $allowUnset = FALSE, $default = NULL, $label = 'default') {
364 if ((static::$propMap[$prop] ??
NULL) === TRUE) {
365 // This is a standard property that will have a getter method.
366 $getter = 'get' . ucfirst($prop);
367 return (!$allowUnset ||
$this->has($prop, $label))
368 ?
$this->$getter($label)
372 // This is not a property name we know, but they could be requesting a
374 return (!$allowUnset ||
$this->has($prop, $label))
375 ?
$this->getCustomProperty($prop, $label)
380 * Set a property by its name (but still using its setter).
382 * @param string $prop valid property name, like contactID
383 * @param mixed $value
384 * @param string $label e.g. 'default' or 'old' or 'new'
388 public function setter($prop, $value = NULL, $label = 'default') {
389 if ((static::$propMap[$prop] ??
NULL) === TRUE) {
390 // This is a standard property.
391 $setter = 'set' . ucfirst($prop);
392 return $this->$setter($value, $label);
394 // We don't allow using the setter for custom properties.
395 throw new \
BadMethodCallException("Cannot use generic setter with non-standard properties; you must use setCustomProperty for custom properties.");
399 * Get the monetary amount.
401 public function getAmount($label = 'default') {
402 return $this->get('amount', $label);
406 * Set the monetary amount.
408 * - We expect to be called with a string amount with optional decimals using
409 * a '.' as the decimal point (not a ',').
411 * - We're ok with floats/ints being passed in, too, but we'll cast them to a
414 * - Negatives are fine.
416 * @see https://github.com/civicrm/civicrm-core/pull/18219
418 * @param string|float|int $value
419 * @param string $label
421 public function setAmount($value, $label = 'default') {
422 if (!is_numeric($value)) {
423 throw new \
InvalidArgumentException("setAmount requires a numeric amount value");
425 return $this->set('amount', $label, filter_var($value, FILTER_SANITIZE_NUMBER_FLOAT
, FILTER_FLAG_ALLOW_FRACTION
));
429 * BillingStreetAddress getter.
433 public function getBillingStreetAddress($label = 'default') {
434 return $this->get('billingStreetAddress', $label);
438 * BillingStreetAddress setter.
440 * @param string $input
441 * @param string $label e.g. 'default'
443 public function setBillingStreetAddress($input, $label = 'default') {
444 return $this->set('billingStreetAddress', $label, (string) $input);
448 * BillingSupplementalAddress1 getter.
452 public function getBillingSupplementalAddress1($label = 'default') {
453 return $this->get('billingSupplementalAddress1', $label);
457 * BillingSupplementalAddress1 setter.
459 * @param string $input
460 * @param string $label e.g. 'default'
462 public function setBillingSupplementalAddress1($input, $label = 'default') {
463 return $this->set('billingSupplementalAddress1', $label, (string) $input);
467 * BillingSupplementalAddress2 getter.
471 public function getBillingSupplementalAddress2($label = 'default') {
472 return $this->get('billingSupplementalAddress2', $label);
476 * BillingSupplementalAddress2 setter.
478 * @param string $input
479 * @param string $label e.g. 'default'
481 public function setBillingSupplementalAddress2($input, $label = 'default') {
482 return $this->set('billingSupplementalAddress2', $label, (string) $input);
486 * BillingSupplementalAddress3 getter.
490 public function getBillingSupplementalAddress3($label = 'default') {
491 return $this->get('billingSupplementalAddress3', $label);
495 * BillingSupplementalAddress3 setter.
497 * @param string $input
498 * @param string $label e.g. 'default'
500 public function setBillingSupplementalAddress3($input, $label = 'default') {
501 return $this->set('billingSupplementalAddress3', $label, (string) $input);
505 * BillingCity getter.
509 public function getBillingCity($label = 'default') {
510 return $this->get('billingCity', $label);
514 * BillingCity setter.
516 * @param string $input
517 * @param string $label e.g. 'default'
519 * @return \Civi\Payment\PropertyBag
521 public function setBillingCity($input, $label = 'default') {
522 return $this->set('billingCity', $label, (string) $input);
526 * BillingPostalCode getter.
530 public function getBillingPostalCode($label = 'default') {
531 return $this->get('billingPostalCode', $label);
535 * BillingPostalCode setter.
537 * @param string $input
538 * @param string $label e.g. 'default'
540 public function setBillingPostalCode($input, $label = 'default') {
541 return $this->set('billingPostalCode', $label, (string) $input);
545 * BillingCounty getter.
549 public function getBillingCounty($label = 'default') {
550 return $this->get('billingCounty', $label);
554 * BillingCounty setter.
556 * Nb. we can't validate this unless we have the country ID too, so we don't.
558 * @param string $input
559 * @param string $label e.g. 'default'
561 public function setBillingCounty($input, $label = 'default') {
562 return $this->set('billingCounty', $label, (string) $input);
566 * BillingCountry getter.
570 public function getBillingCountry($label = 'default') {
571 return $this->get('billingCountry', $label);
575 * BillingCountry setter.
577 * Nb. We require and we store a 2 character country code.
579 * @param string $input
580 * @param string $label e.g. 'default'
582 public function setBillingCountry($input, $label = 'default') {
583 if (!is_string($input) ||
strlen($input) !== 2) {
584 throw new \
InvalidArgumentException("setBillingCountry expects ISO 3166-1 alpha-2 country code.");
586 if (!CRM_Core_PseudoConstant
::getKey('CRM_Core_BAO_Address', 'country_id', $input)) {
587 throw new \
InvalidArgumentException("setBillingCountry expects ISO 3166-1 alpha-2 country code.");
589 return $this->set('billingCountry', $label, (string) $input);
595 public function getContactID($label = 'default'): int {
596 return $this->get('contactID', $label);
600 * @param int $contactID
601 * @param string $label
603 public function setContactID($contactID, $label = 'default') {
604 // We don't use this because it counts zero as positive: CRM_Utils_Type::validate($contactID, 'Positive');
605 if (!($contactID > 0)) {
606 throw new InvalidArgumentException("ContactID must be a positive integer");
609 return $this->set('contactID', $label, (int) $contactID);
613 * Getter for contributionID.
616 * @param string $label
618 public function getContributionID($label = 'default') {
619 return $this->get('contributionID', $label);
623 * @param int $contributionID
624 * @param string $label e.g. 'default'
626 public function setContributionID($contributionID, $label = 'default') {
627 // We don't use this because it counts zero as positive: CRM_Utils_Type::validate($contactID, 'Positive');
628 if (!($contributionID > 0)) {
629 throw new InvalidArgumentException("ContributionID must be a positive integer");
632 return $this->set('contributionID', $label, (int) $contributionID);
636 * Getter for contributionRecurID.
639 * @param string $label
641 public function getContributionRecurID($label = 'default') {
642 return $this->get('contributionRecurID', $label);
646 * @param int $contributionRecurID
647 * @param string $label e.g. 'default'
649 * @return \Civi\Payment\PropertyBag
651 public function setContributionRecurID($contributionRecurID, $label = 'default') {
652 // We don't use this because it counts zero as positive: CRM_Utils_Type::validate($contactID, 'Positive');
653 if (!($contributionRecurID > 0)) {
654 throw new InvalidArgumentException('ContributionRecurID must be a positive integer');
657 return $this->set('contributionRecurID', $label, (int) $contributionRecurID);
661 * Three character currency code.
663 * https://en.wikipedia.org/wiki/ISO_3166-1_alpha-3
665 * @param string $label e.g. 'default'
667 public function getCurrency($label = 'default') {
668 return $this->get('currency', $label);
672 * Three character currency code.
674 * @param string $value
675 * @param string $label e.g. 'default'
677 public function setCurrency($value, $label = 'default') {
678 if (!preg_match('/^[A-Z]{3}$/', $value)) {
679 throw new \
InvalidArgumentException("Attemted to setCurrency with a value that was not an ISO 3166-1 alpha 3 currency code");
681 return $this->set('currency', $label, $value);
686 * @param string $label
690 public function getDescription($label = 'default') {
691 return $this->get('description', $label);
695 * @param string $description
696 * @param string $label e.g. 'default'
698 public function setDescription($description, $label = 'default') {
699 // @todo this logic was copied from a commit that then got deleted. Is it good?
700 $uninformativeStrings = [
701 ts('Online Event Registration: '),
702 ts('Online Contribution: '),
704 $cleanedDescription = str_replace($uninformativeStrings, '', $description);
705 return $this->set('description', $label, $cleanedDescription);
713 public function getEmail($label = 'default') {
714 return $this->get('email', $label);
720 * @param string $email
721 * @param string $label e.g. 'default'
723 public function setEmail($email, $label = 'default') {
724 return $this->set('email', $label, (string) $email);
728 * Amount of money charged in fees by the payment processor.
730 * This is notified by (some) payment processers.
732 * @param string $label
736 public function getFeeAmount($label = 'default') {
737 return $this->get('feeAmount', $label);
741 * @param string $feeAmount
742 * @param string $label e.g. 'default'
744 public function setFeeAmount($feeAmount, $label = 'default') {
745 if (!is_numeric($feeAmount)) {
746 throw new \
InvalidArgumentException("feeAmount must be a number.");
748 return $this->set('feeAmount', $label, (float) $feeAmount);
756 public function getFirstName($label = 'default') {
757 return $this->get('firstName', $label);
763 * @param string $firstName
764 * @param string $label e.g. 'default'
766 public function setFirstName($firstName, $label = 'default') {
767 return $this->set('firstName', $label, (string) $firstName);
771 * Getter for invoiceID.
773 * @param string $label
775 * @return string|null
777 public function getInvoiceID($label = 'default') {
778 return $this->get('invoiceID', $label);
782 * @param string $invoiceID
783 * @param string $label e.g. 'default'
785 public function setInvoiceID($invoiceID, $label = 'default') {
786 return $this->set('invoiceID', $label, $invoiceID);
790 * Getter for isBackOffice.
792 * @param string $label
796 public function getIsBackOffice($label = 'default'):bool {
797 // @todo should this return FALSE instead of exception to keep current situation?
798 return $this->get('isBackOffice', $label);
802 * @param bool $isBackOffice
803 * @param string $label e.g. 'default'
805 public function setIsBackOffice($isBackOffice, $label = 'default') {
806 if (is_null($isBackOffice)) {
807 throw new \
InvalidArgumentException("isBackOffice must be a bool, received NULL.");
809 return $this->set('isBackOffice', $label, (bool) $isBackOffice);
813 * Getter for isRecur.
815 * @param string $label
819 public function getIsRecur($label = 'default'):bool {
820 if (!$this->has('isRecur')) {
823 return $this->get('isRecur', $label);
827 * @param bool $isRecur
828 * @param string $label e.g. 'default'
830 public function setIsRecur($isRecur, $label = 'default') {
831 if (is_null($isRecur)) {
832 throw new \
InvalidArgumentException("isRecur must be a bool, received NULL.");
834 return $this->set('isRecur', $label, (bool) $isRecur);
838 * Set whether the user has selected to notify the processor of a cancellation request.
840 * When cancelling the user may be presented with an option to notify the processor. The payment
841 * processor can take their response, if present, into account.
844 * @param string $label e.g. 'default'
846 * @return \Civi\Payment\PropertyBag
848 public function setIsNotifyProcessorOnCancelRecur($value, $label = 'default') {
849 return $this->set('isNotifyProcessorOnCancelRecur', $label, (bool) $value);
853 * Get whether the user has selected to notify the processor of a cancellation request.
855 * When cancelling the user may be presented with an option to notify the processor. The payment
856 * processor can take their response, if present, into account.
858 * @param string $label e.g. 'default'
860 * @return \Civi\Payment\PropertyBag
862 public function getIsNotifyProcessorOnCancelRecur($label = 'default') {
863 return $this->get('isNotifyProcessorOnCancelRecur', $label);
871 public function getLastName($label = 'default') {
872 return $this->get('lastName', $label);
878 * @param string $lastName
879 * @param string $label e.g. 'default'
881 public function setLastName($lastName, $label = 'default') {
882 return $this->set('lastName', $label, (string) $lastName);
886 * Getter for payment processor generated string for charging.
888 * A payment token could be a single use token (e.g generated by
889 * a client side script) or a token that permits recurring or on demand charging.
891 * The key thing is it is passed to the processor in lieu of card details to
892 * initiate a payment.
894 * Generally if a processor is going to pass in a payment token generated through
895 * javascript it would add 'payment_token' to the array it returns in it's
896 * implementation of getPaymentFormFields. This will add a hidden 'payment_token' field to
897 * the form. A good example is client side encryption where credit card details are replaced by
898 * an encrypted token using a gateway provided javascript script. In this case the javascript will
899 * remove the credit card details from the form before submitting and populate the payment_token field.
901 * A more complex example is used by paypal checkout where the payment token is generated
902 * via a pre-approval process. In that case the doPreApproval function is called on the processor
903 * class to get information to then interact with paypal via js, finally getting a payment token.
904 * (at this stage the pre-approve api is not in core but that is likely to change - we just need
905 * to think about the permissions since we don't want to expose to anonymous user without thinking
906 * through any risk of credit-card testing using it.
908 * If the token is not totally transient it would be saved to civicrm_payment_token.token.
910 * @param string $label
912 * @return string|null
914 public function getPaymentToken($label = 'default') {
915 return $this->get('paymentToken', $label);
919 * @param string $paymentToken
920 * @param string $label e.g. 'default'
922 public function setPaymentToken($paymentToken, $label = 'default') {
923 return $this->set('paymentToken', $label, $paymentToken);
931 public function getPhone($label = 'default') {
932 return $this->get('phone', $label);
938 * @param string $phone
939 * @param string $label e.g. 'default'
941 public function setPhone($phone, $label = 'default') {
942 return $this->set('phone', $label, (string) $phone);
946 * Combined with recurFrequencyUnit this gives how often billing will take place.
948 * e.g every if this is 1 and recurFrequencyUnit is 'month' then it is every 1 month.
951 public function getRecurFrequencyInterval($label = 'default') {
952 return $this->get('recurFrequencyInterval', $label);
956 * @param int $recurFrequencyInterval
957 * @param string $label e.g. 'default'
959 public function setRecurFrequencyInterval($recurFrequencyInterval, $label = 'default') {
960 if (!($recurFrequencyInterval > 0)) {
961 throw new InvalidArgumentException("recurFrequencyInterval must be a positive integer");
964 return $this->set('recurFrequencyInterval', $label, (int) $recurFrequencyInterval);
968 * Getter for recurFrequencyUnit.
969 * Combined with recurFrequencyInterval this gives how often billing will take place.
971 * e.g every if this is 'month' and recurFrequencyInterval is 1 then it is every 1 month.
974 * @param string $label
976 * @return string month|day|year
978 public function getRecurFrequencyUnit($label = 'default') {
979 return $this->get('recurFrequencyUnit', $label);
983 * @param string $recurFrequencyUnit month|day|week|year
984 * @param string $label e.g. 'default'
986 public function setRecurFrequencyUnit($recurFrequencyUnit, $label = 'default') {
987 if (!preg_match('/^day|week|month|year$/', $recurFrequencyUnit)) {
988 throw new \
InvalidArgumentException("recurFrequencyUnit must be day|week|month|year");
990 return $this->set('recurFrequencyUnit', $label, $recurFrequencyUnit);
994 * Set the unique payment processor service provided ID for a particular subscription.
996 * Nb. this is stored in civicrm_contribution_recur.processor_id and is NOT
997 * in any way related to the payment processor ID.
999 * @param string $label
1001 * @return string|null
1003 public function getRecurProcessorID($label = 'default') {
1004 return $this->get('recurProcessorID', $label);
1008 * Set the unique payment processor service provided ID for a particular
1011 * See https://github.com/civicrm/civicrm-core/pull/17292 for discussion
1012 * of how this function accepting NULL fits with standard / planned behaviour.
1014 * @param string|null $input
1015 * @param string $label e.g. 'default'
1017 * @return \Civi\Payment\PropertyBag
1019 public function setRecurProcessorID($input, $label = 'default') {
1020 if ($input === '') {
1023 if (strlen($input) > 255 ||
in_array($input, [FALSE, 0], TRUE)) {
1024 throw new \
InvalidArgumentException('processorID field has max length of 255');
1026 return $this->set('recurProcessorID', $label, $input);
1030 * Getter for payment processor generated string for the transaction ID.
1032 * Note some gateways generate a reference for the order and one for the
1033 * payment. This is for the payment reference and is saved to
1034 * civicrm_financial_trxn.trxn_id.
1036 * @param string $label
1038 * @return string|null
1040 public function getTransactionID($label = 'default') {
1041 return $this->get('transactionID', $label);
1045 * @param string $transactionID
1046 * @param string $label e.g. 'default'
1048 public function setTransactionID($transactionID, $label = 'default') {
1049 return $this->set('transactionID', $label, $transactionID);
1053 * Getter for trxnResultCode.
1055 * Additional information returned by the payment processor regarding the
1058 * This would normally be saved in civicrm_financial_trxn.trxn_result_code.
1061 * @param string $label
1063 * @return string|null
1065 public function getTrxnResultCode($label = 'default') {
1066 return $this->get('trxnResultCode', $label);
1070 * @param string $trxnResultCode
1071 * @param string $label e.g. 'default'
1073 public function setTrxnResultCode($trxnResultCode, $label = 'default') {
1074 return $this->set('trxnResultCode', $label, $trxnResultCode);
1077 // Custom Properties.
1080 * Sometimes we may need to pass in things that are specific to the Payment
1083 * @param string $prop
1084 * @param string $label e.g. 'default' or 'old' or 'new'
1087 * @throws InvalidArgumentException if trying to use this against a non-custom property.
1089 public function getCustomProperty($prop, $label = 'default') {
1090 if (isset(static::$propMap[$prop])) {
1091 throw new \
InvalidArgumentException("Attempted to get '$prop' via getCustomProperty - must use using its getter.");
1094 if (!array_key_exists($prop, $this->props
[$label] ??
[])) {
1095 throw new \
BadMethodCallException("Property '$prop' has not been set.");
1097 return $this->props
[$label][$prop] ??
NULL;
1101 * We have to leave validation to the processor, but we can still give them a
1102 * way to store their data on this PropertyBag
1104 * @param string $prop
1105 * @param mixed $value
1106 * @param string $label e.g. 'default' or 'old' or 'new'
1108 * @throws InvalidArgumentException if trying to use this against a non-custom property.
1110 public function setCustomProperty($prop, $value, $label = 'default') {
1111 if (isset(static::$propMap[$prop])) {
1112 throw new \
InvalidArgumentException("Attempted to set '$prop' via setCustomProperty - must use using its setter.");
1114 $this->props
[$label][$prop] = $value;