<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class MembershipForm extends MY_Controller {

	public function __construct() {
		parent::__construct();
		$currency = '';

		$this->$currency =  GeneralSettings();
	}

	public function index(){


		$data['page'] = 'MEMBERSHIP FORM';
		$data['title'] = 'MEMBERSHIP FORM';

		$this->load->view('membership-form/index', $data);
	}

	public function CheckoutMembership()
	{

		$membershipType = $this->input->post('membershipType');
		$membershipId = $this->input->post('membershipId');
		$transactionId = $this->input->post('transactionId');
		$paymentMethod = $this->input->post('paymentMethod');



		// print_r($this->input->post()); die();
		
		$ch = curl_init();
		curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
		curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

		curl_setopt($ch, CURLOPT_URL, ApiBaseUrl()['url'].postAPI()['url']);
		curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
		curl_setopt($ch, CURLOPT_POST, 1);
		

		$postData = array(
			"_id" => $this->session->userdata('id'),
			"dataJson" => array(
				"membershipType" => $membershipType,
				"membershipId" => $membershipId,
				"transactionId" => $transactionId,
				"paymentMethod" => $paymentMethod,
				"membershipStartDate" => date('m/d/Y'),
				"membershipStartTime" => date('h:i A')
			),
			"componentConfig" => array(
				"moduleName" => "Contacts",
				"productID" => ApiBaseUrl()['productID'],
				"clientID" => ApiBaseUrl()['clientID']
			)
		);


		$jsonPayload = json_encode($postData);

		curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonPayload);


		$token = $this->session->userdata('token');
		$headers = array();
		$headers[] = 'Authorization: Bearer '.$token.'';
		$headers[] = 'Content-Type: application/json';
		curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

		$result = curl_exec($ch);
		$response = json_decode($result, true);
		if (curl_errno($ch)) {
			echo 'Error:' . curl_error($ch);
		}
		curl_close($ch);

		echo json_encode($response);
	}
}