diff --git a/CHANGELOG.md b/CHANGELOG.md index c747baf..0fedd65 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,10 @@ Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +### Added + +- Added payment element check in implementation of hook_webform_submission_insert. + ## [1.0.0] - 2024-12-06 ### Updated diff --git a/src/Helper/PaymentHelper.php b/src/Helper/PaymentHelper.php index 6dbcae8..5858eea 100644 --- a/src/Helper/PaymentHelper.php +++ b/src/Helper/PaymentHelper.php @@ -62,12 +62,16 @@ public function __construct( * Return */ public function webformSubmissionPresave(WebFormSubmissionInterface $submission): void { + + // Only modify submission if payment element exists. ['paymentElement' => $paymentElement, 'paymentElementMachineName' => $paymentElementMachineName] = $this->getWebformElementNames($submission); - $submissionData = $submission->getData(); + if (!isset($paymentElement) && !isset($paymentElementMachineName)) { return; } + $submissionData = $submission->getData(); + /* * The paymentReferenceField is not a part of the form submission, * so we get it from the POST payload. @@ -182,6 +186,14 @@ private function getWebformElementNames(WebformSubmissionInterface $submission): * Throws exception. */ public function webformSubmissionInsert(WebFormSubmissionInterface $submission): void { + + // Only modify submission if payment element exists. + ['paymentElement' => $paymentElement, 'paymentElementMachineName' => $paymentElementMachineName] = $this->getWebformElementNames($submission); + + if (!isset($paymentElement) && !isset($paymentElementMachineName)) { + return; + } + $logger_context = [ 'handler_id' => 'os2forms_payment', 'channel' => 'webform_submission',