示例#1
0
 public function processPayment($event)
 {
     if (!class_exists('Conekta')) {
         error_log("Plugin miss Conekta PHP lib dependency. Clone the repository using 'git clone --recursive git@github.com:conekta/conekta-magento.git'", 0);
         throw new Mage_Payment_Model_Info_Exception("Payment module unavailable. Please contact system administrator.");
     }
     if ($event->payment->getMethod() == Mage::getModel('Conekta_Realtime_Model_Realtime')->getCode()) {
         Conekta::setApiKey(Mage::getStoreConfig('payment/realtime/privatekey'));
         Conekta::setApiVersion("1.0.0");
         Conekta::setLocale(Mage::app()->getLocale()->getLocaleCode());
         $billing = $event->payment->getOrder()->getBillingAddress()->getData();
         $email = $event->payment->getOrder()->getCustomerEmail();
         if ($event->payment->getOrder()->getShippingAddress()) {
             $shipping = $event->payment->getOrder()->getShippingAddress()->getData();
         }
         $items = $event->payment->getOrder()->getAllVisibleItems();
         $line_items = array();
         $i = 0;
         foreach ($items as $itemId => $item) {
             $name = $item->getName();
             $sku = $item->getSku();
             $price = $item->getPrice();
             $description = $item->getDescription();
             $product_type = $item->getProductType();
             $line_items = array_merge($line_items, array(array('name' => $name, 'sku' => $sku, 'unit_price' => $price, 'description' => $description, 'quantity' => 1, 'type' => $product_type)));
             $i = $i + 1;
         }
         $shipp = array();
         if (empty($shipping) != true) {
             $shipp = array('address' => array('street1' => $shipping['street'], 'city' => $shipping['city'], 'state' => $shipping['region'], 'country' => $shipping['country_id'], 'zip' => $shipping['postcode'], 'phone' => $shipping['telephone'], 'email' => $email));
         }
         $days = $event->payment->getMethodInstance()->getConfigData('my_date');
         $expiry_date = Date('Y-m-d', strtotime("+" . $days . " days"));
         try {
             $charge = Conekta_Charge::create(array('cash' => array('type' => 'real_time', 'expires_at' => $expiry_date), 'currency' => Mage::app()->getStore()->getCurrentCurrencyCode(), 'amount' => intval((double) $event->payment->getOrder()->grandTotal * 100), 'description' => 'Compra en Magento', 'reference_id' => $event->payment->getOrder()->getIncrementId(), 'details' => array('name' => preg_replace('!\\s+!', ' ', $billing['firstname'] . ' ' . $billing['middlename'] . ' ' . $billing['firstname']), 'email' => $email, 'phone' => $billing['telephone'], 'billing_address' => array('company_name' => $billing['company'], 'street1' => $billing['street'], 'city' => $billing['city'], 'state' => $billing['region'], 'country' => $billing['country_id'], 'zip' => $billing['postcode'], 'phone' => $billing['telephone'], 'email' => $email), 'line_items' => $line_items, 'shipment' => $shipp)));
         } catch (Conekta_Error $e) {
             throw new Mage_Payment_Model_Info_Exception($e->message_to_purchaser);
         }
         $event->payment->setRealtimeExpiryDate($expiry_date);
         $event->payment->setRealtimeBarcodeUrl($charge->payment_method->barcode_url);
         $event->payment->setRealtimeBarcode($charge->payment_method->barcode);
         $event->payment->setRealtimeStoreName($charge->payment_method->store_name);
         $event->payment->setChargeId($charge->id);
         //Update Quote
         $order = $event->payment->getOrder();
         $quote = $order->getQuote();
         $payment = $quote->getPayment();
         $payment->setRealtimeExpiryDate($expiry_date);
         $payment->setRealtimeBarcodeUrl($charge->payment_method->barcode_url);
         $payment->setRealtimeBarcode($charge->payment_method->barcode);
         $payment->setRealtimeStoreName($charge->payment_method->store_name);
         $payment->setChargeId($charge->id);
         $quote->collectTotals();
         $quote->save();
         $order->setQuote($quote);
         $order->save();
     }
     return $event;
 }
