Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 'origin' field to Rvvup logs #117

Merged
merged 8 commits into from
May 9, 2024
Merged
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
4 changes: 3 additions & 1 deletion Api/Data/ValidationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ interface ValidationInterface
* @param string $lastTransactionId
* @param string|null $rvvupId
* @param string|null $paymentStatus
* @param string|null $origin
* @return ValidationInterface
*/
public function validate(
Quote &$quote,
string &$lastTransactionId,
string $rvvupId = null,
string $paymentStatus = null
string $paymentStatus = null,
string $origin = null
): ValidationInterface;
}
37 changes: 30 additions & 7 deletions Controller/Redirect/In.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function execute()
$rvvupId = $this->request->getParam('rvvup-order-id');
$paymentStatus = $this->request->getParam('payment-status');
$quote = $this->captureService->getQuoteByRvvupId($rvvupId);
$origin = 'customer-flow';

if (!$quote) {
$quote = $this->checkoutSession->getQuote();
Expand All @@ -89,7 +90,13 @@ public function execute()
$rvvupPaymentId = $payment->getAdditionalInformation(Method::PAYMENT_ID);
$lastTransactionId = (string)$payment->getAdditionalInformation(Method::TRANSACTION_ID);

$validate = $this->captureService->validate($quote, $lastTransactionId, $rvvupId, $paymentStatus);
$validate = $this->captureService->validate(
$quote,
$lastTransactionId,
$rvvupId,
$paymentStatus,
$origin
);

if (!$validate->getIsValid()) {
if ($validate->getRestoreQuote()) {
Expand All @@ -113,14 +120,19 @@ public function execute()
$this->checkoutSession->setLastQuoteId($quote->getId());
$this->checkoutSession->setLastOrderId($quote->getReservedOrderId());
$this->checkoutSession->setLastRealOrderId($quote->getReservedOrderId());
return $this->resultService->processOrderResult(null, $rvvupId);
return $this->resultService->processOrderResult(null, $rvvupId, $origin);
}
return $this->resultService->processOrderResult((string)$quote->getReservedOrderId(), $rvvupId, true);
return $this->resultService->processOrderResult(
(string)$quote->getReservedOrderId(),
$rvvupId,
$origin,
true
);
}
}

$this->captureService->setCheckoutMethod($quote);
$validation = $this->captureService->createOrder($rvvupId, $quote);
$validation = $this->captureService->createOrder($rvvupId, $quote, $origin);
$orderId = $validation->getOrderId();
$alreadyExists = $validation->getAlreadyExists();

Expand All @@ -129,7 +141,12 @@ public function execute()
$this->checkoutSession->setLastQuoteId($quote->getId());
$this->checkoutSession->setLastOrderId($quote->getReservedOrderId());
$this->checkoutSession->setLastRealOrderId($quote->getReservedOrderId());
return $this->resultService->processOrderResult((string)$orderId, $rvvupId, true);
return $this->resultService->processOrderResult(
(string)$orderId,
$rvvupId,
$origin,
true
);
}

if (!$orderId) {
Expand All @@ -143,7 +160,13 @@ public function execute()
return $this->redirectToCart();
}

