Skip to content

Commit

Permalink
Merge pull request #9 from enupal/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
andrelopez authored Jan 29, 2021
2 parents e1c328a + ae74d74 commit 4e5511d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Enupal PayPal Changelog

## 1.3.1 - 2021.01.29
### Fixed
- Fixed issue where duplicate orders during IPN

## 1.3.0 - 2020.11.12
### Added
- Added support to PHP 7.4
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "enupal/paypal",
"description": "Sell products or services on your website using a PayPal Buy Now Button",
"type": "craft-plugin",
"version": "1.3.0",
"version": "1.3.1",
"keywords": [
"craft",
"cms",
Expand Down
6 changes: 6 additions & 0 deletions src/controllers/PaypalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ public function actionIpn()
if ($ipn->verifyIPN()) {
Craft::info("IPN validated", __METHOD__);
$order = Paypal::$app->orders->populateOrder();

if ($order->id) {
Craft::info('IPN already processed with order id: '.$order->id, __METHOD__);
return $this->asJson(['success' => 'true']);
}

$button = Paypal::$app->buttons->getButtonBySku($this->getValue('item_number'));

if ($button){
Expand Down
7 changes: 6 additions & 1 deletion src/services/Orders.php
Original file line number Diff line number Diff line change
Expand Up @@ -343,11 +343,16 @@ public function getEmailsPath()
}

/**
* @return Order
* @return Order|\craft\base\ElementInterface
* @throws \Exception
*/
public function populateOrder()
{
$order = $this->getOrderByPaypalTransactionId($this->getPostValue('txn_id'));
if (!is_null($order)) {
return $order;
}

$order = new Order();
$order->orderStatusId = OrderStatus::NEW;

Expand Down

0 comments on commit 4e5511d

Please sign in to comment.