protected function _placeorder($config, $charge, $order, $payment_method)
 {
     //building charge
     $respondCharge = $this->_createCharge($config);
     $transaction = commerce_payment_transaction_new('commerce_checkoutpayment', $order->order_id);
     $transaction->instance_id = $payment_method['instance_id'];
     $transaction->amount = $charge['amount'];
     $transaction->currency_code = $charge['currency_code'];
     $transaction->payload[REQUEST_TIME] = $respondCharge->getCreated();
     $default_currency = commerce_default_currency();
     $amountCents = number_format(commerce_currency_convert($charge['amount'], $charge['currency_code'], $default_currency), 0, '', '');
     $toValidate = array('currency' => $default_currency, 'value' => $amountCents, 'trackId' => $order->order_id);
     $Api = CheckoutApi_Api::getApi(array('mode' => $config['mode']));
     $validateRequest = $Api::validateRequest($toValidate, $respondCharge);
     if ($respondCharge->isValid()) {
         if (preg_match('/^1[0-9]+$/', $respondCharge->getResponseCode())) {
             if ($validateRequest['status']) {
                 $transaction->message = 'Your transaction has been successfully authorized with transaction id : ' . $respondCharge->getId();
             } else {
                 $transaction->message = '';
                 foreach ($validateRequest['message'] as $errormessage) {
                     $transaction->message .= $errormessage . '. ';
                 }
                 $transaction->message .= 'Please contact your merchant.';
             }
             $transaction->status = COMMERCE_PAYMENT_STATUS_PENDING;
             commerce_payment_transaction_save($transaction);
             return true;
         }
         $transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
         drupal_set_message(t('We could not process your card. Please verify your information again or try a different card.'), 'error');
         drupal_set_message(check_plain($respondCharge->getMessage()), 'error');
         $transaction->message = $respondCharge->getRawRespond();
         commerce_payment_transaction_save($transaction);
         return false;
     } else {
         $transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
         $transaction->message = $respondCharge->getRawRespond();
         drupal_set_message(t('We received the following error processing your card. Please verify your information again or try a different card.'), 'error');
         drupal_set_message(check_plain($respondCharge->getExceptionState()->getErrorMessage()), 'error');
         commerce_payment_transaction_save($transaction);
         return false;
     }
 }
 /**
  * Helper function creating multiple dummy orders.
  * If no customers or products exist, then one of each get created.
  */
 protected function createOrders($amount = 1, $createTransactions = FALSE, $possibleDates = array())
 {
     if (empty($this->products)) {
         $this->createProducts();
     }
     if (empty($this->customers)) {
         $this->createCustomers();
     }
     $order_status = 'completed';
     if ($createTransactions) {
         $order_status = 'pending';
     }
     for ($i = 0; $i < $amount; $i++) {
         $totalProducts = rand(1, count($this->products));
         $products = array();
         for ($x = 0; $x < $totalProducts; $x++) {
             $product = $this->products[array_rand($this->products)];
             $products[$product->product_id] = rand(1, 10);
         }
         if (!($customer = next($this->customers))) {
             $customer = reset($this->customers);
         }
         $order = $this->createDummyOrder($customer->uid, $products, $order_status);
         if (!empty($possibleDates)) {
             $date = $possibleDates[array_rand($possibleDates)];
             $order->created = $date;
             commerce_order_save($order);
         }
         $transaction = NULL;
         if ($createTransactions) {
             $transaction = commerce_payment_transaction_new('commerce_payment_example', $order->order_id);
             $transaction->amount = $order->commerce_order_total[LANGUAGE_NONE][0]['amount'];
             $transaction->status = 'success';
             commerce_payment_transaction_save($transaction);
         }
         $this->orders[] = array('commerce_transaction' => $transaction, 'commerce_order' => $order, 'products' => $products);
     }
 }
