PHP - How do I integrate with API

0

I have a form in Wordpress (contact form 7), when the user submits, I need to generate a json with the fields and send it to an external API. I needed to use with class:

<?php
if ( !defined( 'ABSPATH' ) ) exit;

if ( !class_exists( 'CHN' ) ) :

    class CHN extends Base {
        // URL Path CNH
        protected $url_path = '/v1/path';

        // Array campos
        public $doador = array();

        // Array campos - cartão
        public $dados = array();
        public $credito = array();

        public $cpf;
        public $nome;
        public $data_nascimento;
        public $email;
        public $celular;


        public function __construct() {
        }

        public function generate_json() {
            $json_array = array(
                $this->doador
            );
            return json_encode($json_array);
        }

        public function finish_order() {
            $return = $this->CallAPI("POST", $url_base, $this->generate_json);
        }
    }

    $newDados = new Dados_CHN();

    $newDados->doador = array(
        "cpf" => $cpf,
        "nome" => $nome,
        "data_nascimento" => $data_nascimento,
        "email" => $email,
        "celular" => $celular,
    );

endif;

?>

Someone to help with some way?

I created two .php files, one that will be used specifically for one form, and another base, which will be used in more places (3 specific pages, 3 forms).

For the time being, I just need to generate this Json with the form data, and send it to the API, the next steps were for another time.

    
asked by anonymous 14.06.2018 / 18:18

0 answers