if (!$this->captureService->paymentCapture($payment, $lastTransactionId, $rvvupPaymentId, $rvvupId)) {
if (!$this->captureService->paymentCapture(
$payment,
$lastTransactionId,
$rvvupPaymentId,
$rvvupId,
$origin
)) {
$this->messageManager->addErrorMessage(
__(
'An error occurred while capturing your order (ID %1). Please contact us.',
Expand All @@ -153,7 +176,7 @@ public function execute()
return $this->redirectToCart();
}

return $this->resultService->processOrderResult((string)$orderId, $rvvupId);
return $this->resultService->processOrderResult((string)$orderId, $rvvupId, $origin);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion Controller/Webhook/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public function execute(): ResultInterface
'payment_id' => $paymentId,
'event_type' => $eventType,
'store_id' => $this->getStoreId(),
'payment_link_id' => $paymentLinkId
'payment_link_id' => $paymentLinkId,
'origin' => 'webhook'
];

if ($payload['event_type'] == Complete::TYPE) {
Expand Down
26 changes: 20 additions & 6 deletions Model/Data/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,20 @@ public function __construct(
parent::__construct($data);
}

/**
* @param Quote $quote
* @param string $lastTransactionId
* @param string|null $rvvupId
* @param string|null $paymentStatus
* @param string|null $origin
* @return ValidationInterface
*/
public function validate(
Quote &$quote,
string &$lastTransactionId,
string $rvvupId = null,
string $paymentStatus = null
string $paymentStatus = null,
string $origin = null
): ValidationInterface {
$data = $this->getDefaultData();

Expand All @@ -57,7 +66,8 @@ public function validate(
'No Rvvup Order ID provided',
null,
null,
$lastTransactionId
$lastTransactionId,
$origin
);

$data[ValidationInterface::IS_VALID] = false;
Expand Down Expand Up @@ -88,7 +98,8 @@ public function validate(
$message,
$rvvupId,
$lastTransactionId,
$quote->getReservedOrderId() ?? null
$quote->getReservedOrderId() ?? null,
$origin
);

$this->setValidationData($data);
Expand All @@ -104,7 +115,8 @@ public function validate(
'Missing quote for Rvvup payment',
$message,
$rvvupId,
$lastTransactionId
$lastTransactionId,
$origin
);

$data[ValidationInterface::IS_VALID] = false;
Expand All @@ -124,7 +136,8 @@ public function validate(
null,
$rvvupId,
$lastTransactionId,
$quote->getReservedOrderId() ?? null
$quote->getReservedOrderId() ?? null,
$origin
);

$message = __(
Expand All @@ -144,7 +157,8 @@ public function validate(
null,
$rvvupId,
$lastTransactionId,
$quote->getReservedOrderId() ?? null
$quote->getReservedOrderId() ?? null,
$origin
);
$message = __(
'This checkout cannot complete, a new cart was opened in another tab. ' . $errorId
Expand Down
22 changes: 17 additions & 5 deletions Model/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,23 +48,32 @@ public function __construct(
* @param string|null $rvvupOrderId
* @param string|null $rvvupPaymentId
* @param string|null $magentoOrderId
* @param string|null $origin
* @return bool
*/
public function addRvvupError(
string $message,
?string $cause = null,
?string $rvvupOrderId = null,
?string $rvvupPaymentId = null,
?string $magentoOrderId = null
?string $magentoOrderId = null,
?string $origin = null
) {
$result = $this->addRecord(
static::ERROR,
$message,
[$cause, $rvvupOrderId, $rvvupPaymentId, $magentoOrderId]
[$cause, $rvvupOrderId, $rvvupPaymentId, $magentoOrderId, $origin]
);

try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$data = $this->prepareData($message, $cause, $rvvupOrderId, $rvvupPaymentId, $magentoOrderId);

should also include $origin, as its not writing that currently.

$data = $this->prepareData($message, $cause, $rvvupOrderId, $rvvupPaymentId, $magentoOrderId);
$data = $this->prepareData(
$message,
$cause,
$rvvupOrderId,
$rvvupPaymentId,
$magentoOrderId,
$origin
);

/** @var LogModel $model */
$model = $this->modelFactory->create();
Expand All @@ -84,6 +93,7 @@ public function addRvvupError(
* @param string|null $rvvupOrderId
* @param string|null $rvvupPaymentId
* @param string|null $magentoOrderId
* @param string|null $origin
* @return array
* @throws NoSuchEntityException
*/
Expand All @@ -92,7 +102,8 @@ private function prepareData(
?string $cause = null,
?string $rvvupOrderId = null,
?string $rvvupPaymentId = null,
?string $magentoOrderId = null
?string $magentoOrderId = null,
?string $origin = null
): array {

$payload = json_encode([
Expand All @@ -103,7 +114,8 @@ private function prepareData(
'rvvupOrderId' => $rvvupOrderId,
'magento' => [
'storeId' => $this->storeManager->getStore()->getId(),
'orderId' => $magentoOrderId
'orderId' => $magentoOrderId,
'origin' => $origin
]
],
'cause' => $cause
Expand Down
5 changes: 3 additions & 2 deletions Model/ProcessOrder/Cancel.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,13 @@ public function __construct(
}

/**
* @param \Magento\Sales\Api\Data\OrderInterface $order
* @param OrderInterface $order
* @param array $rvvupData
* @param string $origin
* @return \Rvvup\Payments\Api\Data\ProcessOrderResultInterface
* @throws \Rvvup\Payments\Exception\PaymentValidationException
*/
public function execute(OrderInterface $order, array $rvvupData): ProcessOrderResultInterface
public function execute(OrderInterface $order, array $rvvupData, string $origin): ProcessOrderResultInterface
{
$this->validateIdExists($rvvupData);
$this->validateStatusAllowed($rvvupData['payments'][0], $this->allowedStatuses);
Expand Down
3 changes: 2 additions & 1 deletion Model/ProcessOrder/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ public function __construct(
/**
* @param OrderInterface $order
* @param array $rvvupData
* @param string $origin
* @return ProcessOrderResultInterface
* @throws PaymentValidationException
*/
public function execute(OrderInterface $order, array $rvvupData): ProcessOrderResultInterface
public function execute(OrderInterface $order, array $rvvupData, string $origin): ProcessOrderResultInterface
{
if (strpos($order->getPayment()->getMethod(), RvvupConfigProvider::CODE) !== 0) {
throw new PaymentValidationException(__('Order is not paid via Rvvup Payment Link'));
Expand Down
6 changes: 4 additions & 2 deletions Model/ProcessOrder/Complete.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,11 @@ public function __construct(
/**
* @param OrderInterface $order
* @param array $rvvupData
* @param string $origin
* @return ProcessOrderResultInterface
* @throws PaymentValidationException
*/
public function execute(OrderInterface $order, array $rvvupData): ProcessOrderResultInterface
public function execute(OrderInterface $order, array $rvvupData, string $origin): ProcessOrderResultInterface
{
if ($order->getPayment() === null
|| strpos($order->getPayment()->getMethod(), Method::PAYMENT_TITLE_PREFIX) !== 0
Expand Down Expand Up @@ -134,7 +135,8 @@ public function execute(OrderInterface $order, array $rvvupData): ProcessOrderRe
$e->getMessage(),
$rvvupData['id'],
$rvvupData['payments'][0]['id'],
$order->getId()
$order->getId(),
$origin
);

$processOrderResult->setResultType(ProcessOrderResultInterface::RESULT_TYPE_ERROR);
Expand Down
6 changes: 4 additions & 2 deletions Model/ProcessOrder/Processing.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,11 @@ public function __construct(
*
* @param OrderInterface $order
* @param array $rvvupData
* @param string $origin
* @return ProcessOrderResultInterface
* @throws PaymentValidationException
*/
public function execute(OrderInterface $order, array $rvvupData): ProcessOrderResultInterface
public function execute(OrderInterface $order, array $rvvupData, string $origin): ProcessOrderResultInterface
{
/** @var \Rvvup\Payments\Api\Data\ProcessOrderResultInterface $processOrderResult */
$processOrderResult = $this->processOrderResultFactory->create();
Expand Down Expand Up @@ -121,7 +122,8 @@ public function execute(OrderInterface $order, array $rvvupData): ProcessOrderRe
$e->getMessage(),
$rvvupData['id'],
$rvvupData['payments'][0]['id'],
$order->getId()
$order->getId(),
$origin
);

$processOrderResult->setResultType(ProcessOrderResultInterface::RESULT_TYPE_ERROR);
Expand Down
3 changes: 2 additions & 1 deletion Model/ProcessOrder/ProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ interface ProcessorInterface
/**
* @param OrderInterface $order
* @param array $rvvupData
* @param string $origin
* @return ProcessOrderResultInterface
*/
public function execute(OrderInterface $order, array $rvvupData): ProcessOrderResultInterface;
public function execute(OrderInterface $order, array $rvvupData, string $origin): ProcessOrderResultInterface;
}
3 changes: 2 additions & 1 deletion Model/ProcessOrder/UpdateOrder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@ public function __construct(
/**
* @param OrderInterface $order
* @param array $rvvupData
* @param string $origin
* @return ProcessOrderResultInterface
* @throws JsonException
* @throws NoSuchEntityException
*/
public function execute(OrderInterface $order, array $rvvupData): ProcessOrderResultInterface
public function execute(OrderInterface $order, array $rvvupData, string $origin): ProcessOrderResultInterface
{
$processOrderResult = $this->processOrderResultFactory->create();
$processOrderResult->setResultType(ProcessOrderResultInterface::RESULT_TYPE_ERROR);
Expand Down
Loading
Loading