Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 7 additions & 92 deletions Model/Payment/Api/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -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);
}
}
}

/**
Expand Down Expand Up @@ -1008,4 +923,4 @@ protected function getUpdateTransactionUrlPlatform($transactionId, $action) {
$url = join('/', [trim($baseUrl, '/'), 'transaction', $transactionId, $action]);
return $url;
}
}
}
4 changes: 1 addition & 3 deletions Model/System/Config/Source/ApiVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')]
];
}
Expand All @@ -31,9 +30,8 @@ public function toOptionArray() {
*/
public function toArray() {
return [
'classic' => __('Bread Classic'),
'bread_2' => __('Bread Platform')
];
}

}
}
98 changes: 0 additions & 98 deletions Setup/Patch/Data/CopyApiCredentials.php

This file was deleted.

6 changes: 1 addition & 5 deletions etc/csp_whitelist.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,27 @@
<policies>
<policy id="script-src">
<values>
<value id="bread_classic_script" type="host">*.getbread.com</value>
<value id="bread_platform_script" type="host">*.breadpayments.com</value>
<value id="bread_platform_script_ca" type="host">*.rbcpayplan.com</value>
</values>
</policy>
<policy id="connect-src">
<values>
<value id="bread_classic_connect" type="host">*.getbread.com</value>
<value id="bread_platform_connect" type="host">*.breadpayments.com</value>
<value id="bread_platform_connect_ca" type="host">*.rbcpayplan.com</value>
</values>
</policy>
<policy id="frame-src">
<values>
<value id="bread_classic_frame" type="host">*.getbread.com</value>
<value id="bread_platform_frame" type="host">*.breadpayments.com</value>
<value id="bread_platform_frame_ca" type="host">*.rbcpayplan.com</value>
</values>
</policy>
<policy id="img-src">
<values>
<value id="bread_classic_img" type="host">*.getbread.com</value>
<value id="bread_platform_img" type="host">*.breadpayments.com</value>
<value id="bread_platform_img_ca" type="host">*.rbcpayplan.com</value>
</values>
</policy>
</policies>
</csp_whitelist>
</csp_whitelist>