public function confirm()
 {
     if ($this->session->data['payment_method']['code'] == 'pagar_me_checkout') {
         $this->load->model('checkout/order');
         $this->load->model('payment/pagar_me_checkout');
         Pagarme::setApiKey($this->config->get('pagar_me_checkout_api'));
         $transaction = PagarMe_Transaction::findById($this->request->post['token']);
         $amount = $transaction->amount;
         try {
             $transaction->capture($amount);
         } catch (Exception $e) {
             $this->log->write($e->getMessage());
         }
         $status = $transaction->status;
         if ($transaction->status == 'authorized' || $transaction->status == 'paid') {
             $status = 'paid';
             $this->model_payment_pagar_me_checkout->addTransactionId($this->session->data['order_id'], $transaction->id, NULL);
         } else {
             $this->model_payment_pagar_me_checkout->addTransactionId($this->session->data['order_id'], $transaction->id, $transaction->boleto_url);
             $this->session->data['checkout_pagar_me_boleto_url'] = $transaction->boleto_url;
         }
         $this->model_checkout_order->addOrderHistory($this->session->data['order_id'], $this->config->get('pagar_me_checkout_order_' . $status), '', true);
         $this->response->redirect($this->url->link('checkout/success', '', 'SSL'));
     }
 }
Exemplo n.º 2
0
 public function testDeepMetadata()
 {
     $transaction = self::createTestTransaction();
     $transaction->setMetadata(array('basket' => array('session' => array('date' => "31/04/2014", 'time' => "12:00:00"), 'ticketTypeId' => '5209', 'type' => "inteira", 'quantity' => '1', 'price' => 2000)));
     $transaction->charge();
     $this->assertTrue($transaction->getId());
     $transaction2 = PagarMe_Transaction::findById($transaction->getId());
     $metadata = $transaction2->getMetadata();
     $this->assertEqual($metadata['basket']['quantity'], "1");
     $this->assertEqual($metadata['basket']['session']['date'], "31/04/2014");
 }
Exemplo n.º 3
0
<?php   
require("Pagarme.php");
Pagarme::setApiKey("ak_test_VI0RjtmUyIqfXUUYdLHGDOCEUHoUtk");

$transaction = PagarMe_Transaction::findById("177784");

$TRANSACAO = formataValoresTransacao($transaction);



echo utf8_decode("valor da transação : ".$TRANSACAO['total']);
echo "<br>valor de custo : ".$TRANSACAO['transacao_custo'];
echo '<br><br><br><br><br>';
print_r($TRANSACAO);

//echo '<br><br><br><br><br>';       
//print_r($transaction);


