1. Go to this page and download the library: Download craftcms/stripe library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
craft\base\Event::on(
craft\stripe\services\Products::class,
craft\stripe\services\Products::EVENT_BEFORE_SYNCHRONIZE_PRODUCT,
function(craft\stripe\events\StripeProductSyncEvent $event) {
// Set a custom field value when a product looks “shippable”:
if ($event->source->package_dimensions !== null) {
$event->element->setFieldValue('
craft\base\Event::on(
craft\stripe\services\Checkout::class,
craft\stripe\services\Checkout::EVENT_BEFORE_START_CHECKOUT_SESSION,
function(craft\stripe\events\CheckoutSessionEvent $event) {
// Add metadata if the customer is a logged-in “member”:
$currentUser = Craft::$app->getUser()->getIdentity();
// Nothing to do:
if (!$currentUser) {
return;
}
if ($currentUser->isInGroup('members')) {
// Memoize + assign values:
$data = $event->params;
$data['metadata']['is_member'] = true;
// Set back onto the event:
$event->params = $data;
}
},
);