示例#2
0
 public function processPayment($event)
 {
     if (!class_exists('Conekta')) {
         error_log("Plugin miss Conekta PHP lib dependency. Clone the repository using 'git clone --recursive git@github.com:conekta/conekta-magento.git'", 0);
         throw new Mage_Payment_Model_Info_Exception("Payment module unavailable. Please contact system administrator.");
     }
     if ($event->payment->getMethod() == Mage::getModel('Conekta_Spei_Model_Spei')->getCode()) {
         Conekta::setApiKey(Mage::getStoreConfig('payment/webhook/privatekey'));
         Conekta::setApiVersion("1.0.0");
         Conekta::setLocale(Mage::app()->getLocale()->getLocaleCode());
         $order = $event->payment->getOrder();
         $customer = $order->getCustomer();
         $shipping_address = $order->getShippingAddress();
         $billing = $order->getBillingAddress()->getData();
         $email = $order->getCustomerEmail();
         if ($shipping_address) {
             $shipping_data = $shipping_address->getData();
         }
         $items = $order->getAllVisibleItems();
         $line_items = array();
         $i = 0;
         foreach ($items as $itemId => $item) {
             $name = $item->getName();
             $sku = $item->getSku();
             $price = $item->getPrice();
             $description = $item->getDescription();
             $product_type = $item->getProductType();
             $line_items = array_merge($line_items, array(array('name' => $name, 'sku' => $sku, 'unit_price' => $price, 'description' => $description, 'quantity' => 1, 'type' => $product_type)));
             $i = $i + 1;
         }
         $shipp = array();
         if (empty($shipping_data) != true) {
             $shipp = array('price' => intval((double) $order->getShippingAmount() * 100), 'service' => $order->getShippingMethod(), 'carrier' => $order->getShippingDescription(), 'address' => array('street1' => $shipping_data['street'], 'city' => $shipping_data['city'], 'state' => $shipping_data['region'], 'country' => $shipping_data['country_id'], 'zip' => $shipping_data['postcode'], 'phone' => $shipping_data['telephone'], 'email' => $email));
         }
         $days = $event->payment->getMethodInstance()->getConfigData('my_date');
         try {
             $charge = Conekta_Charge::create(array('bank' => array('type' => 'spei'), 'currency' => Mage::app()->getStore()->getCurrentCurrencyCode(), 'amount' => intval((double) $order->grandTotal * 100), 'description' => 'Compra en Magento', 'reference_id' => $order->getIncrementId(), 'details' => array('name' => preg_replace('!\\s+!', ' ', $billing['firstname'] . ' ' . $billing['middlename'] . ' ' . $billing['firstname']), 'email' => $email, 'phone' => $billing['telephone'], 'billing_address' => array('company_name' => $billing['company'], 'street1' => $billing['street'], 'city' => $billing['city'], 'state' => $billing['region'], 'country' => $billing['country_id'], 'zip' => $billing['postcode'], 'phone' => $billing['telephone'], 'email' => $email), 'line_items' => $line_items, 'shipment' => $shipp), 'coupon_code' => $order->getCouponCode(), 'custom_fields' => array('customer' => array('website_id' => $customer->getWebsiteId(), 'entity_id' => $customer->getEntityId(), 'entity_type_id' => $customer->getEntityTypeId(), 'attribute_set_id' => $customer->getAttributeSetId(), 'email' => $customer->getEmail(), 'group_id' => $customer->getGroupId(), 'store_id' => $customer->getStoreId(), 'created_at' => $customer->getCreatedAt(), 'updated_at' => $customer->getUpdatedAt(), 'is_active' => $customer->getIsActive(), 'disable_auto_group_change' => $customer->getDisableAutoGroupChange(), 'get_tax_vat' => $customer->getTaxvat(), 'created_in' => $customer->getCreatedIn(), 'gender' => $customer->getGender(), 'default_billing' => $customer->getDefaultBilling(), 'default_shipping' => $customer->getDefaultShipping(), 'dob' => $customer->getDob(), 'tax_class_id' => $customer->getTaxClassId()), 'discount_description' => $order->getDiscountDescription(), 'discount_amount' => $order->getDiscountAmount(), 'shipping_amount' => $shipping_address->getShippingAmount(), 'shipping_description' => $shipping_address->getShippingDescription(), 'shipping_method' => $shipping_address->getShippingMethod())));
         } catch (Conekta_Error $e) {
             throw new Mage_Payment_Model_Info_Exception($e->message_to_purchaser);
         }
         $event->payment->setSpeiClabe($charge->payment_method->clabe);
         $event->payment->setSpeiBank($charge->payment_method->bank);
         $event->payment->setChargeId($charge->id);
         //Update Quote
         $order = $order;
         $quote = $order->getQuote();
         $payment = $quote->getPayment();
         $payment->setSpeiClabe($charge->payment_method->clabe);
         $payment->setSpeiBank($charge->payment_method->bank);
         $payment->setChargeId($charge->id);
         $quote->collectTotals();
         $quote->save();
         $order->setQuote($quote);
         $order->save();
     }
     return $event;
 }
