From 68fe25cc15f4d6e2b75207fa065afbd3557f8ea0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20Svi=CC=81tok?= Date: Fri, 4 Mar 2022 16:53:01 +0100 Subject: [PATCH] Adds fallback when processing DID_CHANGE_RENEWAL_STATUS notification type In case of missing payment, new payment is created. remp/heldpesk#1130 --- src/Hermes/MissingPaymentException.php | 7 +++++++ .../ServerToServerNotificationWebhookHandler.php | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 src/Hermes/MissingPaymentException.php diff --git a/src/Hermes/MissingPaymentException.php b/src/Hermes/MissingPaymentException.php new file mode 100644 index 0000000..9039d6c --- /dev/null +++ b/src/Hermes/MissingPaymentException.php @@ -0,0 +1,7 @@ +changeSubscriptionTypeOfNextPayment($latestReceiptInfo); case ServerToServerNotification::NOTIFICATION_TYPE_DID_CHANGE_RENEWAL_STATUS: - return $this->changeRenewalStatus($stsNotification, $latestReceiptInfo); + try { + return $this->changeRenewalStatus($stsNotification, $latestReceiptInfo); + } catch (MissingPaymentException $exception) { + Debugger::log($exception->getMessage(), Debugger::ERROR); + // if payment is missing, fallback is to create payment again + return $this->createPayment($latestReceiptInfo); + } case ServerToServerNotification::NOTIFICATION_TYPE_DID_FAIL_TO_RENEW: $this->handleFailedRenewal($stsNotification, $latestReceiptInfo); @@ -457,7 +463,7 @@ private function changeRenewalStatus( $originalTransactionID ); if (empty($paymentMetas)) { - throw new \Exception("Unable to find (recurrent or non-recurrent) payment with `original_transaction_id` [{$originalTransactionID}]. Unable to change renewal status."); + throw new MissingPaymentException("Unable to find (recurrent or non-recurrent) payment with `original_transaction_id` [{$originalTransactionID}]. Unable to change renewal status."); } $lastPayment = reset($paymentMetas)->payment;