예제 #3
0
 /**
  * This is helper function called inside createProgrammatically used for order payment transaction
  * @param $order
  *  This is order object
  */
 private function paymentTransaction($order)
 {
     $transaction = commerce_payment_transaction_new('commerce_stripe', $order->order_id);
     $payment_method = commerce_payment_method_instance_load('commerce_stripe|commerce_payment_commerce_stripe');
     $strip_token = Utils::getStripeToken()->verify(get_class());
     $charge = $order->commerce_order_total['und'][0];
     if (!commerce_stripe_load_library()) {
         drupal_set_message(t('Error capturing payment. Please contact shop admin to proceed.'), 'error');
     }
     $c = array('amount' => $charge['amount'], 'currency' => $charge['currency_code'], 'card' => $strip_token, 'capture' => TRUE, 'description' => t('Order Number: @order_number', array('@order_number' => $order->order_number)));
     \Stripe::setApiKey($payment_method['settings']['secret_key']);
     try {
         if ($charge['amount'] > 0) {
             $response = \Stripe_Charge::create($c);
             $transaction->remote_id = $response->id;
             $transaction->payload[REQUEST_TIME] = $response->__toJSON();
             $transaction->remote_status = 'AUTH_CAPTURE';
             $transaction->message = t('Payment authorized only successfully.');
             $transaction->message .= '<br />' . t('Captured: @date', array('@date' => format_date(REQUEST_TIME, 'short')));
             $transaction->message .= '<br />' . t('Captured Amount: @amount', array('@amount' => $charge['amount'] / 100));
             $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
             $transaction->amount = $charge['amount'];
             $transaction->currency_code = $charge['currency_code'];
             sleep(5);
             commerce_payment_transaction_save($transaction);
             commerce_payment_commerce_payment_transaction_insert($transaction);
         }
     } catch (Exception $e) {
         drupal_set_message(t('We received the following error when trying to capture the transaction.'), 'error');
         drupal_set_message(check_plain($e->getMessage()), 'error');
         $transaction->payload[REQUEST_TIME] = $e->json_body;
         $transaction->message = t('Capture processing error: @stripe_error', array('@stripe_error' => $e->getMessage()));
         $transaction->status = COMMERCE_PAYMENT_STATUS_FAILURE;
         $transaction->remote_status = 'FAILED';
         commerce_payment_transaction_save($transaction);
     }
     if ($charge['amount'] == 0) {
         $user = user_load($order->uid);
         $transaction->instance_id = $payment_method['instance_id'];
         $transaction->amount = $charge['amount'];
         $transaction->currency_code = $charge['currency_code'];
         $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
         $transaction->message = '@name';
         $transaction->message_variables = array('@name' => 'Payment authorized only successfully');
         commerce_payment_transaction_save($transaction);
         commerce_payment_commerce_payment_transaction_insert($transaction);
     }
     if (module_exists('commerce_cardonfile')) {
         $strip_token = Utils::getStripeToken()->verify(get_class());
         $card = _commerce_stripe_create_card($strip_token, $order->uid, $payment_method);
         $remote_id = (string) $card->customer . '|' . (string) $card->id;
         $card_data = commerce_cardonfile_new();
         $card_data->uid = $order->uid;
         $card_data->order_id = $order->order_id;
         $card_data->payment_method = $payment_method['method_id'];
         $card_data->instance_id = $payment_method['instance_id'];
         $card_data->remote_id = $remote_id;
         $card_data->card_type = 'Visa';
         $card_data->card_name = $user->name;
         $card_data->card_number = '1111';
         $card_data->card_exp_month = 5;
         $card_data->card_exp_year = 2018;
         $card_data->status = 1;
         $card_data->instance_default = 1;
         commerce_cardonfile_save($card_data);
     }
 }
