예제 #1
0
 /**
  * Assign corresponding data
  *
  * @param \Magento\Framework\DataObject|mixed $data
  *
  * @return $this
  * @throws LocalizedException
  */
 public function assignData(\Magento\Framework\DataObject $data)
 {
     // route /checkout/onepage/savePayment
     if (!$data instanceof \Magento\Framework\DataObject) {
         $data = new \Magento\Framework\DataObject($data);
     }
     $info_form = $data->getData('additional_data');
     //$info_form = $info_form['mercadopago_custom'];
     if (isset($info_form['one_click_pay']) && $info_form['one_click_pay'] == 1) {
         $info_form = $this->cleanFieldsOcp($info_form);
     }
     if (empty($info_form['token'])) {
         $e = "";
         $exception = new \MercadoPago\Core\Model\Api\V1\Exception(new \Magento\Framework\Phrase($e), $this->_scopeConfig);
         $e = $exception->getUserMessage();
         $exception->setPhrase(new \Magento\Framework\Phrase($e));
         throw $exception;
     }
     $this->_helperData->log("info form", self::LOG_NAME, $info_form);
     $info = $this->getInfoInstance();
     $info->setAdditionalInformation($info_form);
     $info->setAdditionalInformation('payment_type_id', "credit_card");
     if (!empty($info_form['card_expiration_month']) && !empty($info_form['card_expiration_year'])) {
         $info->setAdditionalInformation('expiration_date', $info_form['card_expiration_month'] . "/" . $info_form['card_expiration_year']);
     }
     $info->setAdditionalInformation('payment_method', $info_form['payment_method_id']);
     $info->setAdditionalInformation('cardholderName', $info_form['card_holder_name']);
     return $this;
 }
예제 #2
0
 /**
  * Return response of api to a preference
  *
  * @param $preference
  *
  * @return array
  * @throws \MercadoPago\Core\Model\Api\V1\Exception
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function postPaymentV1($preference)
 {
     //get access_token
     if (!$this->_accessToken) {
         $this->_accessToken = $this->_scopeConfig->getValue(self::XML_PATH_ACCESS_TOKEN);
     }
     $this->_coreHelper->log("Access Token for Post", 'mercadopago-custom.log', $this->_accessToken);
     //set sdk php mercadopago
     $mp = $this->_coreHelper->getApiInstance($this->_accessToken);
     $response = $mp->post("/v1/payments", $preference);
     $this->_coreHelper->log("POST /v1/payments", 'mercadopago-custom.log', $response);
     if ($response['status'] == 200 || $response['status'] == 201) {
         return $response;
     } else {
         $e = "";
         $exception = new \MercadoPago\Core\Model\Api\V1\Exception(new \Magento\Framework\Phrase($e), $this->_scopeConfig);
         if (count($response['response']['cause']) > 0) {
             foreach ($response['response']['cause'] as $error) {
                 $e .= $exception->getUserMessage($error) . " ";
             }
         } else {
             $e = $exception->getUserMessage();
         }
         $this->_coreHelper->log("erro post pago: " . $e, 'mercadopago-custom.log');
         $this->_coreHelper->log("response post pago: ", 'mercadopago-custom.log', $response);
         $exception->setPhrase(new \Magento\Framework\Phrase($e));
         throw $exception;
     }
 }