Campy
Campy

Reputation: 181

Paypal transaction tracking with Wordpress insert query?

I have done a transaction by sandbox mode on PayPal and I am using the Wordpress platform. The problem is my insert query was not executed.

After transaction, I have redirected the page from sandbox to xyz.com/payments-recieved and here I have printed the array and got this

Array
(
    [tx] => 44K35922JH447994H
    [st] => Completed
    [amt] => 29.00
    [cc] => USD
    [cm] => 
    [item_number] => 
    [sig] => NXsJYzHJsIoReedCjkhnpWPQgoqLa5j4fAxcqk+CxJqgVHjdlBB/yWx0h4JVez/e2k+OOKeuhdgh/YxcD0bcR8JwmCd3GFE5N2UxoOws2JusqegLytKpcp6PmEb92aj9B1+e6MMHOf5VKjwX0z50imRiRtjYUSRasFT5IKiNbyA=
)

After that I am trying to insert all the details into the table and here is my full code.

<?php
    /*
        Template Name: All Payments History
    */
    get_header();

    echo "Thanks for choosing our plan<br />";
    echo "<pre>";print_r($_REQUEST);

    global $wpdb; //global query variable

    if($_GET['st']=="Completed") /*check if transaction successfull or not*/
    {
     $item_transaction = $_GET['tx'];
     $item_price = $_GET['amt']; 
     $item_currency = $_GET['cc'];
     $item_no = $_GET['item_number'];
        $wpdb->insert("wp_paypal_payments_tracking", array(
        "transaction_id" => $item_transaction,
        "amount" => $item_price,
        "currency_type" => $item_currency,
        "item_number" => $item_no,
        ));
        echo "Payment Done Successfully";
    }
    get_footer();
?>

How we can fire insert query is there any problem in my code, please let me know and help me out.

Best Regards!!!

Upvotes: 4

Views: 105

Answers (1)

Candy Man
Candy Man

Reputation: 95

You can insert using the query, where wp_paypal_payments_tracking is your table name, you can change it

if ( !empty( $_REQUEST) && $_REQUEST['st']=='completed' ){
    $wpdb->insert( 'wp_paypal_payments_tracking', array(
        'tx' => $_REQUEST['tx'], 
        'st' => $_REQUEST['st'],
        'amt' => $_REQUEST['amt'], 
        'cc' => $_REQUEST['cc'],
        'cm' => $_REQUEST['cm'], 
        'item_number' => $_REQUEST['item_number'], 
        'sig' => $_REQUEST['sig'],
    );
}

Upvotes: 1

Related Questions