Skip to content

Commit

Permalink
Merge pull request #278 from craftcms/bugfix/270-js-files-served-from…
Browse files Browse the repository at this point in the history
…-correct-path

Fixed JS files being served from an incorrect path
  • Loading branch information
nfourtythree authored Dec 19, 2023
2 parents b634dc4 + 3e16e85 commit a03f6e0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
# Release Notes for Stripe for Craft Commerce

## Unreleased

- Payment method data is now stored in expanded form within transaction response data. ([#276](https://github.com/craftcms/commerce-stripe/pull/276))
- Fixed a bug where JavaScript files were being served incorrectly. ([#270](https://github.com/craftcms/commerce-stripe/issues/270))

## 4.0.1.1 - 2023-10-25

Expand Down
20 changes: 14 additions & 6 deletions src/gateways/PaymentIntents.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,25 @@ public function getPaymentFormHtml(array $params): ?string

$view = Craft::$app->getView();
$previousMode = $view->getTemplateMode();
$view->setTemplateMode(View::TEMPLATE_MODE_CP);
if (Craft::$app->getRequest()->isCpRequest) {
$view->setTemplateMode(View::TEMPLATE_MODE_CP);
}

$view->registerScript('', View::POS_END, ['src' => 'https://js.stripe.com/v3/']); // we need this to load at end of body

if ($params['paymentFormType'] == self::PAYMENT_FORM_TYPE_CHECKOUT) {
$html = $view->renderTemplate('commerce-stripe/paymentForms/checkoutForm', $params);
} else {
if ($params['paymentFormType'] == self::PAYMENT_FORM_TYPE_ELEMENTS) {
$view->registerAssetBundle(ElementsFormAsset::class);
$html = $view->renderTemplate('commerce-stripe/paymentForms/elementsForm', $params);
}

// Template mode needs to be CP for the payment form to work
$view->setTemplateMode(View::TEMPLATE_MODE_CP);

$templatePath = ($params['paymentFormType'] == self::PAYMENT_FORM_TYPE_CHECKOUT)
? 'commerce-stripe/paymentForms/checkoutForm'
: 'commerce-stripe/paymentForms/elementsForm';

$html = $view->renderTemplate($templatePath, $params);

$view->setTemplateMode($previousMode);

return $html;
Expand Down Expand Up @@ -219,7 +227,7 @@ public function completePurchase(Transaction $transaction): RequestResponseInter
$paymentIntentOptions = [
'expand' => ['payment_method'],
];

if ($data['object'] == 'payment_intent') {
$paymentIntent = $this->getStripeClient()->paymentIntents->retrieve($data['id'], $paymentIntentOptions);
} else {
Expand Down

0 comments on commit a03f6e0

Please sign in to comment.