示例#3
0
 protected function _getElementHtml(Varien_Data_Form_Element_Abstract $element)
 {
     if (!class_exists('Conekta')) {
         error_log("Plugin miss Conekta PHP lib dependency. Clone the repository using 'git clone --recursive git@github.com:conekta/conekta-magento.git'", 0);
         throw new Mage_Payment_Model_Info_Exception("Payment module unavailable. Please contact system administrator.");
     }
     Conekta::setApiKey(Mage::getStoreConfig('payment/webhook/privatekey'));
     Conekta::setApiVersion("1.0.0");
     Conekta::setLocale(Mage::app()->getLocale()->getLocaleCode());
     $url = new Varien_Data_Form_Element_Text();
     $data = array('name' => $element->getName(), 'html_id' => $element->getId());
     $url->setData($data);
     $webhook_url = Mage::getBaseUrl() . "index.php/webhook/ajax/listener";
     if (!empty($element->getValue())) {
         $url_string = $element->getValue();
     } else {
         $url_string = $webhook_url;
     }
     $url->setValue($url_string);
     $events = array("events" => array("charge.created", "charge.paid", "charge.under_fraud_review", "charge.fraudulent", "charge.refunded", "charge.created", "customer.created", "customer.updated", "customer.deleted", "webhook.created", "webhook.updated", "webhook.deleted", "charge.chargeback.created", "charge.chargeback.updated", "charge.chargeback.under_review", "charge.chargeback.lost", "charge.chargeback.won", "payout.created", "payout.retrying", "payout.paid_out", "payout.failed", "plan.created", "plan.updated", "plan.deleted", "subscription.created", "subscription.paused", "subscription.resumed", "subscription.canceled", "subscription.expired", "subscription.updated", "subscription.paid", "subscription.payment_failed", "payee.created", "payee.updated", "payee.deleted", "payee.payout_method.created", "payee.payout_method.updated", "payee.payout_method.deleted"));
     $error = false;
     $error_message = null;
     try {
         $different = true;
         $webhooks = Conekta_Webhook::where();
         foreach ($webhooks as $webhook) {
             if (strpos($webhook->webhook_url, $url_string) !== false) {
                 $different = false;
             }
         }
         if ($different) {
             $webhook = Conekta_Webhook::create(array_merge(array("url" => $url_string), $events));
         }
     } catch (Exception $e) {
         $error = true;
         $error_message = $e->getMessage();
     }
     $url->setForm($element->getForm());
     $html = $url->getElementHtml();
     $javaScript = "\n    <script type=\"text/javascript\">\n    Event.observe(window, 'load', function() {\n      alert('" . $error_message . "');\n    });\n    </script>";
     if ($error) {
         $html .= $javaScript;
     }
     return $html;
 }
示例#4
0
<?php

