-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added mocking to order creation (#73)
* Added mocking to order creation
- Loading branch information
1 parent
1a64d2c
commit 7f11bae
Showing
3 changed files
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace Rvvup\Payments\Plugin\Customer; | ||
|
||
use Magento\Checkout\Api\PaymentInformationManagementInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\Quote\Api\Data\AddressInterface; | ||
use Magento\Quote\Api\Data\PaymentInterface; | ||
use Rvvup\Payments\Gateway\Method; | ||
|
||
class DisableOrderCreation | ||
{ | ||
/** @var CartRepositoryInterface */ | ||
private $cartRepository; | ||
|
||
/** | ||
* @param CartRepositoryInterface $cartRepository | ||
*/ | ||
public function __construct( | ||
CartRepositoryInterface $cartRepository | ||
) { | ||
$this->cartRepository = $cartRepository; | ||
} | ||
|
||
/** | ||
* @param PaymentInformationManagementInterface $subject | ||
* @param callable $proceed | ||
* @param int $cartId | ||
* @param PaymentInterface $paymentMethod | ||
* @param AddressInterface|null $billingAddress | ||
* @return int | ||
* @throws NoSuchEntityException | ||
*/ | ||
public function aroundSavePaymentInformationAndPlaceOrder( | ||
PaymentInformationManagementInterface $subject, | ||
callable $proceed, | ||
$cartId, | ||
PaymentInterface $paymentMethod, | ||
AddressInterface $billingAddress = null | ||
): int { | ||
// Return reserved order id if Rvvup Payment. | ||
if (strpos($paymentMethod->getMethod(), Method::PAYMENT_TITLE_PREFIX) === 0) { | ||
$cart = $this->cartRepository->get($cartId); | ||
$id = $cart->getReservedOrderId(); | ||
if (!$id) { | ||
$cart->reserveOrderId(); | ||
$this->cartRepository->save($cart); | ||
$id = $cart->getReservedOrderId(); | ||
} | ||
return $id; | ||
} | ||
return $proceed($cartId, $paymentMethod, $billingAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Rvvup\Payments\Plugin\Guest; | ||
|
||
use Magento\Checkout\Api\GuestPaymentInformationManagementInterface; | ||
use Magento\Framework\Exception\NoSuchEntityException; | ||
use Magento\Quote\Api\CartRepositoryInterface; | ||
use Magento\Quote\Api\Data\AddressInterface; | ||
use Magento\Quote\Api\Data\PaymentInterface; | ||
use Rvvup\Payments\Gateway\Method; | ||
|
||
class DisableOrderCreation | ||
{ | ||
/** @var CartRepositoryInterface */ | ||
private $cartRepository; | ||
|
||
/** | ||
* @param CartRepositoryInterface $cartRepository | ||
*/ | ||
public function __construct(CartRepositoryInterface $cartRepository) | ||
{ | ||
$this->cartRepository = $cartRepository; | ||
} | ||
|
||
/** | ||
* @param GuestPaymentInformationManagementInterface $subject | ||
* @param callable $proceed | ||
* @param string $cartId | ||
* @param string $email | ||
* @param PaymentInterface $paymentMethod | ||
* @param AddressInterface|null $billingAddress | ||
* @return int | ||
* @throws NoSuchEntityException | ||
*/ | ||
public function aroundSavePaymentInformationAndPlaceOrder( | ||
GuestPaymentInformationManagementInterface $subject, | ||
callable $proceed, | ||
$cartId, | ||
$email, | ||
PaymentInterface $paymentMethod, | ||
AddressInterface $billingAddress = null | ||
): int { | ||
// Return reserved order id if Rvvup Payment. | ||
if (strpos($paymentMethod->getMethod(), Method::PAYMENT_TITLE_PREFIX) === 0) { | ||
$cart = $this->cartRepository->get($cartId); | ||
$id = $cart->getReservedOrderId(); | ||
if (!$id) { | ||
$cart->reserveOrderId(); | ||
$id = $cart->getReservedOrderId(); | ||
$this->cartRepository->save($cart); | ||
} | ||
return $id; | ||
} | ||
return $proceed($cartId, $email, $paymentMethod, $billingAddress); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters