Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/cartforge.co/app/code/StripeIntegration/Payments/Observer/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/cartforge.co/app/code/StripeIntegration/Payments/Observer/CustomerDetailsChanged.php
<?php

namespace StripeIntegration\Payments\Observer;

use Magento\Framework\Event\ObserverInterface;

class CustomerDetailsChanged implements ObserverInterface
{
    private $config;
    private $loggerHelper;
    private $stripeCustomerFactory;

    public function __construct(
        \StripeIntegration\Payments\Helper\Logger $loggerHelper,
        \StripeIntegration\Payments\Model\Config $config,
        \StripeIntegration\Payments\Model\StripeCustomerFactory $stripeCustomerFactory
    )
    {
        $this->loggerHelper = $loggerHelper;
        $this->config = $config;
        $this->stripeCustomerFactory = $stripeCustomerFactory;
    }

    /**
     * @return void
     */
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        $event = $observer->getEvent();
        $savedCustomer = $event->getCustomerDataObject();
        $prevCustomerData = $event->getOrigCustomerDataObject();

        if (empty($prevCustomerData) || empty($savedCustomer))
            return;

        $oldName = $prevCustomerData->getFirstname() . " " . $prevCustomerData->getLastname();
        $newName = $savedCustomer->getFirstname() . " " . $savedCustomer->getLastname();

        if ($savedCustomer->getEmail() == $prevCustomerData->getEmail() && $oldName == $newName)
            return;

        $customerId = $savedCustomer->getId();
        $customerModel = $this->stripeCustomerFactory->create()->load($customerId, "customer_id");
        $customerStripeId = $customerModel->getStripeId();

        if (!$customerStripeId)
            return;

        try
        {
            $this->config->getStripeClient()->customers->update($customerStripeId, [
                'email' => $savedCustomer->getEmail(),
                'name' => $newName,
                'description' => null
            ]);

        }
        catch (\Exception $e)
        {
            $this->loggerHelper->logError("Could not update Stripe customer: " . $e->getMessage());
        }
    }
}

Spamworldpro Mini