Beispiel #1
0
 public function testUpdate()
 {
     $plan = self::createTestPlan();
     $plan->create();
     $this->assertEqual($plan->getName(), "Plano Silver");
     $plan->setName("Plano gold!");
     $plan->save();
     $plan2 = PagarMe_Plan::findById($plan->getId());
     $this->assertEqual($plan->getName(), $plan2->getName());
     $this->expectException(new IsAExpectation('PagarMe_Exception'));
     $plan2->setDays('60');
     $plan2->save();
 }
	public function gerarSolicitacaoPagarmeAssinatura() {

		$dados = $this->contaPagarme();

		Pagarme::setApiKey($dados['key_api']);
		
		if($this->formaPagamento == 'boleto'){
			$subscription = new PagarMe_Subscription(array(
		        'plan' => PagarMe_Plan::findById($this->plano),	        
		        'postback_url' => $this->notificationURL,
		        "payment_method" => $this->formaPagamento,
		        'customer'  => array(
		            'email' =>  $this->getEmailCliente(),
		            'nome'  =>  $this->getNomeCliente()
		        ),
		        'metadata'  => array(
		            'id_pedido' =>  $this->referencia,
		            'Detalhes Produtos' =>$this->detalhesProdutos	            
		        )	        
		    ));
		}else{
		    $subscription = new PagarMe_Subscription(array(
		        'plan' => PagarMe_Plan::findById($this->plano),
		        'card_hash' => $this->card_hash,
		        'postback_url' => $this->notificationURL,
		        "payment_method" => $this->formaPagamento,
		        'customer'  => array(
		            'email' =>  $this->getEmailCliente(),
		            'nome'  =>  $this->getNomeCliente()
		        ),
		        'metadata'  => array(
		            'id_pedido' =>  $this->referencia,
		            'Detalhes Produtos' =>$this->detalhesProdutos            
		        )	        
		    ));
		}

		try {
            $subscription->create();             
            $retorno['pago'] = true;
            $retorno['conteudo'] = $subscription;
            return $retorno;
        } catch (PagarMe_Exception $e) {
        	$retorno['pago'] = false;
            $retorno['conteudo'] = str_replace('consulte nossa documentação em https://pagar.me/docs.', 'consulte nosso FAQ.', $e->getMessage());
            return '<br> Erro : '.$retorno;
            
        }	    
		
	}
Beispiel #3
0
 protected function _processPlans($payment, $plans)
 {
     $allow_multiples = Mage::getStoreConfigFlag('payment/pagarme_subscriptions/allow_multiples');
     if (count($plans) > 1 && !$allow_multiples) {
         Mage::throwException(Mage::helper('pagarme')->__('Subscription of multiple plans are not allowed!'));
     }
     $api_mode = Mage::getStoreConfig('payment/pagarme_settings/mode');
     $api_key = Mage::getStoreConfig('payment/pagarme_settings/apikey_' . $api_mode);
     Pagarme::setApiKey($api_key);
     $customer_email = $payment->getOrder()->getCustomerEmail();
     $result = null;
     foreach ($plans as $id => $qty) {
         $_plan = Mage::getModel('pagarme/plans')->load($id);
         $subscription = new PagarMe_Subscription(array('plan' => PagarMe_Plan::findById($_plan->getRemoteId()), 'payment_method' => 'boleto', 'customer' => array('email' => $customer_email), 'postback_url' => Mage::getUrl('pagarme/transaction_subscription/postback', array('id' => $payment->getOrder()->getId()))));
         $subscription->create();
         $result = $subscription->current_transaction;
         $transaction = Mage::getModel('pagarme/subscriptions')->setPlanId($_plan->getId())->setRemotePlanId($_plan->getRemoteId())->setRemoteId($subscription->getId())->setTransactionId($result->getId())->setOrderId($payment->getOrder()->getId())->setPaymentMethod($result->getPaymentMethod())->setAmount(intval($result->getAmount()) / 100)->setCost($result->getCost())->setRemoteIP($result->getIp())->setBoletoUrl($result->getBoletoUrl())->setBoletoBarcode($result->getBoletoBarcode())->setBoletoExpirationDate($result->getBoletoExpirationDate())->setStatus($result->getStatus())->setCreatedAt($result->getDateCreated())->setUpdatedAt($result->getDateUpdated())->save();
     }
     // pagar.me info
     $payment->setPagarmeSubscriptionId($subscription->getId())->setPagarmeTransactionId($result->getId())->setPagarmeBoletoUrl($result->getBoletoUrl())->setPagarmeBoletoBarcode($result->getBoletoBarcode())->setPagarmeBoletoExpirationDate($result->getBoletoExpirationDate());
     $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('status' => $result->getStatus()));
 }
