0

I am using fygaro payment gateway. On successful payment , I am getting json response from fygaro on fygaro's domain itself. But on successful payment, I want to store some data in database for that what i need to do can someone help? Currently I am using call back api, code is as follows,

<?php

function svapp_fygaro_payment_check( WP_REST_Request $request ) {
    global $wpdb;

    header( 'HTTP/1.1 200 OK' );// Takes raw data from the request
    $json = file_get_contents(' php://input');// Converts it into a PHP object
    $data = json_decode($json);//Verify Data and assign to php variable
    $order_id = isset($data->customReference) ? $data->customReference : null;
    $createdAt = isset($data->createdAt) ? $data->createdAt : null;
    $jwt = isset($data->jwt) ? $data->jwt : null;

    //Add your code here.
    if(isset($jwt)){
        $amountpaid =  isset($jwt->amount) ? $jwt->amount : null;
        $clientData=  isset($jwt->clientData) ? $jwt->clientData : null;
    }
    //It should update table after successfull payment
    if(isset($data) || isset($jwt)){

        $res=$wpdb->insert('sv_payment_fygaro', array(
            'post_id' => '118',
            'external_reference' =>  $order_id,
            'paymentstatus' => '1',
            'jwt' => $jwt,
            'amount'=>$amountpaid,
            'createdAt'=>$createdAt,
        ));

    }

    return new WP_REST_Response( $res, 200 );
}
3
  • 2
    can you fix the code block? It has no indenting and lots of random <br> tags. Also it's not clear what the problem is, you described that you want to store data on a callback, but not what the question is, e.g. is the problem that your callback is never called? That it has a fatal php error? That your table is never updated? Please be specific, use the Edit link to update and modify your question to add more information. That includes information about how you're registering the endpoint, as well as what the sv_payment_fygaro is and where it comes from. Are you using WooCommerce?
    – Tom J Nowell
    Commented Oct 3, 2022 at 11:37
  • $jwt appears to be an object of some kind, since you're looking for $jwt->amount and $jwt->clientData. But in your insert statement you're treating it like it's a scalar value on the line 'jwt' => $jwt. You may need to serialize or json_encode() that value if you want to add it to the DB.
    – Pat J
    Commented Oct 3, 2022 at 14:03
  • Actually none of the values are inserting in my database. Atleast static values should be inserted so I will check about JWT data format. post_id and paymentstatus are also not inserting. Commented Oct 4, 2022 at 5:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.