PHP - How do I integrate with API

Asked

Viewed 330 times

0

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

<?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 class files, one that will be used specifically for a form, and another base, which will be used in more places (there will be 3 specific pages, with 3 forms).

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

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.