我有这门课
class Api extends \Magento\Framework\Model\AbstractModel
{
public function __construct(
\Magento\Framework\Message\ManagerInterface $messageManager,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\MyModule\Payment\Helper\Data $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;
}
}
然后这个类被一个自定义控制器使用:
class Index extends \Magento\Framework\App\Action\Action
{
public function __construct(
\Magento\Framework\App\Action\Context $context,
\MyModule\Payment\Model\Api $moduleApi,
\Magento\Checkout\Model\Session $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');
}
}
}
在由我的支付网关触发的 SECOND 自定义控制器上Callback
,我使用$order = $this->getOrderFactory->create()->loadByIncrementId($incrementId)
我注入$this->getOrderFactory
的一个实例在哪里。\Magento\Sales\Model\OrderFactory
我increment id
从我的支付网关得到了回报。
不知何故,在这Callback
堂课中,当我使用 时$order->getData('test')
,我什么也得不到
我的问题是
我在这里缺少一些核心的magento概念吗?
或者有没有其他方法可以检索这个Callback
只有以下信息的测试数据increment Id
(因为在回调点,用户已经离开 magento 并回来了)
这对我来说很奇怪,因为我可以编辑和保存订单,Callback
但我的额外数据没有保存/与订单对象本身关联
提前致谢!
更新
我确认我使用order id
从支付网关获得的订单对象(行)与从支付网关获得的订单对象(行)相同session's Last Order
我addStatusHistoryComment
在lastOrder
上面的 Api 类中调用并addStatusHistoryComment
在我的 Callback 类中调用了两个调用都在我的管理仪表板中更新相同的顺序
我还确认getData('test')
在我设置后立即调用它给我想要的数据。
所以我不明白为什么 getData 在从 Callback 调用时不起作用