Skip to content

Commit

Permalink
Merge pull request #86 from gmatsuoka/master
Browse files Browse the repository at this point in the history
fix decimal - mco
  • Loading branch information
gmatsuoka authored Mar 8, 2017
2 parents 8934719 + 6338380 commit d9b63c3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,21 @@
require_once "mercadopago.php";

class ControllerExtensionPaymentMPTransparente extends Controller {
private $version = "1.0";
private $version = "1.0.1";
private $versionModule = "2.3";
private $error;
private $order_info;
private $message;
private $special_checkouts = array('MLM', 'MLB', "MPE");
private $sponsors = array('MLB' => 204931135,
private $sponsors = array(
'MLB' => 204931135,
'MLM' => 204962951,
'MLA' => 204931029,
'MCO' => 204964815,
'MLV' => 204964612,
'MPE' => 217176790,
'MLC' => 204927454);
'MLC' => 204927454
);


public function index() {
Expand All @@ -24,6 +26,7 @@ public function index() {
$data['button_back'] = $this->language->get('button_back');
$data['terms'] = '';
$data['public_key'] = $this->config->get('mp_transparente_public_key');
$data['site_id'] = $this->config->get('mp_transparente_country');

$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
Expand Down Expand Up @@ -150,7 +153,7 @@ public function validCoupon($coupon_id) {
}

public function payment() {

$params_mercadopago = $_REQUEST['mercadopago_custom'];
$this->load->model('checkout/order');
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
Expand All @@ -161,8 +164,13 @@ public function payment() {
$params_mercadopago['paymentMethodId'] = $params_mercadopago['paymentMethodSelector'];
}

$total_price = round($order_info['total'] * $order_info['currency_value'], 2);
if($this->config->get('mp_transparente_country') == 'MCO'){
$total_price = $this->currency->format($order_info['total'], $order_info['currency_code'], false, false);
}

$payment = array();
$payment['transaction_amount'] = round($params_mercadopago['amount'], 2);
$payment['transaction_amount'] = $total_price;
$payment['token'] = $params_mercadopago['token'];
$payment['installments'] = (int) $params_mercadopago['installments'];
$payment['payment_method_id'] = $params_mercadopago['paymentMethodId'];
Expand Down Expand Up @@ -316,7 +324,7 @@ public function getCustomerId() {

if ($response_has_results_key && $response_has_at_least_one_item) {
$customer_id = $response["response"]["results"][0]["id"];

} else {

$new_customer = $this->createCustomer();
Expand Down Expand Up @@ -360,7 +368,7 @@ private function createCard($payment) {
$issuerId = isset($payment['issuer_id']) ? intval($payment['issuer_id']) : "";
$paymentMethodId = isset($payment['payment_method_id']) ? $payment['payment_method_id'] : "";

$card = $mp-> post("/v1/customers/" . $id . "/cards",
$card = $mp-> post("/v1/customers/" . $id . "/cards",
array(
"token" => $payment['metadata']['token'],
"issuer_id" => $issuerId,
Expand Down Expand Up @@ -447,5 +455,5 @@ function setPreModuleAnalytics() {
//error_log("===setPreModuleAnalytics====" . json_encode($return));

return $return;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ class ControllerExtensionPaymentMPStandard extends Controller {
public $sucess = true;
private $order_info;
private $message;
private $version = "1.0";
private $versionModule = "2.3";
private $version = "1.0.1";
private $versionModule = "2.3";
private $sponsors = array('MLB' => 204931135,
'MLM' => 204962951,
'MLA' => 204931029,
Expand Down Expand Up @@ -55,13 +55,18 @@ public function index() {
$items = array();

foreach ($all_products as $product) {
$product_price = round($product['price'] * $order_info['currency_value'], 2);
if($this->config->get('mp_standard_country') == 'MCO'){
$product_price = $this->currency->format($product['price'], $order_info['currency_code'], false, false);
}

$products .= $product['quantity'] . ' x ' . $product['name'] . ', ';
$items[] = array(
"id" => $product['product_id'],
"title" => $product['name'],
"description" => $product['quantity'] . ' x ' . $product['name'], // string
"quantity" => intval($product['quantity']),
"unit_price" => $this->currency->format($product['price'], $order_info['currency_code'], false, false), //decimal
"unit_price" => $product_price,
//"unit_price" => round(floatval($product['price']) * $order_info['currency_code'], 2), //decimal
"currency_id" => $currency,
"picture_url" => HTTP_SERVER . 'image/' . $product['image'],
Expand All @@ -71,9 +76,6 @@ public function index() {

$total = $this->currency->format($order_info['total'] - $this->cart->getSubTotal(), $order_info['currency_code'], false, false);

error_log("====total====".$total);
error_log("====text_total====".$this->language->get('text_total'));

if ($total > 0) {
$items[] = array(
"id" => 99,
Expand Down
26 changes: 14 additions & 12 deletions v2.3/ticket/catalog/controller/extension/payment/mp_ticket.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

class ControllerExtensionPaymentMPTicket extends Controller {

private $version = "1.0";
private $versionModule = "2.3";
private $version = "1.0.1";
private $versionModule = "2.3";
private $error;
public $sucess = true;
private $order_info;
Expand All @@ -23,8 +23,8 @@ public function index() {
$data['payment_button'] = $this->language->get('payment_button');

error_log("====tradução payment=====".$this->language->get('payment_button'));
$data['analytics'] = $this->setPreModuleAnalytics();

$data['analytics'] = $this->setPreModuleAnalytics();
$data['payment_button'] = $this->language->get('payment_button');

if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/extension/payment/mp_ticket.tpl')) {
Expand All @@ -42,6 +42,8 @@ public function payment() {
$order_info = $this->model_checkout_order->getOrder($this->session->data['order_id']);
$all_products = $this->cart->getProducts();
$items = array();
$site_id = $this->getCountry();

foreach ($all_products as $product) {
$items[] = array(
"id" => $product['product_id'],
Expand All @@ -68,14 +70,17 @@ public function payment() {
"apartment" => "-",
"street_number" => "-"));

$value = floatval(number_format(floatval($order_info['total']) * floatval($order_info['currency_value']), 2));
$access_token = $this->config->get('mp_ticket_access_token');
$mp = new MP($access_token);

$total_price = round($order_info['total'] * $order_info['currency_value'], 2);
if($site_id == 'MCO'){
$total_price = $this->currency->format($order_info['total'], $order_info['currency_code'], false, false);
}

$payment_data = array("payer" => $payer,
"external_reference" => $order_info['order_id'],
"transaction_amount" => $value,
"transaction_amount" => $total_price,
//"token" => $this->request->post['token'],
"description" => 'Products',
"payment_method_id" => $this->request->get['payment_method_id']);
Expand All @@ -88,13 +93,10 @@ public function payment() {
$payment_data['additional_info'] = array('shipments' => $shipments, 'items' => $items);
$is_test_user = strpos($order_info['email'], '@testuser.com');
if (!$is_test_user) {
$payment_data["sponsor_id"] = $this->sponsors[$this->getCountry()];
$payment_data["sponsor_id"] = $this->sponsors[$site_id];
}

$payment_response = $mp->create_payment($payment_data);
error_log('payment response: ' . json_encode($payment_response));

error_log("=======payment_response========" . json_encode($payment_response));

$this->model_checkout_order->addOrderHistory($order_info['order_id'], $this->config->get('mp_ticket_order_status_id'), null, false);
echo json_encode(
Expand Down Expand Up @@ -262,5 +264,5 @@ function setPreModuleAnalytics() {
error_log("===setPreModuleAnalytics====" . json_encode($return));

return $return;
}
}
}
}

0 comments on commit d9b63c3

Please sign in to comment.