Wocommerce Vnpay: Update status and empty cart

Gửi URL file php cho bên Vnpay sau đó chèn đoạn code sau vào file

  1. <?php
  2.  
  3. require_once($_SERVER['DOCUMENT_ROOT'].'/wp-load.php');
  4. global $woocommerce;
  5. $inputData = array();
  6. $returnData = array();
  7. $txnResponseCode = $_GET["vnp_ResponseCode"];
  8. $order = new WC_Order($_GET["vnp_TxnRef"]);
  9. // echo $order = getOrder(864);
  10. $secureHash = $_GET["vnp_SecureHash"];
  11.  
  12. if ($txnResponseCode == '00') {
  13. $woocommerce->cart->empty_cart();
  14. $returnData['RspCode'] = '00';
  15. $returnData['Message'] = 'Confirm Success';
  16. $returnData['Signature'] = $secureHash;
  17. $order->add_order_note(__($transStatus, 'woocommerce'));
  18. $order->update_status('completed');
  19. }
  20. else {
  21. $woocommerce->cart->empty_cart();
  22. $returnData['RspCode'] = '00';
  23. $returnData['Message'] = 'Confirm Success';
  24. $returnData['Signature'] = $secureHash;
  25. $order->add_order_note(__($transStatus, 'woocommerce'));
  26. $order->update_status('failed');
  27.  
  28. }
  29. echo json_encode($returnData);
  30. ?>

Leave a Reply

You must be logged in to post a comment.