diff --git a/Model/Payment/Api/Client.php b/Model/Payment/Api/Client.php index c64e7e1..e1f2c8b 100644 --- a/Model/Payment/Api/Client.php +++ b/Model/Payment/Api/Client.php @@ -111,7 +111,7 @@ public function cancel($breadTransactionId, $amount = 0, $lineItems = []) $payment = $this->order->getPayment(); $paymentApiVersion = $payment->getData('bread_api_version'); $this->logger->info('Payment API version: '. $paymentApiVersion); - if(!is_null($paymentApiVersion) && in_array($paymentApiVersion, ['classic','bread_2'])) { + if(!is_null($paymentApiVersion) && in_array($paymentApiVersion, ['bread_2'])) { $apiVersion = strtolower($paymentApiVersion); } @@ -167,7 +167,7 @@ public function authorize($breadTransactionId, $amount, $merchantOrderId = null) $payment = $this->order->getPayment(); $paymentApiVersion = $payment->getData('bread_api_version'); - if(!is_null($paymentApiVersion) && in_array($paymentApiVersion, ['classic','bread_2'])) { + if(!is_null($paymentApiVersion) && in_array($paymentApiVersion, ['bread_2'])) { $apiVersion = strtolower($paymentApiVersion); } @@ -308,7 +308,7 @@ public function settle($breadTransactionId, $amount = null, $currency = null) $payment = $this->order->getPayment(); $paymentApiVersion = $payment->getData('bread_api_version'); - if(!is_null($paymentApiVersion) && in_array($paymentApiVersion, ['classic','bread_2'])) { + if(!is_null($paymentApiVersion) && in_array($paymentApiVersion, ['bread_2'])) { $apiVersion = strtolower($paymentApiVersion); } @@ -364,7 +364,7 @@ public function refund($breadTransactionId, $amount = 0, $lineItems = [], $curre $payment = $this->order->getPayment(); $paymentApiVersion = $payment->getData('bread_api_version'); - if(!is_null($paymentApiVersion) && in_array($paymentApiVersion, ['classic','bread_2'])) { + if(!is_null($paymentApiVersion) && in_array($paymentApiVersion, ['bread_2'])) { $apiVersion = strtolower($paymentApiVersion); } @@ -487,7 +487,7 @@ protected function call($url, $data, $method = \Laminas\Http\Request::METHOD_POS if(!is_null($this->order)) { $payment = $this->order->getPayment(); $paymentApiVersion = $payment->getData('bread_api_version'); - if (!is_null($paymentApiVersion) && in_array($paymentApiVersion, ['classic', 'bread_2'])) { + if (!is_null($paymentApiVersion) && in_array($paymentApiVersion, ['bread_2'])) { $apiVersion = strtolower($paymentApiVersion); } } @@ -557,92 +557,7 @@ protected function call($url, $data, $method = \Laminas\Http\Request::METHOD_POS ]); throw $e; } - } else { - // @codingStandardsIgnoreStart - try { - $curl = curl_init($url); - curl_setopt($curl, CURLOPT_HEADER, 0); - curl_setopt($curl, CURLOPT_USERPWD, $username . ':' . $password); - curl_setopt($curl, CURLOPT_TIMEOUT, 30); - - if ($method == \Laminas\Http\Request::METHOD_POST) { - curl_setopt($curl, CURLOPT_POST, 1); - curl_setopt($curl, CURLOPT_HTTPHEADER, [ - 'Content-Type: application/json', - 'Content-Length: ' . strlen($this->jsonHelper->jsonEncode($data))]); - curl_setopt($curl, CURLOPT_POSTFIELDS, $this->jsonHelper->jsonEncode($data)); - } - - if ($method == \Laminas\Http\Request::METHOD_PUT) { - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'PUT'); - curl_setopt($curl, CURLOPT_POSTFIELDS, $this->jsonHelper->jsonEncode($data)); - } - - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - $result = curl_exec($curl); - $status = curl_getinfo($curl, CURLINFO_HTTP_CODE); - $this->logger->info('Sending request to Bread classic APIs'); - $this->logger->info('Response: ' . json_encode($result)); - if ($status != 200) { - $this->logger->log(curl_error($curl)); - - //TODO: rewrite this when API is updated to better handle errors, instead of searching through the description string - // Need to explicitly say !== false instead of === true or something similar because of what strpos returns - $isSplitPayDecline = strpos($result, "There's an issue with authorizing the credit card portion") !== false; - - if ($isSplitPayDecline) { - $this->logger->info('Is Split pay decline'); - if ($this->helper->isSplitPayAutoDecline()) { - $this->logger->info('Split pay auto-decline enabled. Transaction will be cancelled'); - $this->cancel($this->getBreadTransactionId()); - } - - $errorMessage = 'The credit/debit card portion of your transaction was declined. ' - . 'Please use a different card or contact your bank. Otherwise, you can still check out with ' - . 'an amount covered by your Bread loan capacity.'; - } else { - $errorMessage = 'Call to Bread API failed.'; - } - - throw new \Magento\Framework\Exception\LocalizedException( - __($errorMessage) - ); - } - } catch (\Throwable $e) { - $this->logger->log([ - 'USER' => $username, - 'PASSWORD' => $password, - 'URL' => $url, - 'STATUS' => $status, - 'DATA' => $data, - 'RESULT' => $result - ]); - - curl_close($curl); - throw $e; - } - - curl_close($curl); - // @codingStandardsIgnoreEnd - - $this->logger->log( - [ - 'USER' => $username, - 'PASSWORD' => $password, - 'URL' => $url, - 'DATA' => $data, - 'RESULT' => $result - ] - ); - - if (!$this->isJson($result)) { - throw new \Magento\Framework\Exception\LocalizedException( - __('API Response Is Not Valid JSON. Result: ' . $result) - ); - } - - return $this->jsonHelper->jsonDecode($result); - } + } } /** @@ -1008,4 +923,4 @@ protected function getUpdateTransactionUrlPlatform($transactionId, $action) { $url = join('/', [trim($baseUrl, '/'), 'transaction', $transactionId, $action]); return $url; } -} \ No newline at end of file +} diff --git a/Model/System/Config/Source/ApiVersion.php b/Model/System/Config/Source/ApiVersion.php index 36cb4cb..37ac30d 100644 --- a/Model/System/Config/Source/ApiVersion.php +++ b/Model/System/Config/Source/ApiVersion.php @@ -19,7 +19,6 @@ class ApiVersion implements \Magento\Framework\Option\ArrayInterface { */ public function toOptionArray() { return [ - ['value' => 'classic', 'label' => __('Bread Classic')], ['value' => 'bread_2', 'label' => __('Bread Platform')] ]; } @@ -31,9 +30,8 @@ public function toOptionArray() { */ public function toArray() { return [ - 'classic' => __('Bread Classic'), 'bread_2' => __('Bread Platform') ]; } -} \ No newline at end of file +} diff --git a/Setup/Patch/Data/CopyApiCredentials.php b/Setup/Patch/Data/CopyApiCredentials.php deleted file mode 100644 index 44d1dfb..0000000 --- a/Setup/Patch/Data/CopyApiCredentials.php +++ /dev/null @@ -1,98 +0,0 @@ - 'api_public_key', - 'classic_api_secret_key' => 'api_secret_key', - 'classic_api_sandbox_public_key' => 'api_sandbox_public_key', - 'classic_api_sandbox_secret_key' => 'api_sandbox_secret_key', - - ]; - - /** - * @var ConfigInterface - */ - private $config; - - /** - * @var ModuleDataSetupInterface - */ - private $moduleDataSetup; - - /** - * @var TypeListInterface - */ - private $cacheTypeList; - - /** - * @param ConfigInterface $config - * @param ModuleDataSetupInterface $moduleDataSetup - * @param TypeListInterface $cacheTypeList - */ - public function __construct( - ConfigInterface $config, - ModuleDataSetupInterface $moduleDataSetup, - TypeListInterface $cacheTypeList - ) { - $this->config = $config; - $this->moduleDataSetup = $moduleDataSetup; - $this->cacheTypeList = $cacheTypeList; - } - - - public function apply() - { - $this->moduleDataSetup->startSetup(); - - foreach (self::PATH_TRANSLATION_MAP as $classic => $platform) { - $row = $this->moduleDataSetup->getTableRow( - 'core_config_data', - 'path', - 'payment/breadcheckout/' . $classic - ); - if ($row && !empty($row['value'])) { - $this->config->saveConfig( - 'payment/breadcheckout/' . $platform, $row['value'], - ScopeConfigInterface::SCOPE_TYPE_DEFAULT, - 0 - ); - } - } - - //Clear config cache - $this->cacheTypeList->cleanType(Config::TYPE_IDENTIFIER); - - $this->moduleDataSetup->endSetup(); - } - - /** - * {@inheritdoc} - */ - public static function getDependencies() - { - return []; - } - - /** - * {@inheritdoc} - */ - public function getAliases() - { - return []; - } - - public static function getVersion() - { - return '2.3.0'; - } -} diff --git a/etc/csp_whitelist.xml b/etc/csp_whitelist.xml index aeeab28..30cec3e 100644 --- a/etc/csp_whitelist.xml +++ b/etc/csp_whitelist.xml @@ -3,31 +3,27 @@ - *.getbread.com *.breadpayments.com *.rbcpayplan.com - *.getbread.com *.breadpayments.com *.rbcpayplan.com - *.getbread.com *.breadpayments.com *.rbcpayplan.com - *.getbread.com *.breadpayments.com *.rbcpayplan.com - \ No newline at end of file +