Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #90 from gmatsuoka/master
Browse files Browse the repository at this point in the history
added validation to show messages in serious errors
  • Loading branch information
mmitameli authored Jun 27, 2018
2 parents 4a42d4c + 3f736cd commit 3254acd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 28 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
}
],
"type": "magento2-component",
"version": "2.1.1",
"version": "2.1.2",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
63 changes: 40 additions & 23 deletions src/MercadoPago/Core/Model/Custom/Payment.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,40 +267,57 @@ public function postRequest(DataObject $request, ConfigInterface $config)
*/
public function initialize($paymentAction, $stateObject)
{

if ($this->getInfoInstance()->getAdditionalInformation('token') == "") {
throw new \Exception(__('Verify the form data or wait until the validation of the payment data'));
}
try {

$infoInstance = $this->getInfoInstance();
$infoInstance = $this->getInfoInstance();

$response = $this->preparePostPayment();
$response = $this->preparePostPayment();

if ($response) {
$payment = $response['response'];
if (isset($response['status']) && ($response['status'] == 200 || $response['status'] == 201)) {
$payment = $response['response'];

if(isset($payment['id'])){
$infoInstance->setAdditionalInformation('payment_id_detail', $payment['id']);
}
if(isset($payment['id'])){
$infoInstance->setAdditionalInformation('payment_id_detail', $payment['id']);
}

if(isset($payment['payer']['identification']['type'])){
$infoInstance->setAdditionalInformation('payer_identification_type', $payment['payer']['identification']['type']);
}
if(isset($payment['payer']['identification']['number'])){
$infoInstance->setAdditionalInformation('payer_identification_number', $payment['payer']['identification']['number']);
}
if(isset($payment['payer']['identification']['type'])){
$infoInstance->setAdditionalInformation('payer_identification_type', $payment['payer']['identification']['type']);
}
if(isset($payment['payer']['identification']['number'])){
$infoInstance->setAdditionalInformation('payer_identification_number', $payment['payer']['identification']['number']);
}

if(isset($response['response']['status'])){
$this->getInfoInstance()->setAdditionalInformation('status', $response['response']['status']);
}
if(isset($response['response']['status'])){
$this->getInfoInstance()->setAdditionalInformation('status', $response['response']['status']);
}

if(isset($response['response']['status_detail'])){
$this->getInfoInstance()->setAdditionalInformation('status_detail', $response['response']['status_detail']);
if(isset($response['response']['status_detail'])){
$this->getInfoInstance()->setAdditionalInformation('status_detail', $response['response']['status_detail']);
}

return true;
}else{

if(isset($response['response']) && isset($response['response']['message'])){
throw new \Magento\Framework\Exception\LocalizedException(__($response['response']['message']));
}else{
throw new \Magento\Framework\Exception\LocalizedException(__('An error occurred when creating the payment.'));
}

return $this;
}

return true;
}

return false;
} catch (\Exception $e) {
$this->_helperData->log("Serious error when creating payment: " . $e->getMessage(), self::LOG_NAME);

throw new \Magento\Framework\Exception\LocalizedException(__('There was an internal error when creating the payment.'));

return $this;
}
}

/**
Expand All @@ -325,7 +342,6 @@ public function validate()
public function assignData(\Magento\Framework\DataObject $data)
{
$this->_helperData->log("assigData", self::LOG_NAME);


// route /checkout/onepage/savePayment
if (!($data instanceof \Magento\Framework\DataObject)) {
Expand Down Expand Up @@ -375,6 +391,7 @@ public function assignData(\Magento\Framework\DataObject $data)
*/
public function preparePostPayment($usingSecondCardInfo = null)
{

$this->_helperData->log("Credit Card -> init prepare post payment", self::LOG_NAME);

$quote = $this->_getQuote();
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mercadopago/module-core",
"description": "Mercado Pago payment method module",
"type": "magento2-module",
"version": "2.1.1",
"version": "2.1.2",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/Core/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MercadoPago_Core" setup_version="2.1.1">
<module name="MercadoPago_Core" setup_version="2.1.2">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/MercadoEnvios/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"php": "~5.5.0|~5.6.0|~7.0.0"
},
"type": "magento2-module",
"version": "2.1.1",
"version": "2.1.2",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
2 changes: 1 addition & 1 deletion src/MercadoPago/MercadoEnvios/etc/module.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="MercadoPago_MercadoEnvios" setup_version="2.1.1">
<module name="MercadoPago_MercadoEnvios" setup_version="2.1.2">
<sequence>
<module name="Magento_Sales"/>
<module name="Magento_Payment"/>
Expand Down

0 comments on commit 3254acd

Please sign in to comment.