magento2.3.2 用户支付成功后台没有生成订单 丢单问题处理

后台

后台订单不连续,查看paypal收款账户发现000000157 订单用户已成功支付,但magento2后台没这个订单

用户开始投诉,运营很着急,开始找产品,产品说这是技术问题,转到技术这处理,技术开始排查

1.首先分析问题

用户已支付,订单没生成,以前的订单都没发现有这个问题,这段时间出现的

分析原因:说明paypal用户已支付了,支付成功后在通知系统时没有写到数据库里发生的问题

2.进后台先打开paypal调试,查看paypal支付日志

 

确实支付成功了,paypal支付是没有问题的,就看通知到系统有没有成功了

系统只有收到pyapal支付成功通知才会创建订单

报错日志

[2020-06-02 18:01:54] main.CRITICAL: The "000000117" order ID is incorrect. Verify the ID and try again. {"exception":"[object] (Exception(code: 0): The \"000000117\" order ID is incorrect. Verify the ID and try again. at /www/wwwroot/www.xxxx.com/vendor/magento/module-paypal/Model/Ipn.php:143)"} []

 

3.查访问日志找支付成功通知

20/Jun/2020:00:05:40 +0800] "POST /paypal/ipn/ HTTP/1.1" 500 - "-" "PayPal IPN ( https://www.paypal.com/ipn )"
[20/Jun/2020:00:13:00 +0800] "POST /paypal/ipn/ HTTP/1.1" 500 - "-" "PayPal IPN ( https://www.paypal.com/ipn )"
[20/Jun/2020:00:29:49 +0800] "POST /paypal/ipn/ HTTP/1.1" 500 - "-" "PayPal IPN ( https://www.paypal.com/ipn )"
[20/Jun/2020:00:39:25 +0800] "POST /paypal/ipn/ HTTP/1.1" 500 - "-" "PayPal IPN ( https://www.paypal.com/ipn )"
[20/Jun/2020:01:02:26 +0800] "POST /paypal/ipn/ HTTP/1.1" 500 - "-" "PayPal IPN ( https://www.paypal.com/ipn )"
 [20/Jun/2020:01:27:10 +0800] "POST /paypal/ipn/ HTTP/1.1" 500 - "-" "PayPal IPN ( https://www.paypal.com/ipn )"
[20/Jun/2020:02:07:54 +0800] "POST /paypal/ipn/ HTTP/1.1" 500 - "-" "PayPal IPN ( https://www.paypal.com/ipn )"
[20/Jun/2020:02:14:13 +0800] "POST /paypal/ipn/ HTTP/1.1" 500 - "-" "PayPal IPN ( https://www.paypal.com/ipn )"

发现支付通知都是500异常,只有个别是200成功的

发现其它报错问题

网上搜了下发现

https://community.magento.com/t5/Magento-2-x-Technical-Issues/Successful-orders-dont-appear-on-the-admin-panel-after-online/td-p/390986#

https://github.com/magento/magento2/issues/25862

magento2.3.5以下版本都有这个问题

开始修改

\vendor\magento\module-checkout\Model\GuestPaymentInformationManagement.php

savePaymentInformationAndPlaceOrder() 方法替换

/**
     * @inheritdoc
	 * 保存付款信息和订单
     */
    public function savePaymentInformationAndPlaceOrder(
        $cartId,
        $email,
        \Magento\Quote\Api\Data\PaymentInterface $paymentMethod,
        \Magento\Quote\Api\Data\AddressInterface $billingAddress = null
    ) {
        $this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress);
        try {
            $orderId = $this->cartManagement->placeOrder($cartId);
        } catch (\Magento\Framework\Exception\LocalizedException $e) {
            $this->getLogger()->critical(
                'Placing an order with quote_id ' . $cartId . ' is failed: ' . $e->getMessage()
            );
            throw new CouldNotSaveException(
                __($e->getMessage()),
                $e
            );
        } catch (\Exception $e) {
            $this->getLogger()->critical($e);
            throw new CouldNotSaveException(
                __('An error occurred on the server. Please try to place the order again.'),
                $e
            );
        }

        return $orderId;
    }

 后台漏单问题解决

查找过程

