Skip to content

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

Craft CMS plugins

Foster Checkout

A 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.

The settings on each gateway at Checkout -> Gateways cover the keys merchants change for every order. Use the event when the change depends on who is buying or what is in the cart, or for a key those settings do not cover.

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 URL options. Anything a gateway’s own payment form template reads can be set here.

Turn Link off for a gateway with Include Link at Checkout -> Gateways, which also removes the methods marked “Powered by Link”. That setting writes elementOptions.wallets.link. Use the event to decide per order, since it runs after the setting.

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