Skip to content

Commerce Foundations is our pre-built Craft Commerce store. See what it includes

Craft CMS plugins

Foster Checkout

A drop-in checkout for Craft Commerce, with its copy and settings managed from the control panel.

Payment form parameters

Change what a gateway’s payment form is rendered with, per order. The checkout builds the parameters it passes to the gateway’s getPaymentFormHtml(), then hands them to this event before rendering.

Extra parameters at Checkout -> Gateways does the same for every order. Use the event when the change depends on who is buying or what is in the cart.

Answering the event#

<?php

namespace modules\site;

use craft\commerce\stripe\gateways\PaymentIntents;
use fostercommerce\fostercheckout\events\DefinePaymentFormParamsEvent;
use fostercommerce\fostercheckout\services\Checkout;
use yii\base\Event;

Event::on(
    Checkout::class,
    Checkout::EVENT_DEFINE_PAYMENT_FORM_PARAMS,
    static function (DefinePaymentFormParamsEvent $definePaymentFormParamsEvent): void {
        if (! $definePaymentFormParamsEvent->gateway instanceof PaymentIntents) {
            return;
        }

        if ($definePaymentFormParamsEvent->order->getCustomer()?->fullName === null) {
            $definePaymentFormParamsEvent->params['elementOptions']['wallets']['link'] = 'never';
        }
    }
);

params holds whatever the checkout built for that gateway. For Stripe that includes elementOptions, which the Payment Element is created with; for PayPal the SDK options. Anything a gateway’s own payment form template reads can be set here.

Link is a Stripe wallet, not a payment method type. It is shown whenever the intent allows cards and Link is on in the Stripe Dashboard, and it carries Instant Bank Payments and Klarna with it. Restricting the intent’s payment method types does not remove it; elementOptions.wallets.link = 'never' does, for that form only.

We can take it from here.

We take on the Craft and Craft Commerce sites you built, so you can get back to building. Introduce a client who signs a management contract and you get a $3,000 partnership fee.

How the Dev Partnership Program works
See if we’re a fit