コード例 #1
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()));
 }
コード例 #2
0
<?php   
require("Pagarme.php");
Pagarme::setApiKey("ak_test_VI0RjtmUyIqfXUUYdLHGDOCEUHoUtk");


$subscription = PagarMe_Subscription::findById("13140");
$ASSINATURA = formataValoresAssinatura($subscription);

print_r($ASSINATURA);
echo '<br><br><br><br><br>';
print_r($subscription);

function formataValoresAssinatura($subscription){

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

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

    $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['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'];    
コード例 #3
0
<?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>
コード例 #4
0
 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;
 }
コード例 #5
0
ファイル: Subscription.php プロジェクト: edusnets/pagarme-php
 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());
 }
コード例 #6
0
ファイル: Cc.php プロジェクト: eneiasramos/pagarme-magento
 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()));
 }