-
{{ paymentSource.description }} {% if paymentSource.id == currentUser.primaryPaymentSourceId %}({{ 'Primary'|t }}){% endif %}
+
{{ paymentSource.description }} {% if paymentSource.id == currentUser.primaryPaymentSourceId %}{{ 'Primary'|t }}{% endif %}
{% if paymentSource.gateway %}
{{ paymentSource.gateway.name }} ({{ paymentSource.token }})
{% endif %}
@@ -106,30 +111,33 @@
{{ hiddenInput('cancelUrl', '/[[folderName]]/customer/cards'|hash) }}
{{ redirectInput('/[[folderName]]/customer/cards') }}
-
- {{ gateway.getPaymentFormHtml({})|raw }}
-
-
-
-
- {# Force in some basic styling for the gateway-provided form markup (better to build your own form markup!) #}
-
+ {% set params = {} %}
+
+ {% if className(gateway) == 'craft\\commerce\\stripe\\gateways\\PaymentIntents' %}
+ {% set params = {
+ paymentFormType: 'elements',
+ appearance: {
+ theme: 'stripe'
+ },
+ elementOptions: {
+ layout: {
+ type: 'accordion',
+ defaultCollapsed: false,
+ radios: false,
+ spacedAccordionItems: false
+ }
+ },
+ submitButtonClasses: '[[classes.btn.base]] [[classes.btn.mainColor]] my-2',
+ submitButtonText: 'Create',
+ errorMessageClasses: 'bg-red-200 text-red-600 my-2 p-2 rounded',
+ } %}
+ {% endif %}
{{ input('text', 'description', '', {
maxlength: 70,
autocomplete: 'off',
- placeholder: 'Card description'|t,
+ placeholder: 'Payment source description'|t,
class: ['w-full', '[[classes.input]]']
}) }}
@@ -140,13 +148,21 @@
-
- {{ tag('button', {
- type: 'submit',
- class: '[[classes.btn.base]] [[classes.btn.mainColor]]',
- text: 'Add card'|t
- }) }}
+
+ {% namespace gateway.handle|commercePaymentFormNamespace %}
+ {{ gateway.getPaymentFormHtml(params)|raw }}
+ {% endnamespace %}
+
+ {% if gateway.showPaymentFormSubmitButton() %}
+
+ {{ tag('button', {
+ type: 'submit',
+ class: '[[classes.btn.base]] [[classes.btn.mainColor]]',
+ text: 'Add card'|t
+ }) }}
+
+ {% endif %}
{% endif %}
diff --git a/src/console/controllers/ExampleTemplatesController.php b/src/console/controllers/ExampleTemplatesController.php
index f80acb6eb4..0423e40691 100644
--- a/src/console/controllers/ExampleTemplatesController.php
+++ b/src/console/controllers/ExampleTemplatesController.php
@@ -236,6 +236,8 @@ private function _addCssClassesToReplacementData(): void
$this->_replacementData = ArrayHelper::merge($this->_replacementData, [
'[[color]]' => $mainColor,
'[[dangerColor]]' => $dangerColor,
+ '[[classes.text.color]]' => "text-$mainColor-500",
+ '[[classes.text.dangerColor]]' => "text-$dangerColor-500",
'[[classes.a]]' => "text-$mainColor-500 hover:text-$mainColor-600",
'[[classes.input]]' => "border border-gray-300 hover:border-gray-500 px-4 py-2 leading-tight rounded",
'[[classes.box.base]]' => "bg-gray-100 border-$mainColor-300 border-b-2 p-6",
diff --git a/src/controllers/CartController.php b/src/controllers/CartController.php
index 3754a074a7..aad1586e95 100644
--- a/src/controllers/CartController.php
+++ b/src/controllers/CartController.php
@@ -277,6 +277,20 @@ public function actionUpdateCart(): ?Response
return $this->_returnCart();
}
+ /**
+ * @return Response|null
+ * @throws BadRequestHttpException
+ * @throws InvalidConfigException
+ * @since 4.3
+ */
+ public function actionForgetCart(): ?Response
+ {
+ $this->requirePostRequest();
+ Plugin::getInstance()->getCarts()->forgetCart();
+ $this->setSuccessFlash(Craft::t('commerce', 'Cart forgotten.'));
+ return $this->redirectToPostedUrl();
+ }
+
/**
* @throws BadRequestHttpException
* @throws Exception
diff --git a/src/controllers/PaymentSourcesController.php b/src/controllers/PaymentSourcesController.php
index f3f074fcbf..684d0ae707 100644
--- a/src/controllers/PaymentSourcesController.php
+++ b/src/controllers/PaymentSourcesController.php
@@ -64,7 +64,7 @@ public function actionAdd(): ?Response
$description = (string)$this->request->getBodyParam('description');
try {
- $paymentSource = $plugin->getPaymentSources()->createPaymentSource($customer->id, $gateway, $paymentForm, $description);
+ $paymentSource = $plugin->getPaymentSources()->createPaymentSource($customer->id, $gateway, $paymentForm, $description, $isPrimaryPaymentSource);
} catch (Throwable $exception) {
Craft::$app->getErrorHandler()->logException($exception);
return $this->asModelFailure(
diff --git a/src/services/PaymentSources.php b/src/services/PaymentSources.php
index a28553f654..530f2ed175 100644
--- a/src/services/PaymentSources.php
+++ b/src/services/PaymentSources.php
@@ -266,7 +266,7 @@ public function getPaymentSourceByIdAndUserId(int $sourceId, int $userId): ?Paym
* @throws InvalidConfigException
* @throws PaymentSourceException If unable to create the payment source
*/
- public function createPaymentSource(int $customerId, GatewayInterface $gateway, BasePaymentForm $paymentForm, string $sourceDescription = null): PaymentSource
+ public function createPaymentSource(int $customerId, GatewayInterface $gateway, BasePaymentForm $paymentForm, string $sourceDescription = null, bool $makePrimarySource = false): PaymentSource
{
try {
$source = $gateway->createPaymentSource($paymentForm, $customerId);
@@ -284,6 +284,10 @@ public function createPaymentSource(int $customerId, GatewayInterface $gateway,
throw new PaymentSourceException(Craft::t('commerce', 'Could not create the payment source.'));
}
+ if($makePrimarySource) {
+ Plugin::getInstance()->getCustomers()->savePrimaryPaymentSourceId($source->getCustomer(), $source->id);
+ }
+
return $source;
}
diff --git a/src/templates/subscriptions/_edit.twig b/src/templates/subscriptions/_edit.twig
index 8872536bb4..0ff0d76e52 100644
--- a/src/templates/subscriptions/_edit.twig
+++ b/src/templates/subscriptions/_edit.twig
@@ -206,11 +206,6 @@
{{ subscription.nextPaymentDate|datetime }}