POST /paypal/ipn/ HTTP/1.1" 500 - "-" "PayPal IPN ( https://www.paypal.com/ipn

\/paypal\/ipn\/ HTTP\/1.1\" 500
-----------------------------------
sed -n '/2019-12-28 11:26/,/2019-12-28 12:13/p' nohup.out | grep '接收到xx请求参数,开始处理' | wc -l
sed -n '/2019-12-28 11:26/,/2019-12-28 12:13/p' nohup.out | grep '接收到xx请求参数,开始处理' | wc -l
有效
查找ipn 200 成功的
\/paypal\/ipn\/ HTTP\/1.1" 200   
查找ipn 500
\ HTTP\/1.1" 500   
-------------------------
POST /paypal/ipn/ HTTP/1.1" 200
POST \/paypal\/ipn\/ HTTP\/1.1" 200 查找成功的
POST \/paypal\/ipn\/ HTTP\/1.1" 500 查找失败的

 

tail -f 实时查看日志文件 tail -f 日志文件log
tail - 10 f 实时查看日志文件 后10行
tail -f -n 10 payment.log linux查看日志后10行
搜寻字符串
grep ‘搜寻字符串’ filename
按ctrl+c 退出
------------------------------------------------------------------------------------------------

magento2.3.2漏单续集

12个月后又出现个别漏单问题

[2020-11-21 21:51:26] main.CRITICAL: The "000001203" order ID is incorrect. Verify the ID and try again. {"exception":"[object] (Exception(code: 0): The \"000001203\" order ID is incorrect. Verify the ID and try again. at /www/wwwroot/www.xxx.com/vendor/magento/module-paypal/Model/Ipn.php:147)"} []
[2020-11-21 21:51:26] main.CRITICAL: The "000001203" order ID is incorrect. Verify the ID and try again. {"exception":"[object] (Exception(code: 0): The \"000001203\" order ID is incorrect. Verify the ID and try again. at /www/wwwroot/www.xxx.com/vendor/magento/module-paypal/Model/Ipn.php:147)"} []
[2020-11-21 21:51:36] main.CRITICAL: The "000001203" order ID is incorrect. Verify the ID and try again. {"exception":"[object] (Exception(code: 0): The \"000001203\" order ID is incorrect. Verify the ID and try again. at /www/wwwroot/www.xxx.com/vendor/magento/module-paypal/Model/Ipn.php:147)"} []
[2020-11-21 21:51:56] main.CRITICAL: The "000001203" order ID is incorrect. Verify the ID and try again. {"exception":"[object] (Exception(code: 0): The \"000001203\" order ID is incorrect. Verify the ID and try again. at /www/wwwroot/www.xxx.com/vendor/magento/module-paypal/Model/Ipn.php:147)"} []
[2020-11-21 21:52:05] main.CRITICAL: PayPal gateway has rejected request. Payment has already been made for this InvoiceID (#10412: Duplicate invoice). {"exception":"[object] (Magento\\Framework\\Exception\\LocalizedException(code: 0): PayPal gateway has rejected request. Payment has already been made for this InvoiceID (#10412: Duplicate invoice). at /www/wwwroot/www.xxx.com/vendor/magento/framework/ObjectManager/Factory/AbstractFactory.php:116)"} []

本地断点调试(现金支付)magento2下单流程

vendor/magento/module-paypal/Model/Ipn.php

138  protected function _getOrder()

$this->_order = $this->_orderFactory->create()->loadByIncrementId($incrementId);

if (!$this->_order->getId()) {
      
            throw new Exception(sprintf('The "%s" order ID is incorrect. Verify the ID and try again.', $incrementId));
        }

 

下订单调试

 checkout/Model/GuestPaymentInformationManagement.php savePaymentInformationAndPlaceOrder 101 cartId:
 checkout/Model/GuestPaymentInformationManagement.php savePaymentInformation 132
 checkout/Model/GuestPaymentInformationManagement.php limitShippingCarrier 183
 module-quote/Model/GuestCart/GuestCartManagement.php placeOrder 82:
 module-quote/Model/GuestCart/GuestCartManagement.php placeOrder 87:2525--NULL
 module-quote/Model/QuoteManagement.php placeOrder 358:
 checkout/Observer/SalesQuoteSaveAfterObserver.php execute 36
 module-quote/Model/QuoteManagement.php placeOrder 415 LastOrderId:709
 checkout/Model/GuestPaymentInformationManagement.php savePaymentInformationAndPlaceOrder 105:709
 checkout/Model/GuestPaymentInformationManagement.php savePaymentInformationAndPlaceOrder 109:709
 checkout/Model/GuestPaymentInformationManagement.php savePaymentInformationAndPlaceOrder 113:709
 checkout/Model/GuestPaymentInformationManagement.php savePaymentInformationAndPlaceOrder 120:709
 checkout/Model/Session.php setQuoteId 334
 checkout/Controller/Onepage.php dispatch 145:
 checkout/Controller/Onepage.php _canShowForUnregisteredUsers 270:
 checkout/Controller/Onepage.php getOnepage 260:
 checkout/Model/Type/Onepage.php getQuote 278
 checkout/Controller/Onepage/Session.php 513:
 checkout/Controller/Onepage.php getOnepage 260:
 checkout/Model/Session.php clearQuote 452
 checkout/Model/Session.php setQuoteId 334
 checkout/Model/Session.php 513:
 Model-sales/Model/Order.php loadByIncrementId
 checkout/Model/Session.php 513:
 checkout/Model/Session.php 513:

下单流程整理

1.用户添加购物车   

购物车id生成quote    quote_address购物车地址   quote_item 购物车item   quote_item_option购物车中item项商品和数量

module-checkout/Model/GuestPaymentInformmationManagement.php

public function savePaymentInformationAndPlaceOrder(

$this->savePaymentInformation($cartId, $email, $paymentMethod, $billingAddress);   //保存bilin信息到表quote_address

$orderId = $this->cartManagement->placeOrder($cartId); //生成订单

module-quote/Model/GuestCart/GuestCartManagement.php 

public function placeOrder( 方法中

$this->quoteManagement->placeOrder(

module-quote/Model/QuoteManagement.php 中

public function placeOrder( 方法

$order = $this->submit($quote);  返回的 $order 有问题
405行增加异常判断 //$order->getId() 不能为空
        if (null == $order || !$order->getId()) {
            throw new LocalizedException(
                __('A server error stopped your order from being placed. Please try to place your order again.')
            );
        }

 

在submit方法中

public function submit(QuoteEntity $quote, $orderData = [])
    {
        if (!$quote->getAllVisibleItems()) {
            $quote->setIsActive(false);
            return null;
        } 

         return $this->submitQuote($quote, $orderData);
     
    }

线上报错提示:

module-sales/Model/Service/OrderService.php place() save catch 224:000001432--We can't save the address: Email has a wrong format

电子邮件地址格式错误,在Paypal Express Checkout Magento 2.3.2上

FINDINGS

Error message comes from Magento\Quote\Model\SubmitQuoteValidator::validateOrder
but at validator method Magento\Sales\Model\Order\Address\Validator::validate
Address object returns null for email.

 

Paypal Express结帐无法正常工作,它显示“异常消息:我们无法保存地址:电子邮件格式错误”。但是付款成功,但未创建Magento订单。

Exception message: We can't save the address:
Email has a wrong format
Trace: <pre>#1 Magento\Framework\Model\ResourceModel\Db\AbstractDb->save() called at [vendor/magento/framework/Model/AbstractModel.php:655]

 

vendor/magento/module-sales/Model/Order/Address/Validator.php 并且$ address-> getEmail()变为NULL /空

paypal express checkout提交时漏单问题解决办法:

 

        /* set customer email if email is found empty (bug) */
		if ($this->_quote->getCustomerEmail() === null && $this->_quote->getBillingAddress()->getEmail() !== null) {
			$this->_quote->setCustomerEmail($this->_quote->getBillingAddress()->getEmail());
		}

app/code/Magento/Sales/Model/Order/Address.php 新增

 /**
     * @inheritdoc
     */
    public function beforeSave()
    {
        if ($this->getEmail() === null) {
            $this->setEmail($this->getOrder()->getCustomerEmail());
        }
        return parent::beforeSave();
    }

vi /www/wwwroot/www.broadout.com/vendor/magento/module-quote/Model/QuoteManagement.php +379

 public function placeOrder( 这个方法中
新增判断
//当email为空时
                        if(empty($quote->getCustomerEmail())){
                                file_put_contents("test.txt","\r\n module-quote/Model/QuoteManagement.php placeOrder 389:",FILE_APPEND);
                                $quote->setCustomerEmail($quote->getBillingAddress()->getEmail());
                        }
                        if (empty($quote->getCustomerEmail())) {
                                file_put_contents("test.txt","\r\n module-quote/Model/QuoteManagement.php placeOrder 399:",FILE_APPEND);
                                throw new LocalizedException(
                                        __('A server error stopped your order from being placed. Please try to place your order again.')
                                );
                        }

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

过了一周后发现还是有个别漏单问题出现

sql查询

查询指定订单号
select * from quote where reserved_order_id='000001761';

4538
查询quote_address指定用户地址中的emaill
select * from quote_address where quote_id='4538';
shipping  email为空


查询quote_ite
select * from quote_item where quote_id='4538';

查询quote_item_option
select * from quote_item_option where item_id='7648' or item_id='8394';

链表查询
select b.* from quote_item a left join quote_item_option b on a.item_id=b.item_id where a.quote_id='4144';

000001761  quote_address下单时间和支付时间中间有3个小时差   发现shipping email为空
12361    4538    2020-12-29 03:32:03    2020-12-29 04:40:52             shipping                  
12387    4538    2020-12-29 06:11:04    2020-12-29 06:11:04           billing    zajpjmalloyads@aol.com        John 

在下单中添加为空判断,当为空时,把已有billing email更新到shipping email中

修改一:
处理paypal express 支付email为空问题
vi vendor/magento/module-paypal/Model/Express/Checkout.php +810

修正原来的
			
/* set customer email if email is found empty (bug) */
		if (empty($this->_quote->getCustomerEmail())) {
			$this->_quote->setCustomerEmail($this->_quote->getBillingAddress()->getEmail()?$this->_quote->getBillingAddress()->getEmail():$this->_quote->getShippingAddress()->getEmail());
			
		}


在quote_address表中shipping列email为空所以下单失败

修改二:

vi vendor/magento/module-quote/Model/QuoteManagement.php +507

protected function submitQuote(QuoteEntity $quote, $orderData = [])
方法下增加
		//当用户email为空时
		if(empty($quote->getCustomerEmail())){
			
			$quote->setCustomerEmail($quote->getBillingAddress()->getEmail()?$quote->getBillingAddress()->getEmail():$quote->getShippingAddress()->getEmail());	
			file_put_contents("test.txt","\r\n module-quote/Model/QuoteManagement.php submitQuote email is null 516:".$quote->getBillingAddress()->getEmail()."--".$quote->getShippingAddress()->getEmail(),FILE_APPEND);
		}


578行增加重复判断
//当用户email为空时
		if(empty($quote->getCustomerEmail())){
			
			$quote->setCustomerEmail($quote->getBillingAddress()->getEmail()?$quote->getBillingAddress()->getEmail():$quote->getShippingAddress()->getEmail());	
			file_put_contents("test.txt","\r\n module-quote/Model/QuoteManagement.php submitQuote email is null 582:".$quote->getBillingAddress()->getEmail()."--".$quote->getShippingAddress()->getEmail(),FILE_APPEND);
		}
		
        //上面是判断email为空时处理
---------------------------------------------
        $order->setQuoteId($quote->getId());
        $order->setCustomerEmail($quote->getCustomerEmail());

 

修改三:

vi /www/wwwroot/www.broadout.com/vendor/magento/module-checkout/Model/GuestPaymentInformationManagement.php +162
//这里是自己添加的一行
$quote->getShippingAddress()->setEmail($email);

修改四:
最终保存sales_order表时 判断为空时给个默认值
vi /www/wwwroot/www.broadout.com/vendor/magento/module-sales/Model/Service/OrderService.php +231
//判断email为空时
			if(empty($order->getCustomerEmail())){
				$order->setCustomerEmail("yuanzelin8@gmail.com");
				file_put_contents("test.txt","\r\n module-sales/Model/Service/OrderService.php place() save email is null 233:".$order->getCustomerEmail()."--".$order->getQuoteId()."--".date("Y-m-d H:i:s",time()+8*60*60),FILE_APPEND);
				
			}

漏单关键点:

paypal/Model/Express/Checkout.php place 812:xx@gmail.com--xx@gmail.com
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值