Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
hilrob committed Dec 13, 2017
2 parents 85ca0ec + aebca46 commit b8e1b8f
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 29 deletions.
69 changes: 47 additions & 22 deletions Model/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ class Api
const PATCH_ADD = 'add';
const PATCH_REPLACE = 'replace';

const VALIDATION_ERROR = 'VALIDATION_ERROR';

/**
* @var null|ApiContext
*/
Expand Down Expand Up @@ -128,7 +130,7 @@ class Api
protected $encryptor;

/**
* @var Repository
* @var \Magento\Framework\View\Asset\Repository
*/
protected $assetRepo;

Expand Down Expand Up @@ -261,11 +263,11 @@ public function getPayment($paymentId)
}

/**
* Create payment for curretn quote
* Create payment for current quote
*
* @param WebProfile $webProfile
* @param \Magento\Quote\Model\Quote $quote
* @return boolean
* @return boolean|PayPalPayment
*/
public function createPayment($webProfile, $quote, $taxFailure = false)
{
Expand Down Expand Up @@ -300,7 +302,7 @@ public function createPayment($webProfile, $quote, $taxFailure = false)
}
$this->payPalPlusHelper->handleException($ex);
return false;
} catch (Exception $e) {
} catch (\Exception $e) {
$this->logger->critical($e);
return false;
}
Expand Down Expand Up @@ -342,11 +344,37 @@ public function patchPayment($quote)
$amountPatch->setValue($amount);
$patchRequest->addPatch($amountPatch);

$response = $payment->update(
$patchRequest,
$this->_apiContext
);
return $response;

try {
$response = $payment->update(
$patchRequest,
$this->_apiContext
);
return $response;
} catch (\PayPal\Exception\PayPalConnectionException $ex) {
$message = json_decode($ex->getData());
if (
isset($message->name)
&& isset($message->details)
&& $message->name == self::VALIDATION_ERROR
) {
$validationMessage = __('Your address is invalid. Please check following errors: ');
foreach ($message->details as $detail) {
if (isset($detail->field) && isset($detail->issue)) {
$validationMessage .=
__(
'Field: "%1" - %2. ',
[
$detail->field,
$detail->issue
]
);
}
}
throw new \Exception($validationMessage);
}
}

}
return false;
}
Expand Down Expand Up @@ -395,11 +423,10 @@ public function executePayment($paymentId, $payerId)
} catch (PayPalConnectionException $ex) {
$this->payPalPlusHelper->handleException($ex);
return false;
} catch (Exception $e) {
} catch (\Exception $e) {
$this->logger->critical($e);
return false;
}
return false;
}

/**
Expand Down Expand Up @@ -436,11 +463,10 @@ public function getWebhooks()
} catch (PayPalConnectionException $ex) {
$this->payPalPlusHelper->handleException($ex);
return false;
} catch (Exception $e) {
} catch (\Exception $e) {
$this->logger->critical($e);
return false;
}
return false;
}

/**
Expand All @@ -457,11 +483,10 @@ public function getWebhookEvent($webhookEventId)
} catch (PayPalConnectionException $ex) {
$this->payPalPlusHelper->handleException($ex);
return false;
} catch (Exception $e) {
} catch (\Exception $e) {
$this->logger->critical($e);
return false;
}
return false;
}

/**
Expand All @@ -477,7 +502,7 @@ public function getWebhooksEventTypes()
} catch (PayPalConnectionException $ex) {
$this->payPalPlusHelper->handleException($ex);
return false;
} catch (Exception $e) {
} catch (\Exception $e) {
$this->logger->critical($e);
return false;
}
Expand Down Expand Up @@ -513,7 +538,7 @@ public function createWebhook()
}
$this->payPalPlusHelper->handleException($ex);
return false;
} catch (Exception $e) {
} catch (\Exception $e) {
$this->logger->critical($e);
return false;
}
Expand All @@ -535,7 +560,7 @@ public function deleteWebhook($webhookId)
} catch (PayPalConnectionException $ex) {
$this->payPalPlusHelper->handleException($ex);
return false;
} catch (Exception $e) {
} catch (\Exception $e) {
$this->logger->critical($e);
return false;
}
Expand All @@ -553,7 +578,7 @@ public function validateWebhook($rawBody)
try {
$webhookEvent = new \PayPal\Api\WebhookEvent();
return $webhookEvent->validateAndGetReceivedEvent($rawBody, $this->_apiContext);
} catch (Exception $ex) {
} catch (\Exception $ex) {
$this->logger->critical($ex);
return false;
}
Expand Down Expand Up @@ -593,7 +618,7 @@ protected function buildShippingAddress($quote)
* Build BillingAddress from quote
*
* @param \Magento\Quote\Model\Quote $quote
* @return ShippingAddress
* @return ShippingAddress|boolean
*/
protected function buildBillingAddress($quote)
{
Expand Down Expand Up @@ -742,7 +767,7 @@ protected function buildAmount($quote)
}

