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; }
protected function send_to_conekta() { global $woocommerce; include_once 'conekta_gateway_helper.php'; Conekta::setApiKey($this->secret_key); Conekta::setLocale("es"); $data = getRequestData($this->order); $line_items = array(); $items = $this->order->get_items(); $line_items = build_line_items($items); $details = build_details($data, $line_items); try { $charge = Conekta_Charge::create(array("amount" => $data['amount'], "currency" => $data['currency'], "reference_id" => $this->order->id, "description" => "Recibo de pago para orden # " . $this->order->id, "cash" => array("type" => "oxxo"), "details" => $details)); $this->transactionId = $charge->id; update_post_meta($this->order->id, 'conekta-id', $charge->id); update_post_meta($this->order->id, 'conekta-creado', $charge->created_at); update_post_meta($this->order->id, 'conekta-expira', $charge->payment_method->expiry_date); update_post_meta($this->order->id, 'conekta-barcode', $charge->payment_method->barcode); update_post_meta($this->order->id, 'conekta-barcodeurl', $charge->payment_method->barcode_url); return true; } catch (Conekta_Error $e) { $description = $e->message_to_purchaser; global $wp_version; if (version_compare($wp_version, '4.1', '>=')) { wc_add_notice(__('Error: ', 'woothemes') . $description, $notice_type = 'error'); } else { error_log('Gateway Error:' . $description . "\n"); $woocommerce->add_error(__('Error: ', 'woothemes') . $description); } return false; } }
public function payment() { Conekta::setApiKey("key_U7qsxjuAzRny1F5ogKXFyw"); Conekta::setLocale('ES'); $reg = Input::get('reg_id'); $pedido = Pedidos::find(Input::get('id')); $card = Input::get('conektaTokenId'); $monto = $pedido->total; $restaurantes = Restaurantes::find($pedido->id_restaurante)->first(); $user = $usuario = User::where('id', '=', $pedido->id_usuario)->first(); try { $charge = Conekta_Charge::create(array("description" => "Conekta tastyfoods", "amount" => $monto * 100, "currency" => "MXN", "reference_id" => "orden_de_id_interno", "card" => $card, 'details' => array('name' => $user->nombre, 'email' => $user->username, 'customer' => array('corporation_name' => 'Conekta Inc.', 'logged_in' => true), 'line_items' => array(array('name' => 'pedido de comida', 'description' => 'Conekta tastyfoods', 'unit_price' => $monto, 'quantity' => 1, 'sku' => 'cohb_s1', 'type' => 'food'))))); } catch (Conekta_Error $e) { return Response::json($e->getMessage()); } $pedido->estatus = 'pagada'; $pedido->tipo = 'tarjeta'; $pedido->save(); $restaurantes->pagadas = $restaurantes->pagadas + 1; $restaurantes->save(); date_default_timezone_set('America/Mexico_City'); $hora = date('Y-m-d H:i:s'); // $nuevamas = strtotime ( '+2 minute' , strtotime ( $notificacion ) ) ; // $nuevamas = date ( 'Y-m-d H:i:s' , $nuevamas ); // if($reg != ""){ // PushNotification::app('Tasty') // ->to($reg) // ->send('Califica el sabor de los platillos que acabas de consumir!'); // } // return Response::json($charge->status); }
<?php error_reporting(E_ALL); require_once "../conekta/lib/Conekta.php"; Conekta::setApiKey("key_eYvWV7gSDkNYXsmr"); Conekta::setLocale('es'); try { // Llamada a Conekta... $charge = Conekta_Charge::create(array('description' => 'Stogies', 'reference_id' => '9839-wolf_pack', 'amount' => 20000, 'currency' => 'MXN', 'card' => 'tok_test_insufficient_funds', 'details' => array('name' => 'Arnulfo Quimare', 'phone' => '403-342-0642', 'email' => '*****@*****.**', 'customer' => array('logged_in' => true, 'successful_purchases' => 14, 'created_at' => 1379784950, 'updated_at' => 1379784950, 'offline_payments' => 4, 'score' => 9), 'line_items' => array(array('name' => 'Box of Cohiba S1s', 'description' => 'Imported From Mex.', 'unit_price' => 20000, 'quantity' => 1, 'sku' => 'cohb_s1', 'category' => 'food')), 'billing_address' => array('street1' => '77 Mystery Lane', 'street2' => 'Suite 124', 'street3' => null, 'city' => 'Darlington', 'state' => 'NJ', 'zip' => '10192', 'country' => 'Mexico', 'tax_id' => 'xmn671212drx', 'company_name' => 'X-Men Inc.', 'phone' => '77-777-7777', 'email' => '*****@*****.**')))); } catch (Conekta_Error $e) { echo $e->getMessage(); } // $token = $charge->status; // // //if ($token == 'paid') { // ////require_once 'init.php'; header('Location: ../aprobado.html'); //}else { // //header('Location: ../rechazado.html'); //} ?>
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); } }
protected function send_to_conekta() { global $woocommerce; include_once 'conekta_gateway_helper.php'; Conekta::setApiKey($this->secret_key); Conekta::setLocale("es"); $data = getRequestData($this->order); try { $line_items = array(); $items = $this->order->get_items(); $line_items = build_line_items($items); $details = build_details($data, $line_items); $charge = Conekta_Charge::create(array("amount" => $data['amount'], "currency" => $data['currency'], "monthly_installments" => $data['monthly_installments'] > 1 ? $data['monthly_installments'] : null, "card" => $data['token'], "reference_id" => $this->order->id, "description" => "Compra con orden # " . $this->order->id . " desde Woocommerce v" . $this->version, "details" => $details)); $this->transactionId = $charge->id; if ($data['monthly_installments'] > 1) { update_post_meta($this->order->id, 'meses-sin-intereses', $data['monthly_installments']); } update_post_meta($this->order->id, 'transaction_id', $this->transactionId); return true; } catch (Conekta_Error $e) { $description = $e->message_to_purchaser; global $wp_version; if (version_compare($wp_version, '4.1', '>=')) { wc_add_notice(__('Error: ', 'woothemes') . $description, $notice_type = 'error'); } else { error_log('Gateway Error:' . $description . "\n"); $woocommerce->add_error(__('Error: ', 'woothemes') . $description); } return false; } }
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_Bank_Model_Bank')->getCode()) { Conekta::setApiKey(Mage::getStoreConfig('payment/bank/privatekey')); 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('bank' => array('type' => 'banorte', '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->setBankExpiryDate($expiry_date); $event->payment->setBankServiceName($charge->payment_method->service_name); $event->payment->setBankServiceNumber($charge->payment_method->service_number); $event->payment->setBankName($charge->payment_method->type); $event->payment->setBankReference($charge->payment_method->reference); $event->payment->setChargeId($charge->id); //Update Quote $order = $event->payment->getOrder(); $quote = $order->getQuote(); $payment = $quote->getPayment(); $payment->setBankExpiryDate($expiry_date); $payment->setBankServiceName($charge->payment_method->service_name); $payment->setBankServiceNumber($charge->payment_method->service_number); $payment->setBankName($charge->payment_method->type); $payment->setBankReference($charge->payment_method->reference); $payment->setChargeId($charge->id); $quote->collectTotals(); $quote->save(); $order->setQuote($quote); $order->save(); } return $event; }
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_Oxxo_Model_Oxxo')->getCode()) { Conekta::setApiKey(Mage::getStoreConfig('payment/oxxo/privatekey')); 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'); $expiry_date = Date('Y-m-d', strtotime("+" . $days . " days")); try { $charge = Conekta_Charge::create(array('cash' => array('type' => 'oxxo', 'expires_at' => $expiry_date), '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->setOxxoExpiryDate($expiry_date); $event->payment->setOxxoBarcodeUrl($charge->payment_method->barcode_url); $event->payment->setOxxoBarcode($charge->payment_method->barcode); $event->payment->setChargeId($charge->id); //Update Quote $order = $order; $quote = $order->getQuote(); $payment = $quote->getPayment(); $payment->setOxxoExpiryDate($expiry_date); $payment->setOxxoBarcodeUrl($charge->payment_method->barcode_url); $payment->setOxxoBarcode($charge->payment_method->barcode); $payment->setChargeId($charge->id); $quote->collectTotals(); $quote->save(); $order->setQuote($quote); $order->save(); } return $event; }
public function set_locale_options() { if (function_exists("get_locale") && get_locale() !== "") { $current_lang = explode("_", get_locale()); $this->lang = $current_lang[0]; $this->lang_messages = (require_once "lang/" . $this->lang . ".php"); Conekta::setLocale($this->lang); } return $this; }