Skip to content

Commit

Permalink
PT-6784 - fix wrong payment status for canceled payments
Browse files Browse the repository at this point in the history
  • Loading branch information
mitelg committed Sep 30, 2016
1 parent 6c72d45 commit ffc8322
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 14 deletions.
12 changes: 6 additions & 6 deletions Components/RestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ public function __construct(PayPalConfig $config, $certPath = true)
}

$this->restClient = new Client(
[
array(
'base_url' => $base_url,
'defaults' => [
'headers' => [
'defaults' => array(
'headers' => array(
'PayPal-Partner-Attribution-Id' => 'ShopwareAG_Cart_PayPalPlus_1017'
],
),
'verify' => $certPath
]
]
)
)
);

$this->setAuth($restUser, $restPw);
Expand Down
23 changes: 15 additions & 8 deletions Subscriber/PaymentPaypal.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Shopware\SwagPaymentPaypalPlus\Subscriber;

use Enlight_Components_Session_Namespace as Session;
use Exception;
use Shopware\Components\Logger;
use Shopware\SwagPaymentPaypalPlus\Components\PaymentInstructionProvider;
use Shopware\SwagPaymentPaypalPlus\Components\RestClient;
Expand Down Expand Up @@ -89,7 +90,7 @@ public function onPreDispatchPaymentPaypal(\Enlight_Controller_ActionEventArgs $
$payment = array();
try {
$payment = $this->restClient->get($uri, array('payer_id' => $payerId));
} catch (\Exception $e) {
} catch (Exception $e) {
$this->logger->error('An error occurred on getting the payment on returning from PayPal: ' . $e->getMessage());
}

Expand All @@ -115,13 +116,11 @@ public function onPreDispatchPaymentPaypal(\Enlight_Controller_ActionEventArgs $
}

$paypalConfig = $this->paypalBootstrap->Config();
$statusId = $paypalConfig->get('paypalStatusId', 12);
$transactionId = $payment['id'];
$orderNumber = null;

if ($payment['state'] == 'created') {
if ($paypalConfig->get('paypalSendInvoiceId')) {
$orderNumber = $controller->saveOrder($transactionId, sha1($payment['id']), $statusId);
$orderNumber = $controller->saveOrder($payment['id'], sha1($payment['id']));
$params = array(
array(
'op' => 'add',
Expand All @@ -141,11 +140,19 @@ public function onPreDispatchPaymentPaypal(\Enlight_Controller_ActionEventArgs $

$uri = 'payments/payment/' . $paymentId;

$this->restClient->patch($uri, $params);
try {
$this->restClient->patch($uri, $params);
} catch (Exception $e) {
$this->logger->error('An error occurred on patching the order number to the payment: ' . $e->getMessage());
}
}

$uri = "payments/payment/$paymentId/execute";
$payment = $this->restClient->create($uri, array('payer_id' => $payerId));
try {
$payment = $this->restClient->create($uri, array('payer_id' => $payerId));
} catch (Exception $e) {
$this->logger->error('An error occurred on executing the payment: ' . $e->getMessage());
}
}

if ($payment['state'] == 'approved') {
Expand All @@ -156,7 +163,7 @@ public function onPreDispatchPaymentPaypal(\Enlight_Controller_ActionEventArgs $
}

if (!$orderNumber) {
$orderNumber = $controller->saveOrder($transactionId, sha1($payment['id']), $statusId);
$orderNumber = $controller->saveOrder($transactionId, sha1($payment['id']));
} else {
$sql = 'UPDATE s_order
SET transactionID = ?
Expand All @@ -181,7 +188,7 @@ public function onPreDispatchPaymentPaypal(\Enlight_Controller_ActionEventArgs $
ON DUPLICATE KEY UPDATE swag_payal_express = 2
';
$controller->get('db')->query($sql, array($orderNumber));
} catch (\Exception $e) {
} catch (Exception $e) {
}

$controller->redirect(
Expand Down

0 comments on commit ffc8322

Please sign in to comment.