diff --git a/src/base/Gateway.php b/src/base/Gateway.php index 8d7a4e8..3f4a5ca 100644 --- a/src/base/Gateway.php +++ b/src/base/Gateway.php @@ -450,25 +450,26 @@ public function supportsWebhooks(): bool */ public function getTransactionHashFromWebhook(): ?string { - $rawData = Craft::$app->getRequest()->getRawBody(); - if (!$rawData) { - return null; - } + $transactionHash = null; + $rawData = Craft::$app->getRequest()->getRawBody(); $data = Json::decodeIfJson($rawData); - if (!$data) { - return null; - } + + if ($data) { + $transactionHash = ArrayHelper::getValue($data, 'data.object.metadata.transaction_reference'); + if (!$transactionHash || !is_string($transactionHash)) { + $transactionHash = null; + } - $transactionHash = ArrayHelper::getValue($data, 'data.object.metadata.transaction_reference'); - if (!$transactionHash || !is_string($transactionHash)) { - $transactionHash = null; - } + if (!$transactionHash) { + $transactionHash = ArrayHelper::getValue($data, 'data.object.payment_intent'); + } - if (!$transactionHash) { - // Use the object ID as the unique ID of the stripe object for the transaction hash so we can enforce a mutex - // in \craft\commerce\services\Webhooks::processWebhook() which call this method. - $transactionHash = ArrayHelper::getValue($data, 'data.object.id'); + if (!$transactionHash) { + // Use the object ID as the unique ID of the stripe object for the transaction hash so we can enforce a mutex + // in \craft\commerce\services\Webhooks::processWebhook() which call this method. + $transactionHash = ArrayHelper::getValue($data, 'data.object.id'); + } } return $transactionHash; diff --git a/src/gateways/PaymentIntents.php b/src/gateways/PaymentIntents.php index 748d3ed..dd639dc 100644 --- a/src/gateways/PaymentIntents.php +++ b/src/gateways/PaymentIntents.php @@ -139,6 +139,7 @@ public function getPaymentFormHtml(array $params): ?string { $defaults = [ 'clientSecret' => '', + 'subscription' => '', 'scenario' => 'payment', 'order' => null, 'gateway' => $this, @@ -322,7 +323,7 @@ public function createPaymentSource(BasePaymentForm $sourceData, int $customerId { // Is Craft request the commerce/pay controller action? $appRequest = Craft::$app->getRequest(); - $isCommercePayRequest = $appRequest->getIsSiteRequest() && $appRequest->getIsActionRequest() && $appRequest->getActionSegments() == ['commerce', 'pay', 'index']; + $isCommercePayRequest = $appRequest->getIsSiteRequest() && $appRequest->getIsActionRequest() && $appRequest->getActionSegments() == ['commerce', 'payments', 'pay']; if ($isCommercePayRequest) { throw new PaymentSourceCreatedLaterException(Craft::t('commerce', 'The payment source should be created after successful payment.')); @@ -477,7 +478,7 @@ public function getBillingIssueResolveFormHtml(Subscription $subscription): stri case 'requires_confirmation': return $this->getPaymentFormHtml(['clientSecret' => $clientSecret]); case 'requires_action': - return $this->getPaymentFormHtml(['clientSecret' => $clientSecret, 'scenario' => 'requires_action']); + return $this->getPaymentFormHtml(['clientSecret' => $clientSecret, 'scenario' => 'requires_action', 'subscription' => $subscription->uid]); } } diff --git a/src/templates/paymentForms/elementsForm.twig b/src/templates/paymentForms/elementsForm.twig index fc63a46..b9d567c 100644 --- a/src/templates/paymentForms/elementsForm.twig +++ b/src/templates/paymentForms/elementsForm.twig @@ -5,6 +5,7 @@