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;
            
        }	    
		
	}
예제 #2
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()));
 }
     $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>

  <form id="payment_form" action="transacaoAssinatura.php" method="POST">
예제 #4
0
 public function testCreateWithPlan()
 {
     $plan = self::createTestPlan();
     $subscription = self::createTestSubscription();
     $plan->create();
     $subscription->setPlan($plan);
     $subscription->create();
     $this->validateSubscription($subscription);
     $this->assertTrue($subscription->getPlan()->getId());
     $this->assertTrue($plan->getId());
     $subscription2 = PagarMe_Subscription::findById($subscription->getId());
     $this->assertTrue($subscription2->getPlan());
     $this->assertEqual($subscription2->getPlan()->getId(), $plan->getId());
     $card = self::createTestCard();
     $subscription3 = new PagarMe_Subscription(array('customer' => array('email' => '*****@*****.**')));
     $subscription3->setPlan($plan);
     $subscription3->setCard($card);
     $subscription3->create();
     $this->assertTrue($subscription3->getId());
     $card->create();
     $subscription4 = new PagarMe_Subscription(array('customer' => array('email' => '*****@*****.**')));
     $subscription4->setPlan($plan);
     $subscription4->setCard($card);
     $subscription4->create();
     $this->assertTrue($subscription4->getId());
     $subscription4 = new PagarMe_Subscription(array('card' => $card, 'customer' => array('email' => '*****@*****.**')));
     $subscription4->setPlan($plan);
     $subscription4->create();
     $this->assertTrue($subscription4->getId());
 }
예제 #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()));
 }