header('Content-Type: text/html; charset=utf-8');
/* Panel de control antifraude */
// Incluir la libreria de Conekta
require_once "../vendor/conekta-php/lib/Conekta.php";
// Configurar Conekta
Conekta::setApiVersion("1.0.0");
Conekta::setApiKey('key_HizotERe7EkwAj4TAQnryw');
// Pedir los cargos
try {
    $charges = Conekta_Charge::where(array('failure_code' => 'suspected_fraud'));
    $charges = json_decode($charges, true);
} catch (Conekta_Error $e) {
    // La consulta no pudo ser procesada
    echo $e->getMessage();
}
// Mostrar la razón de las transacciones fraudulentas
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <title>Transacciones de PinkRevolver</title>

    <!-- Bootstrap -->
    <link href="css/bootstrap.min.css" rel="stylesheet">
 private function _createWebhook()
 {
     require_once dirname(__FILE__) . '/lib/conekta-php/lib/Conekta.php';
     Conekta::setApiKey(Configuration::get('CONEKTA_MODE') ? Configuration::get('CONEKTA_PRIVATE_KEY_LIVE') : Configuration::get('CONEKTA_PRIVATE_KEY_TEST'));
     Conekta::setApiVersion("1.0.0");
     Conekta::setLocale('en');
     $events = array("events" => array("charge.paid"));
     // Reset error message
     Configuration::deleteByName('CONEKTA_WEBHOOK_ERROR_MESSAGE');
     // Obtain user input
     $url = Tools::safeOutput(Tools::getValue('conekta_webhook'));
     // Obtain stored value
     $config_url = Tools::safeOutput(Configuration::get('CONEKTA_WEBHOOK'));
     $is_valid_url = !empty($url) && !filter_var($url, FILTER_VALIDATE_URL) === false;
     $failed_attempts = (int) Configuration::get('CONEKTA_WEBHOOK_FAILED_ATTEMPTS');
     // If input is valid, has not been stored and has not failed more than 5 times
     if ($is_valid_url && $config_url != $url && ($failed_attempts < 5 && $url != Configuration::get('CONEKTA_WEBHOOK_FAILED_URL'))) {
         try {
             $different = true;
             $webhooks = Conekta_Webhook::where();
             $urls = array();
             foreach ($webhooks as $webhook) {
                 array_push($urls, $webhook->webhook_url);
             }
             if (!in_array($url_string, $urls)) {
                 if (Configuration::get('CONEKTA_MODE')) {
                     $mode = array("production_enabled" => 1);
                 } else {
                     $mode = array("development_enabled" => 1);
                 }
                 $webhook = Conekta_Webhook::create(array_merge(array("url" => $url), $mode, $events));
                 Configuration::updateValue('CONEKTA_WEBHOOK', $url);
                 // delete error variables
                 Configuration::deleteByName('CONEKTA_WEBHOOK_FAILED_ATTEMPTS');
                 Configuration::deleteByName('CONEKTA_WEBHOOK_FAILED_URL');
                 Configuration::deleteByName('CONEKTA_WEBHOOK_ERROR_MESSAGE');
             }
         } catch (Exception $e) {
             Configuration::updateValue('CONEKTA_WEBHOOK_ERROR_MESSAGE', $e->message_to_purchaser);
         }
     } else {
         if ($url == Configuration::get('CONEKTA_WEBHOOK_FAILED_URL')) {
             Configuration::updateValue('CONEKTA_WEBHOOK_ERROR_MESSAGE', "Webhook was already register, try changing webhook!");
             Configuration::deleteByName('CONEKTA_WEBHOOK_FAILED_ATTEMPTS');
             $failed_attempts = 0;
         } elseif ($failed_attempts >= 5) {
             Configuration::updateValue('CONEKTA_WEBHOOK_ERROR_MESSAGE', "Maximum failed attempts reached!");
         } elseif (!$is_valid_url) {
             Configuration::updateValue('CONEKTA_WEBHOOK_ERROR_MESSAGE', "Not a valid url!");
         } else {
             Configuration::updateValue('CONEKTA_WEBHOOK_ERROR_MESSAGE', "Webhook was already registered in your shop!");
         }
     }
     if (!empty(Configuration::get('CONEKTA_WEBHOOK_ERROR_MESSAGE'))) {
         $failed_attempts = $failed_attempts + 1;
         Configuration::updateValue('CONEKTA_WEBHOOK_FAILED_ATTEMPTS', $failed_attempts);
         Configuration::updateValue('CONEKTA_WEBHOOK_FAILED_URL', $url);
     }
 }