$total = $quote->getBaseGrandTotal();
if((float)$quote->getShippingAddress()->getBaseShippingAmount() == 0 && (float)$quote->getShippingAddress()->getBaseShippingInclTax() >= 0) {
if ((float)$quote->getShippingAddress()->getBaseShippingAmount() == 0 && (float)$quote->getShippingAddress()->getBaseShippingInclTax() >= 0) {
$total = (float)$total - (float)$quote->getShippingAddress()->getBaseShippingInclTax();
}

Expand Down Expand Up @@ -834,7 +859,7 @@ protected function getHeaderImage()
/**
* Reset web profile id
*
* @return type
* @return boolean
*/
public function resetWebProfileId()
{
Expand Down
14 changes: 12 additions & 2 deletions Model/MethodList.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,11 @@ public function __construct(
*/
public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote = null, $checkPPP = true)
{

$pppEnabled = $this->scopeConfig->getValue(
'payment/iways_paypalplus_payment/active',
\Magento\Store\Model\ScopeInterface::SCOPE_STORE);

if ($checkPPP) {
$allowedPPPMethods = explode(
',',
Expand All @@ -67,11 +72,16 @@ public function getAvailableMethods(\Magento\Quote\Api\Data\CartInterface $quote
foreach ($this->paymentHelper->getStoreMethods($store, $quote) as $method) {
if ($this->_canUseMethod($method, $quote)) {
$method->setInfoInstance($quote->getPayment());

if ($pppEnabled && strpos($method->getCode(), 'paypal_') === 0) {
continue;
}

if ($checkPPP) {
if (
$method->getCode() == Payment::CODE
($method->getCode() == Payment::CODE
|| $method->getCode() == self::AMAZON_PAYMENT
|| !in_array($method->getCode(), $allowedPPPMethods)
|| !in_array($method->getCode(), $allowedPPPMethods))
) {
$methods[] = $method;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Iways\PayPalPlus\Model\PaymentInformationManagement;

use Iways\PayPalPlus\Model\PaymentInformationManagement;
use Magento\Framework\Exception\CouldNotSaveException;
use Magento\Quote\Api\CartRepositoryInterface;

class GuestPPPPaymentInformationManagement extends PaymentInformationManagement implements \Iways\PayPalPlus\Api\GuestPPPPaymentInformationManagementInterface
Expand Down Expand Up @@ -100,7 +101,15 @@ public function savePaymentInformation(
}
$paymentMethod = $this->handleComment($paymentMethod);
$this->paymentMethodManagement->set($cartId, $paymentMethod);
$this->patchPayment($quoteIdMask->getQuoteId());

try {
$this->patchPayment($quoteIdMask->getQuoteId());
} catch (\Exception $e) {
throw new CouldNotSaveException(
__($e->getMessage()),
$e
);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
namespace Iways\PayPalPlus\Model\PaymentInformationManagement;

use Iways\PayPalPlus\Model\PaymentInformationManagement;
use Magento\Framework\Exception\CouldNotSaveException;

class PPPPaymentInformationManagement extends PaymentInformationManagement implements \Iways\PayPalPlus\Api\PPPPaymentInformationManagementInterface
{
Expand Down Expand Up @@ -88,7 +89,15 @@ public function savePaymentInformation(
}
$paymentMethod = $this->handleComment($paymentMethod);
$this->paymentMethodManagement->set($cartId, $paymentMethod);
$this->patchPayment($cartId);

try {
$this->patchPayment($cartId);
} catch (\Exception $e) {
throw new CouldNotSaveException(
__($e->getMessage()),
$e
);
}
return true;
}

Expand Down
3 changes: 3 additions & 0 deletions RELEASE_NOTES.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
==== 1.1.5 ====
US address validation error handling.

==== 1.1.4 ====
Changed locale_code parsing
Added workaround for broken shipping cost calculation in checkout
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
}
],
"type": "magento2-module",
"version": "1.1.4",
"version": "1.1.5",
"license": [
"OSL-3.0"
],
Expand Down
2 changes: 1 addition & 1 deletion marketplace.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
}
],
"type": "magento2-module",
"version": "1.1.4",
"version": "1.1.5",
"license": [
"OSL-3.0"
],
Expand Down
2 changes: 1 addition & 1 deletion view/frontend/web/js/action/patch-ppp-payment.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ define(
}
).fail(
function (response) {
errorProcessor.process(response, messageContainer);
errorProcessor.process(response);
}
).always(
function () {
Expand Down

0 comments on commit b8e1b8f

Please sign in to comment.