charge() public method

public charge ( )
 public function payment()
 {
     $this->load->model('checkout/order');
     $this->load->model('account/customer');
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $customer = $this->model_account_customer->getCustomer($order_info['customer_id']);
     if ($this->config->get('dados_status')) {
         if ($customer['cpf'] != '') {
             $document_number = $this->removeSeparadores($customer['cpf']);
             $customer_name = $order_info['payment_firstname'] . " " . $order_info['payment_lastname'];
         } else {
             $document_number = $this->removeSeparadores($customer['cnpj']);
             $customer_name = $customer['razao_social'];
         }
         $numero = $order_info['payment_numero'];
         $complemento = $order_info['payment_company'];
     } else {
         $document_number = $this->removeSeparadores($order_info['payment_tax_id']);
         $customer_name = $order_info['payment_firstname'] . " " . $order_info['payment_lastname'];
         $numero = 'Sem número';
         $complemento = '';
     }
     Pagarme::setApiKey($this->config->get('pagar_me_cartao_api'));
     $transaction = new PagarMe_Transaction(array('amount' => $this->request->post['amount'], 'card_hash' => $this->request->post['card_hash'], 'installments' => $this->request->post['installments'], 'postback_url' => HTTP_SERVER . 'index.php?route=payment/pagar_me_cartao/callback', "customer" => array("name" => $customer_name, "document_number" => $document_number, "email" => $order_info['email'], "address" => array("street" => $order_info['payment_address_1'], "neighborhood" => $order_info['payment_address_2'], "zipcode" => $order_info['payment_postcode'], "street_number" => $numero, "complementary" => $complemento), "phone" => array("ddd" => substr(preg_replace('/[^0-9]/', '', $order_info['telephone']), 0, 2), "number" => substr(preg_replace('/[^0-9]/', '', $order_info['telephone']), 2)))));
     $transaction->charge();
     $status = $transaction->status;
     // status da transação
     $id_transacao = $transaction->id;
     $json = array();
     $this->log->write($status);
     $this->load->model('payment/pagar_me_cartao');
     if ($status == 'paid' || $status == 'processing') {
         $this->model_payment_pagar_me_cartao->addTransactionId($this->session->data['order_id'], $id_transacao, $this->request->post['installments'], $this->request->post['bandeira']);
         $json['success'] = true;
     } else {
         $this->model_payment_pagar_me_cartao->addTransactionId($this->session->data['order_id'], $id_transacao);
         $json['success'] = false;
     }
     $this->response->setOutput(json_encode($json));
 }
 public function payment()
 {
     $this->load->model('checkout/order');
     $this->load->model('account/customer');
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $customer = $this->model_account_customer->getCustomer($order_info['customer_id']);
     if ($this->config->get('dados_status')) {
         if ($customer['cpf'] != '') {
             $document_number = $this->removeSeparadores($customer['cpf']);
             $customer_name = $order_info['payment_firstname'] . " " . $order_info['payment_lastname'];
         } else {
             $document_number = $this->removeSeparadores($customer['cnpj']);
             $customer_name = $customer['razao_social'];
         }
         $numero = $order_info['payment_numero'];
         $complemento = $order_info['payment_company'];
     } else {
         $document_number = $this->removeSeparadores($order_info['payment_tax_id']);
         $customer_name = $order_info['payment_firstname'] . " " . $order_info['payment_lastname'];
         $numero = 'Sem número';
         $complemento = '';
     }
     Pagarme::setApiKey($this->config->get('pagar_me_boleto_api'));
     $transaction = new PagarMe_Transaction(array('amount' => $this->request->post['amount'], 'payment_method' => 'boleto', 'boleto_expiration_date' => date('Y-m-d', strtotime('+' . $this->config->get('pagar_me_boleto_dias_vencimento') + 1 . ' days')), 'postback_url' => HTTP_SERVER . 'index.php?route=payment/pagar_me_boleto/callback', "customer" => array("name" => $customer_name, "document_number" => $document_number, "email" => $order_info['email'], "address" => array("street" => $order_info['payment_address_1'], "neighborhood" => $order_info['payment_address_2'], "zipcode" => $this->removeSeparadores($order_info['payment_postcode']), "street_number" => $numero, "complementary" => $complemento), "phone" => array("ddd" => substr(preg_replace('/[^0-9]/', '', $order_info['telephone']), 0, 2), "number" => substr(preg_replace('/[^0-9]/', '', $order_info['telephone']), 2)))));
     try {
         $transaction->charge();
     } catch (Exception $e) {
         $this->log->write("Erro Pagar.Me boleto: " . $e->getMessage());
         die;
     }
     $status = $transaction->status;
     // status da transação
     $boleto_url = $transaction->boleto_url;
     // URL do boleto bancário
     $id_transacao = $transaction->id;
     $json = array();
     if ($status == 'waiting_payment') {
         $this->load->model('payment/pagar_me_boleto');
         $this->model_payment_pagar_me_boleto->addTransactionId($this->session->data['order_id'], $id_transacao, $boleto_url);
         $json['transaction'] = $transaction->id;
         $json['success'] = true;
         $json['boleto_url'] = $boleto_url;
     } else {
         $json['success'] = false;
     }
     $this->response->setOutput(json_encode($json));
 }
 public function iniciaPagamentoPagarme()
 {
     $pagarme = $this->obterCredenciaisPagarme();
     Pagarme::setApiKey($pagarme['pagarme_key_api']);
     $transaction = new PagarMe_Transaction(array("amount" => $this->valor, "card_hash" => $this->card_hash, "payment_method" => $this->formaPagamento, 'postback_url' => $this->notificationURLPagarMe, "installments" => $this->parcelas, "email" => $this->emailUsuario, 'metadata' => array('id_pedido' => $this->transacaoID), "customer" => array("name" => $this->nomeUsuario, "email" => $this->emailUsuario)));
     try {
         $transaction->charge();
         $retorno['status'] = true;
         $retorno['conteudo'] = $transaction;
         return $retorno;
     } catch (PagarMe_Exception $e) {
         $msg = str_replace('consulte nossa documentação em https://pagar.me/docs.', 'consulte nosso FAQ.', $e->getMessage());
         $retorno['status'] = false;
         $retorno['conteudo'] = '<br> Erro : ' . $msg;
         return $retorno;
     }
 }