function formataValoresTransacao($transaction){

    $valor_transacao       = substr($transaction->amount, 0, -2) . '.' . substr($transaction->amount, -2);
    $custo 			       = number_format($transaction->cost,0, '.', '');    
    $valor_custo	       = substr($custo, 0, -2) . '.' . substr($custo, -2);    
    $TRANSACAO['parcelas'] = $transaction->installments;

    if($TRANSACAO['parcelas'] >= 2 && $TRANSACAO['parcelas'] <= 6) $TRANSACAO['taxas'] = (1.49 + 2.60);
    else if($TRANSACAO['parcelas'] >= 7 && $TRANSACAO['parcelas'] <= 12) $TRANSACAO['taxas'] = (1.49 + 2.9);
    else $TRANSACAO['taxas'] = (1.49 + 2.5);

    $TRANSACAO['total'] = number_format($valor_transacao, 2, '.', '');
 public function formataValoresAssinatura($id, $tipo)
 {
     $dados = $this->contaPagarme();
     Pagarme::setApiKey($dados['key_api']);
     if ($tipo == 'transaction') {
         $transaction = PagarMe_Transaction::findById($id);
         $subscription = PagarMe_Subscription::findById($transaction->subscription_id);
     } else {
         $subscription = PagarMe_Subscription::findById($id);
     }
     $valor_transacao = substr($subscription->current_transaction->amount, 0, -2) . '.' . substr($subscription->current_transaction->amount, -2);
     if ($subscription->current_transaction->cost == 0) {
         $custo = "380";
     } else {
         $custo = number_format($subscription->current_transaction->cost, 0, '.', '');
     }
     $valor_custo = substr($custo, 0, -2) . '.' . substr($custo, -2);
     $ASSINATURA['parcelas'] = $subscription->current_transaction->installments;
     //BOLETO
     $ASSINATURA['boleto_url'] = $subscription->current_transaction->boleto_url;
     $ASSINATURA['boleto_barcode'] = $subscription->current_transaction->boleto_barcode;
     $ASSINATURA['boleto_dataExpiracao'] = substr($subscription->current_transaction->expiration_date, 0, 10);
     if (empty($ASSINATURA['boleto_url'])) {
         if ($ASSINATURA['parcelas'] >= 2 && $ASSINATURA['parcelas'] <= 6) {
             $ASSINATURA['taxas'] = 1.49 + 2.6;
         } else {
             if ($ASSINATURA['parcelas'] >= 7 && $ASSINATURA['parcelas'] <= 12) {
                 $ASSINATURA['taxas'] = 1.49 + 2.9;
             } else {
                 $ASSINATURA['taxas'] = 1.49 + 2.5;
             }
         }
         //cálculo para ver a taxa
         $ASSINATURA['transacao_taxa_05'] = 0.5 * 100 / substr($subscription->current_transaction->amount, 0, -2);
         $ASSINATURA['transacao_taxa_05'] = number_format($ASSINATURA['transacao_taxa_05'], 2, '.', '');
         $ASSINATURA['taxas'] = $ASSINATURA['taxas'] + $ASSINATURA['transacao_taxa_05'];
     }
     $ASSINATURA['total'] = number_format($valor_transacao, 2, '.', '');
     $ASSINATURA['transacao_custo'] = number_format($valor_custo, 2, '.', '');
     $ASSINATURA['total_liquido'] = number_format($ASSINATURA['total'] - $ASSINATURA['transacao_custo'], 2, '.', '');
     $ASSINATURA['venda_id'] = $subscription->metadata->id_pedido;
     $ASSINATURA['id'] = $subscription->current_transaction->id;
     $ASSINATURA['id_asinatura'] = $subscription->id;
     $ASSINATURA['data'] = $subscription->current_transaction->date_created;
     $ASSINATURA['ultima_atualizacao'] = $subscription->current_transaction->date_updated;
     $ASSINATURA['status'] = $subscription->status;
     //DADOS ASSINATURA
     $ASSINATURA['data_inicio_cobranca'] = substr($subscription->current_period_start, 0, 10) . ' 00:00';
     $ASSINATURA['data_fim_cobranca'] = substr($subscription->current_period_end, 0, 10) . ' 23:59';
     //DADOS CARTÃO
     $ASSINATURA['cartao_fingerprint'] = $subscription->card->fingerprint;
     $ASSINATURA['cartao_id'] = $subscription->card->id;
     $ASSINATURA['cartao_nome'] = $subscription->card->holder_name;
     //DADOS PLANO
     $ASSINATURA['plano_id'] = $subscription->plan->id;
     $ASSINATURA['plano_valor'] = $subscription->plan->amount;
     $ASSINATURA['plano_dias'] = $subscription->plan->days;
     $ASSINATURA['plano_nome'] = $subscription->plan->name;
     $ASSINATURA['plano_dias_tiral'] = $subscription->plan->trial_days;
     $ASSINATURA['plano_data_criacao'] = $subscription->plan->date_created;
     //DADOS CLIENTE
     $ASSINATURA['cliente_id'] = $subscription->customer->id;
     $ASSINATURA['cliente_nome'] = $subscription->customer->name;
     $ASSINATURA['cliente_cpf'] = $subscription->customer->document_number;
     $ASSINATURA['cliente_email'] = $subscription->customer->email;
     $ASSINATURA['cliente_nome'] = $subscription->customer->name;
     return $ASSINATURA;
 }
Exemplo n.º 5
0
<?php

	require("Pagarme.php");

    Pagarme::setApiKey("ak_test_VI0RjtmUyIqfXUUYdLHGDOCEUHoUtk");

	$transaction = PagarMe_Transaction::findById("176698");

	$POST['id'] = $transaction->id;
	$POST['fingerprint'] = $transaction->card->fingerprint;
	print_r($POST);
	echo'<br><br><br><br>';
	if(PagarMe::validateFingerprint($POST['id'], $POST['fingerprint'])) {
		echo 'valida';
 	}else{
 		echo 'false';
 	}
    
       
?>
    
Exemplo n.º 6
0
            if (empty($_REQUEST['email'])) {
                $error['email'] = 'Campo E-Mail obrigatório';
            } else {
                $field['email'] = $_REQUEST['email'];
            }
            if (count($field)) {
                $session->set('field', $field);
            }
            if (count($error)) {
                $session->set('error', $error);
                header('location: /../../admin/users/create.php');
            } else {
                // Gravação dos dados do form
                header('location: /../../admin/users/create.php');
            }
            break;
        case 'payment':
            $token = $_REQUEST['token'];
            \PagarMe::setApiKey("ak_test_gxdZQnY40daggFTyF2UA6dA6HgpyBR");
            $transaction = \PagarMe_Transaction::findById("{$token}");
            $transaction->capture(75000);
            var_dump($transaction);
            break;
        default:
            echo $_REQUEST['acao'];
            die('default');
            break;
    }
} else {
    die('Request Vazio');
}