function take_action($order, $rta2)
{
    $order = commerce_order_load($order);
    $payment_method = commerce_payment_method_instance_load('bank_transfer|commerce_payment_bank_transfer');
    $settings = $payment_method["settings"];
    if ($rta2["StatusCode"] == "-1") {
        $status = $settings["status"]["aprobada"];
        $transaction = commerce_payment_transaction_new('bank_transfer', $order->order_id);
        $transaction->instance_id = $payment_method['instance_id'];
        $transaction->amount = $rta2["Payload"]["Request"]["AMOUNT"] * 100;
        $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
        $transaction->payload = print_r($rta2["Payload"], 1);
        $transaction->remote_id = $rta2["Payload"]["Answer"]["OPERATIONID"];
        commerce_payment_transaction_save($transaction);
        commerce_order_status_update($order, $status);
        drupal_goto(commerce_checkout_order_uri($order));
    } else {
        if ($rta2["Payload"]["Answer"]["BARCODETYPE"] != "") {
            $transaction = commerce_payment_transaction_new('bank_transfer', $order->order_id);
            $transaction->instance_id = $payment_method['instance_id'];
            $transaction->amount = $rta2["Payload"]["Request"]["AMOUNT"] * 100;
            $transaction->status = COMMERCE_PAYMENT_STATUS_PENDING;
            $transaction->payload = print_r($rta2["Payload"], 1);
            $transaction->remote_id = $rta2["Payload"]["Answer"]["OPERATIONID"];
            commerce_payment_transaction_save($transaction);
            $status = $settings["status"]["offline"];
            ?>
        
            <div id="content" style="width: 75%;">
	     	<div><div class="titulos">Nro de Operaci&oacute;n:</div><em><strong><?php 
            echo $order->order_id;
            ?>
</strong></em><hr></div>
            <div><div class="titulos">Total a pagar</div>$ <?php 
            echo $rta2["Payload"]["Request"]["AMOUNT"] . ".-";
            ?>
<hr></div>
        	<div class="titulos"><h3>DATOS PERSONALES<h3><hr></div>
	        <div><div class="titulos">Nombre</div> <?php 
            echo $user->name;
            ?>
 <hr></div>
<?php 
            if ($rta2["Payload"]["Answer"]["PAYMENTMETHODNAME"] == "PAGOFACIL") {
                $empresa = "PAGO FACIL";
            } else {
                $empresa = "RAPIPAGO";
            }
            $barcode = "12345678";
            if (!empty($rta2["Payload"]["Answer"]["BARCODE"])) {
                $barcode = $rta2["Payload"]["Answer"]["BARCODE"];
            }
            ?>
	       <div><div class="titulos">Podr&aacute;s pagar este cup&oacute;n en los locales de:</div><?php 
            echo $empresa;
            ?>
<hr></div>
<?php 
            echo "<img   src='" . $base_path . drupal_get_path('module', 'commerce_todo_pago') . "/includes/image.php?filetype=PNG&dpi=72&scale=5&rotation=0&font_family=Arial.ttf&font_size=8&text=" . $barcode . "&thickness=30&checksum=&code=BCGi25&' />";
            ?>
            <br /> 
            	<div class="right">
            		<input type="button" name="imprimir" value="Imprimir" onclick="window.print();" class="button">
            		<a href="<?php 
            echo commerce_checkout_order_uri($order);
            ?>
">Click aca para continuar.</a>
            	</div>
            	<br />
            </div>
<?php 
            commerce_order_status_update($order, $status);
        } else {
            _tranUpdate($order->order_id, array("first_step" => null, "second_step" => null));
            if ($rta2["StatusCode"] == 404) {
                drupal_goto('<front>');
                return;
            }
            $status = $settings["status"]["rechazada"];
            commerce_order_status_update($order, $status);
            drupal_set_message(t('Hubo un error en la transaccion, intente nuevamente'), 'error');
            commerce_payment_redirect_pane_previous_page($order);
            drupal_goto(commerce_checkout_order_uri($order));
        }
    }
}
<?php

define('DRUPAL_ROOT', dirname(__FILE__) . '/../../../../');
chdir(DRUPAL_ROOT);
require './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
if (isset($_POST['SIGN'])) {
    $sign = strtoupper(md5(md5($_POST['SHOP_ID']) . '&' . md5($_POST["ORDER_ID"]) . '&' . md5($_POST['STATE'])));
    if ($_POST['SIGN'] == $sign) {
        switch ($_POST['STATE']) {
            case 'paid':
                $order = commerce_order_load($_POST["ORDER_ID"]);
                $order_wrapper = entity_metadata_wrapper('commerce_order', $order);
                $transaction = commerce_payment_transaction_new('ubrir', $order->order_id);
                $transaction->instance_id = $order->data['payment_method'];
                $transaction->amount = $order_wrapper->commerce_order_total->amount->value();
                $transaction->currency_code = $order_wrapper->commerce_order_total->currency_code->value();
                $transaction->status = COMMERCE_PAYMENT_STATUS_SUCCESS;
                $transaction->message = t('Оплата успешно совершена.');
                commerce_payment_transaction_save($transaction);
                break;
        }
    }
}