Esempio n. 4
0
 public function testValidation()
 {
     $transaction = new PagarMe_Transaction();
     $transaction->setCardNumber("123");
     $this->expectException(new IsAExpectation('PagarMe_Exception'));
     $transaction->charge();
     $transaction->setCardNumber('4111111111111111');
     $transaction->setCardHolderName('');
     $this->expectException(new IsAExpectation('PagarMe_Exception'));
     $transaction->charge();
     $transaction->setCardHolderName("Jose da silva");
     $transaction->setExpiracyMonth(13);
     $this->expectException(new IsAExpectation('PagarMe_Exception'));
     $transaction->charge();
     $transaction->setExpiracyMonth(12);
     $transaction->setExpiracyYear(10);
     $this->expectException(new IsAExpectation('PagarMe_Exception'));
     $transaction->charge();
     $transaction->setExpiracyYear(16);
     $transaction->setCvv(123456);
     $this->expectException(new IsAExpectation('PagarMe_Exception'));
     $transaction->charge();
     $transaction->setCvv(123);
     $transaction->setAmount(0);
     $this->expectException(new IsAExpectation('PagarMe_Exception'));
     $transaction->charge();
     $transaction->setAmount(1000);
 }
Esempio n. 5
0
            'postback_url' => "http://requestb.in/1gmoytx1",
            'boleto_expiration_date' => (date('d/m/Y', strtotime(date('d-m-Y') . ' + 7 days'))),            
            "customer" => array(
                "name" => "Thiago",
                "document_number" => "135.105.251-91",
                "email" => "*****@*****.**",
                "address" => array(
                    "street" => "Av. Brigadeiro Faria Lima",
                    "neighborhood" => "Jardim Paulistano",
                    "zipcode" => "01452000",
                    "street_number" => "2941",
                    "complementary" => "8º andar"
                ),
                "phone" => array(
                    "ddd" => "11",
                    "number" => "30713261"
                ),
                
            
        )));

        $transaction->charge();

        $boleto_url = $transaction->boleto_url; // URL do boleto bancário
        $boleto_barcode = $transaction->boleto_barcode; // código de barras do boleto bancário

        $transaction->charge();        
    
       
?>
 public function payment()
 {
     $this->load->model('checkout/order');
     $this->load->model('account/customer');
     $order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
     $customer = $this->model_account_customer->getCustomer($order_info['customer_id']);
     $document_number = '';
     $numero = 'Sem Número';
     $complemento = '';
     $customer_name = trim($order_info['payment_firstname']) . ' ' . trim($order_info['payment_lastname']);
     /* Pega os custom fields de CPF/CNPJ, número e complemento */
     $this->load->model('account/custom_field');
     $custom_fields = $this->model_account_custom_field->getCustomFields($customer['customer_group_id']);
     foreach ($custom_fields as $custom_field) {
         if ($custom_field['location'] == 'account') {
             if ((strpos(strtolower($custom_field['name']), 'cpf') || strpos(strtolower($custom_field['name']), 'cnpj')) !== false) {
                 $document_number = $order_info['custom_field'][$custom_field['custom_field_id']];
             }
         } elseif ($custom_field['location'] == 'address') {
             if (strpos(strtolower($custom_field['name']), 'numero') !== false || strpos(strtolower($custom_field['name']), 'número') !== false) {
                 $numero = $order_info['payment_custom_field'][$custom_field['custom_field_id']];
             } elseif (strpos(strtolower($custom_field['name']), 'complemento')) {
                 $complemento = $order_info['payment_custom_field'][$custom_field['custom_field_id']];
             }
         }
     }
     Pagarme::setApiKey($this->config->get('pagar_me_cartao_api'));
     $transaction = new PagarMe_Transaction(array('amount' => $this->request->post['amount'], 'card_hash' => $this->request->post['card_hash'], 'installments' => $this->request->post['installments'], 'postback_url' => HTTP_SERVER . 'index.php?route=payment/pagar_me_cartao/callback', "customer" => array("name" => $customer_name, "document_number" => $document_number, "email" => $order_info['email'], "address" => array("street" => $order_info['payment_address_1'], "neighborhood" => $order_info['payment_address_2'], "zipcode" => $this->removeSeparadores($order_info['payment_postcode']), "street_number" => $numero, "complementary" => $complemento), "phone" => array("ddd" => substr(preg_replace('/[^0-9]/', '', $order_info['telephone']), 0, 2), "number" => substr(preg_replace('/[^0-9]/', '', $order_info['telephone']), 2)))));
     $transaction->charge();
     $status = $transaction->status;
     // status da transação
     $id_transacao = $transaction->id;
     $json = array();
     $this->log->write($status);
     $this->load->model('payment/pagar_me_cartao');
     if ($status == 'paid' || $status == 'processing') {
         $this->model_payment_pagar_me_cartao->addTransactionId($this->session->data['order_id'], $id_transacao, $this->request->post['installments'], $this->request->post['bandeira']);
         $json['success'] = true;
     } else {
         $this->model_payment_pagar_me_cartao->addTransactionId($this->session->data['order_id'], $id_transacao);
         $json['success'] = false;
     }
     $this->response->setOutput(json_encode($json));
 }