I have this class
class Api extends MagentoFrameworkModelAbstractModel
{
public function __construct(
MagentoFrameworkMessageManagerInterface $messageManager,
MagentoFrameworkAppConfigScopeConfigInterface $scopeConfig,
MagentoStoreModelStoreManagerInterface $storeManager,
MyModulePaymentHelperData $helper
) {
$this->messageManager = $messageManager;
$this->scopeConfig = $scopeConfig;
$this->storeManager = $storeManager;
$this->helper = $helper;
$this->contentType = $this->helper->getConfigData('content_type');
}
.
.
.
function createOnlinePurchase($authToken, $lastOrder)
{
.
.
.
//here I pass lastOrder's increment id to my payment gateway
$lastOrder->setData('test','test data');
$lastOrder->save();
//make payment gateway api call, get payment url
return url;
}
}
this class is then used by a custom controller:
class Index extends MagentoFrameworkAppActionAction
{
public function __construct(
MagentoFrameworkAppActionContext $context,
MyModulePaymentModelApi $moduleApi,
MagentoCheckoutModelSession $session
) {
parent::__construct($context);
$this->moduleApi = $moduleApi;
$this->session = $session;
}
public function execute() {
$token = $this->moduleApi->requestAuthToken();
if ($this->session->getLastRealOrder() && $token !== null) {
$url = $this->moduleApi->createOnlinePurchase($token, $this->session->getLastRealOrder());
if ($url !== null && substr($url, 0, 4) == 'http') {
$this->session->clearStorage();
return $this->resultRedirectFactory->create()->setUrl($url);
}
else {
$this->messageManager->addError(__("Url invalid: ".$url));
return $this->resultRedirectFactory->create()->setPath('checkout/onepage/failure');
}
}
}
on a SECOND custom controller Callback
, which is triggered by my payment gateway, I retrieved the order object using $order = $this->getOrderFactory->create()->loadByIncrementId($incrementId)
where $this->getOrderFactory
is an instance of MagentoSalesModelOrderFactory
I injected.
I got the increment id
back from my payment gateway.
Somehow within this Callback
class, when I use $order->getData('test')
, I get nothing
My question is
Is there some core magento concept I’m missing here?
Or is there any other way I can retrieve this test data in Callback
which only have the information of increment Id
(because at the point of Callback, user have already left magento and come back)
It’s weird to me beause I can edit and save the order from Callback
but my extra data is not saved/associated with the order object itself
Thanks in advance!