<?php
if(!empty($_POST)){
     $PLANO     = $_POST['codigoPlano']; 
     $CARD_HASH = $_POST['card_hash'];

    require("Pagarme.php");
    Pagarme::setApiKey("ak_test_VI0RjtmUyIqfXUUYdLHGDOCEUHoUtk");

    $subscription = new PagarMe_Subscription(array(
        'plan' => PagarMe_Plan::findById($PLANO),
        'card_hash' => $CARD_HASH,
        'customer' => array(
            'email' => "*****@*****.**"
        ),
        'postback_url' => "http://requestb.in/t923b4t9"
    ));

    $subscription->create();

}


?>
<html>
<head>
    <meta charset="UTF-8">
  <script src="https://pagar.me/assets/pagarme-v2.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
</head> 

<body>
Beispiel #5
0
 protected function _processPlans($payment, $plans)
 {
     $allow_multiples = Mage::getStoreConfigFlag('payment/pagarme_subscriptions/allow_multiples');
     if (count($plans) > 1 && !$allow_multiples) {
         Mage::throwException(Mage::helper('pagarme')->__('Subscription of multiple plans are not allowed!'));
     }
     $api_mode = Mage::getStoreConfig('payment/pagarme_settings/mode');
     $api_key = Mage::getStoreConfig('payment/pagarme_settings/apikey_' . $api_mode);
     Pagarme::setApiKey($api_key);
     $card_hash = $payment->getPagarmeCardHash() != null ? $payment->getPagarmeCardHash() : $payment->getPagarmeCheckoutHash();
     $customer_email = $payment->getOrder()->getCustomerEmail();
     $result = null;
     foreach ($plans as $id => $qty) {
         $_plan = Mage::getModel('pagarme/plans')->load($id);
         $subscription = new PagarMe_Subscription(array('plan' => PagarMe_Plan::findById($_plan->getRemoteId()), 'payment_method' => 'credit_card', 'card_hash' => $card_hash, 'customer' => array('email' => $customer_email), 'postback_url' => Mage::getUrl('pagarme/transaction_subscription/postback', array('id' => $payment->getOrder()->getId()))));
         $subscription->create();
         $result = $subscription->current_transaction;
         $transaction = Mage::getModel('pagarme/subscriptions')->setRemoteId($result->getId())->setOrderId($payment->getOrder()->getId())->setPaymentMethod($result->getPaymentMethod())->setAmount(intval($result->getAmount()) / 100)->setInstallments($result->getInstallments())->setCost($result->getCost())->setRemoteIP($result->getIp())->setAuthorizationCode($result->getAuthorizationCode())->setTid($result->getTid())->setStatus($result->getStatus())->setCreatedAt($result->getDateCreated())->setUpdatedAt($result->getDateUpdated())->save();
     }
     $payment->setCcOwner($result->getCardHolderName())->setCcLast4($result->getCardLastDigits())->setCcType(Mage::getSingleton('pagarme/source_cctype')->getTypeByBrand($result->getCardBrand()))->setPagarmeTransactionId($result->getId())->setPagarmeAntifraudScore($result->getAntifraudScore())->setTransactionId($result->getId())->setIsTransactionClosed(0);
     $payment->setTransactionAdditionalInfo(Mage_Sales_Model_Order_Payment_Transaction::RAW_DETAILS, array('status' => $result->getStatus()));
 }