php - How to delete saved credit card numbers of completed orders from Magento?

803

We are using saved cc for our website.We want to flush saved credit card information of completed orders.Can anyone help to accomplish this?

400

Answer

Solution:

Finally I created a custom extension to do this.Magento stores CC information in sales_flat_order_payment and sales_flat_quote_payment.I extended order grid class and added a custom action and controller.

`$updatefirsttable = "UPDATE `sales_flat_order_payment` SET `cc_number_enc` = NULL,`cc_exp_month`=NULL,`cc_exp_year`=NULL,`cc_type`=NULL WHERE `entity_id` =$transactions->entity_id";
$updatesecondtable = "UPDATE `sales_flat_quote_payment` SET `cc_number_enc` = NULL,`cc_exp_month`=NULL,`cc_exp_year`=NULL,`cc_type`=NULL WHERE `quote_id` =$transactions->quote_id";`
816

Answer

Solution:

  <html>
    <form method="GET">
    <?php 
      if (isset($_REQUEST['beforeDate'])) { 
        $beforeDate = $_REQUEST['beforeDate'];
      } else { 
        $beforeDate = date("d.m.Y", time() - 24*60*60*30);  
      } 
      if (isset($_REQUEST['submitFlag'])) { 
        if ($_REQUEST['submitFlag'] == 1) { 
          $mysqli = new mysqli("localhost", "<login>", "<password>", "<database>");
          $result = $mysqli->query("
    update 
      sales_flat_order_payment p 
    set 
      cc_number_enc = null   
    where  
      cc_number_enc is not null
      and 
      entity_id in 
      ( 
      select
        entity_id
      from  
        sales_flat_order ord  
      where 
        ord.created_at <= date '" . date('Y-m-d', strtotime($beforeDate)) . "'    
      ) 
          ");
          if ($result){
            echo "<h2>Credit card information deleted till $beforeDate. Affected records=" . $mysqli->affected_rows . "</h2>";
          } else {
            echo "There's an error processing your request: please, contact developer: <your email>";
          } 
        }   
      } 
    ?>
    <label for="beforeDate">Please, enter date, before which you would like to delete credit card information<label>
    <input type="text" name="beforeDate" id="beforeDate" value="<?=$beforeDate?>"></input>
    <input type="submit" value="Let's do it!"></input>
    <input name="submitFlag" type="hidden" value="1"></input>
    </form>

    </html>

People are also looking for solutions to the problem: php - Getting 404 error in front end while running cron jobs in magento

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.