Skip to content

Instantly share code, notes, and snippets.

@tallesairan
Created September 17, 2019 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tallesairan/bde0f5f8fb4cb2aff455f0e9db595092 to your computer and use it in GitHub Desktop.
Save tallesairan/bde0f5f8fb4cb2aff455f0e9db595092 to your computer and use it in GitHub Desktop.
<?php
$data = [];
$data['referencia'] = $_REQUEST['referencia'];
$data['chave_checkout'] = $_REQUEST['chave_checkout'];
$data['meio_pagamento'] = $_REQUEST['meio_pagamento'];
$data['nome'] = $_REQUEST['nome'];
$data['email'] = $_REQUEST['email'];
$data['cep'] = $_REQUEST['cep'];
$data['cnpj_cpf'] = $_REQUEST['cnpj_cpf'];
$data['telefone'] = $_REQUEST['tel'];
$data['tel'] = $_REQUEST['tel'];
$data['endereco'] = $_REQUEST['endereco'];
$data['numero'] = $_REQUEST['numero'];
$data['complemento'] = $_REQUEST['complemento'];
$data['bairro'] = $_REQUEST['bairro'];
$data['cidade'] = $_REQUEST['cidade'];
$data['estado'] = $_REQUEST['estado'];
$data['tipo_frete'] = '999999';
$data['quantidade'] = 1;
$data['NameOnCard'] = $_REQUEST['NameOnCard'];
$data['CreditCardNumber'] = $_REQUEST['CreditCardNumber'];
$data['ExpiryDate_month'] = $_REQUEST['ExpiryDate_month'];
$data['ExpiryDate_year'] = $_REQUEST['ExpiryDate_year'];
$data['SecurityCode'] = $_REQUEST['SecurityCode'];
$data['bandCartao'] = $_REQUEST['bandCartao'];
$data['parcelamento'] = $_REQUEST['parcelamento'];
$Process = new Process( $monetizzeApiKey, $monetizzeCtk, $monetizzeApiUrl, $appSession );
$response = [];
/*
*
*/
$response['startMonetizze'] = date( 'H:m:s' );
$monetizzeResponse = $Process->processCheckout( $data );
$response['monetizze'] = $monetizzeResponse;
$response['endMonetizze'] = date( 'H:m:s' );
<?php
namespace App;
class Process{
public $apiKey;
public $ctk;
public $apiUrl;
public $appSession;
public function __construct($apiKey, $ctk, $apiUrl, $appSession){
$this->apiKey = $apiKey;
$this->ctk = $ctk;
$this->apiUrl = $apiUrl;
$this->appSession = $appSession;
}
public function processCheckout($data)
{
$url = $this->apiUrl.'checkout/transparente/processar';
$header = array();
$header[] = 'Content-Type: application/json';
$header[] = 'Api-Key: ' . $this->apiKey;
$data_string = json_encode($data);
$header[] = 'Content-Length: ' . strlen($data_string);
$header[] = 'Keep-Alive: 300';
$header[] = 'Connection: Keep-Alive';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; tr-TR) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27" );
curl_setopt( $ch, CURLOPT_AUTOREFERER, true );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $data_string );
curl_setopt( $ch, CURLOPT_ENCODING, "utf-8" );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_REFERER, $url );
curl_setopt( $ch, CURLOPT_HTTPHEADER, $header );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); # required for https urls
curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT, 30 );
curl_setopt( $ch, CURLOPT_TIMEOUT, 35 );
curl_setopt( $ch, CURLOPT_MAXREDIRS, 1000 );
$content = curl_exec( $ch );
$err = curl_error( $ch );
curl_close( $ch );
if ( $err ) {
return [ 'error' => true, 'message' => $err ];
} else {
return json_decode($content,TRUE);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment