Skip to content

Commit b662cc7

Browse files
Merge branch 'main' into virtual-checkout-tests
2 parents fec849e + 0ac7eed commit b662cc7

File tree

23 files changed

+409
-182
lines changed

23 files changed

+409
-182
lines changed

Controller/Adminhtml/Create/PaymentLink.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public function execute()
5555
{
5656
$amount = (float)$this->_request->getParam('amount');
5757
$amount = (float)number_format($amount, 2, '.', '');
58-
$storeId = $this->_request->getParam('store_id');
58+
$storeId = (string) $this->_request->getParam('store_id');
5959
$orderId = $this->_request->getParam('order_id');
6060
$currencyCode = $this->_request->getParam('currency_code');
6161
$result = $this->resultFactory->create(ResultFactory::TYPE_JSON);

Controller/Adminhtml/Create/VirtualTerminal.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use Magento\Backend\App\Action;
77
use Magento\Backend\App\Action\Context;
88
use Magento\Framework\App\Action\HttpPostActionInterface;
9-
use Magento\Framework\Controller\Result\JsonFactory;
109
use Magento\Framework\Controller\ResultFactory;
1110
use Magento\Store\Model\ScopeInterface;
1211
use Psr\Log\LoggerInterface;
@@ -48,7 +47,7 @@ public function __construct(
4847
public function execute()
4948
{
5049
$amount = $this->_request->getParam('amount');
51-
$storeId = $this->_request->getParam('store_id');
50+
$storeId = (string) $this->_request->getParam('store_id');
5251
$orderId = $this->_request->getParam('order_id');
5352
$currencyCode = $this->_request->getParam('currency_code');
5453
$result = $this->resultFactory->create(ResultFactory::TYPE_JSON);

Controller/Redirect/In.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function execute()
8888
$paymentStatus = $this->request->getParam('payment-status');
8989
$quote = $this->captureService->getQuoteByRvvupId($rvvupId);
9090
$checkoutId = $this->request->getParam('checkout_id');
91-
$storeId = $this->request->getParam('store_id');
91+
$storeId = (string) $this->request->getParam('store_id');
9292
$origin = 'customer-flow';
9393

9494
if ($checkoutId && $storeId) {

Controller/Webhook/Index.php

+11-10
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Psr\Log\LoggerInterface;
2121
use Rvvup\Payments\Exception\PaymentValidationException;
2222
use Rvvup\Payments\Gateway\Method;
23+
use Rvvup\Payments\Model\Config\RvvupConfigurationInterface;
2324
use Rvvup\Payments\Model\ConfigInterface;
2425
use Rvvup\Payments\Model\ProcessRefund\ProcessorPool as RefundPool;
2526
use Rvvup\Payments\Model\Webhook\WebhookEventType;
@@ -35,7 +36,7 @@ class Index implements HttpPostActionInterface, CsrfAwareActionInterface
3536
/** @var RequestInterface */
3637
private $request;
3738

38-
/** @var ConfigInterface */
39+
/** @var RvvupConfigurationInterface */
3940
private $config;
4041

4142
/** @var ResultFactory */
@@ -73,7 +74,7 @@ class Index implements HttpPostActionInterface, CsrfAwareActionInterface
7374
* @param RequestInterface $request
7475
* @param StoreRepositoryInterface $storeRepository
7576
* @param Http $http
76-
* @param ConfigInterface $config
77+
* @param RvvupConfigurationInterface $config
7778
* @param ResultFactory $resultFactory
7879
* @param LoggerInterface $logger
7980
* @param WebhookRepository $webhookRepository
@@ -86,7 +87,7 @@ public function __construct(
8687
RequestInterface $request,
8788
StoreRepositoryInterface $storeRepository,
8889
Http $http,
89-
ConfigInterface $config,
90+
RvvupConfigurationInterface $config,
9091
ResultFactory $resultFactory,
9192
LoggerInterface $logger,
9293
WebhookRepository $webhookRepository,
@@ -131,12 +132,12 @@ public function execute(): ResultInterface
131132
$storeId = $this->getStoreId($quote, $order);
132133

133134
// Merchant ID does not match, no need to process
134-
if ($merchantId !== $this->config->getMerchantId()) {
135+
if ($merchantId !== $this->config->getMerchantId($storeId)) {
135136
return $this->returnSkipResponse(
136137
'Invalid merchant id',
137138
[
138139
'merchant_id' => $merchantId,
139-
'config_merchant_id' => $this->config->getMerchantId(),
140+
'config_merchant_id' => $this->config->getMerchantId($storeId),
140141
'rvvup_id' => $rvvupOrderId
141142
]
142143
);
@@ -279,19 +280,19 @@ private function returnExceptionResponse(): ResultInterface
279280
/**
280281
* @param Quote|null $quote
281282
* @param OrderInterface|null $order
282-
* @return int
283+
* @return string
283284
* @throws NoSuchEntityException
284285
*/
285-
private function getStoreId(?Quote $quote, ?OrderInterface $order): int
286+
private function getStoreId(?Quote $quote, ?OrderInterface $order): string
286287
{
287288
if (isset($quote)) {
288-
return $quote->getStoreId();
289+
return (string) $quote->getStoreId();
289290
}
290291
if (isset($order) && $order->getId()) {
291-
return $order->getStoreId();
292+
return (string) $order->getStoreId();
292293
}
293294

294-
return (int) $this->storeManager->getStore()->getId();
295+
return (string) $this->storeManager->getStore()->getId();
295296
}
296297

297298
private function orderOrQuoteResolver($rvvupOrderId, $paymentLinkId, $checkoutId): array

Cron/Log.php

+8-7
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Magento\Framework\Exception\NoSuchEntityException;
99
use Magento\Framework\Serialize\Serializer\Json;
1010
use Magento\Store\Model\ScopeInterface;
11+
use Rvvup\Payments\Model\Config\RvvupConfigurationInterface;
1112
use Rvvup\Payments\Model\ConfigInterface;
1213
use Rvvup\Payments\Model\Logger;
1314
use Rvvup\Payments\Model\ResourceModel\LogModel\LogCollection;
@@ -26,7 +27,7 @@ class Log
2627
/** @var Curl */
2728
private $curl;
2829

29-
/** @var ConfigInterface */
30+
/** @var RvvupConfigurationInterface */
3031
private $config;
3132

3233
/** @var LogResource */
@@ -39,15 +40,15 @@ class Log
3940
* @param LogCollectionFactory $logCollectionFactory
4041
* @param Json $json
4142
* @param Curl $curl
42-
* @param ConfigInterface $config
43+
* @param RvvupConfigurationInterface $config
4344
* @param Logger $logger
4445
* @param LogResource $resource
4546
*/
4647
public function __construct(
4748
LogCollectionFactory $logCollectionFactory,
4849
Json $json,
4950
Curl $curl,
50-
ConfigInterface $config,
51+
RvvupConfigurationInterface $config,
5152
Logger $logger,
5253
LogResource $resource
5354
) {
@@ -87,7 +88,7 @@ private function processLogs(LogCollection $collection): void
8788
try {
8889
$payload = $item->getData('payload');
8990
$data = $this->json->unserialize($payload);
90-
$storeId = $data['metadata']['magento']['storeId'];
91+
$storeId = (string) $data['metadata']['magento']['storeId'];
9192

9293
if (!isset($batch[$storeId])) {
9394
$batch[$storeId] = [];
@@ -102,7 +103,7 @@ private function processLogs(LogCollection $collection): void
102103
$this->resource->save($item);
103104
}
104105
foreach ($batch as $key => $item) {
105-
$this->notifyRvvup((string) $key, $item);
106+
$this->notifyRvvup($key, $item);
106107
}
107108
}
108109

@@ -114,13 +115,13 @@ private function processLogs(LogCollection $collection): void
114115
private function notifyRvvup(string $storeId, array $data): void
115116
{
116117
try {
117-
$token = $this->config->getJwtConfig(ScopeInterface::SCOPE_STORE, $storeId);
118+
$token = $this->config->getBearerToken($storeId);
118119
$headers = [
119120
'Content-Type: application/json',
120121
'Accept: application/json',
121122
'Authorization: Bearer ' . $token
122123
];
123-
$baseUrl = $this->config->getEndpoint(ScopeInterface::SCOPE_STORE, $storeId);
124+
$baseUrl = $this->config->getGraphQlUrl($storeId);
124125
$url = str_replace('graphql', 'plugin/log', $baseUrl);
125126
$postData = ['headers' => $headers, 'json' => $data];
126127
$this->curl->request(Request::METHOD_POST, $url, $postData);

Gateway/Command/Cancel.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ public function execute(array $commandSubject)
6060
$payment = $quote->getPayment();
6161

6262
$paymentLinkId = $payment->getAdditionalInformation(Method::PAYMENT_LINK_ID);
63-
$storeId = $commandSubject['payment']->getOrder()->getStoreId();
64-
$this->paymentLinkService->cancelPaymentLink((string)$storeId, $paymentLinkId);
63+
$storeId = (string) $commandSubject['payment']->getOrder()->getStoreId();
64+
$this->paymentLinkService->cancelPaymentLink($storeId, $paymentLinkId);
6565
$message = __('Canceled Rvvup Payment Link online');
6666
$orderPayment->getOrder()->addCommentToStatusHistory($message, false, false);
6767

Gateway/Command/CreatePayment.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Magento\Payment\Gateway\CommandInterface;
88
use Magento\Quote\Model\ResourceModel\Quote\Payment;
99
use Rvvup\Payments\Gateway\Method;
10+
use Rvvup\Payments\Model\Config\RvvupConfigurationInterface;
1011
use Rvvup\Payments\Model\ConfigInterface;
1112
use Rvvup\Payments\Model\SdkProxy;
1213

@@ -16,7 +17,7 @@ class CreatePayment implements CommandInterface
1617
private $sdkProxy;
1718

1819
/**
19-
* @var ConfigInterface
20+
* @var RvvupConfigurationInterface
2021
*/
2122
private $config;
2223

@@ -27,12 +28,12 @@ class CreatePayment implements CommandInterface
2728

2829
/**
2930
* @param SdkProxy $sdkProxy
30-
* @param ConfigInterface $config
31+
* @param RvvupConfigurationInterface $config
3132
* @param Payment $paymentResource
3233
*/
3334
public function __construct(
3435
SdkProxy $sdkProxy,
35-
ConfigInterface $config,
36+
RvvupConfigurationInterface $config,
3637
Payment $paymentResource
3738
) {
3839
$this->sdkProxy = $sdkProxy;
@@ -44,6 +45,7 @@ public function execute(array $commandSubject)
4445
{
4546
/** @var \Magento\Sales\Model\Order\Payment $payment */
4647
$payment = $commandSubject['payment'];
48+
$storeId = (string) $commandSubject['storeId'];
4749
$method = str_replace(Method::PAYMENT_TITLE_PREFIX, '', $payment->getMethod());
4850
$orderId = $payment->getAdditionalInformation()[Method::ORDER_ID];
4951
$type = 'STANDARD';
@@ -60,7 +62,7 @@ public function execute(array $commandSubject)
6062
'type' => $type,
6163
'captureType' => 'AUTOMATIC_PLUGIN',
6264
'idempotencyKey' => $idempotencyKey,
63-
'merchantId' => $this->config->getMerchantId()
65+
'merchantId' => $this->config->getMerchantId($storeId)
6466
]
6567
];
6668

Model/CartPaymentActionsGet.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
use Rvvup\Payments\Api\CartPaymentActionsGetInterface;
1717
use Rvvup\Payments\Api\Data\PaymentActionInterface;
1818
use Rvvup\Payments\Api\Data\PaymentActionInterfaceFactory;
19-
use Rvvup\Payments\Gateway\Method;
2019
use Throwable;
2120

2221
class CartPaymentActionsGet implements CartPaymentActionsGetInterface
@@ -87,7 +86,10 @@ private function getPaymentActions(PaymentInterface $payment, Quote $cart, bool
8786
}
8887
$data = ['quote' => $cart, 'validate' => !$expressActions];
8988
$this->commandPool->get('initialize')->execute($data);
90-
$data = $this->commandPool->get('createPayment')->execute(['payment' => $payment]);
89+
$data = $this->commandPool->get('createPayment')->execute([
90+
'payment' => $payment,
91+
'storeId' => (string) $cart->getStoreId()
92+
]);
9193
return $data['data']['paymentCreate']['summary']['paymentActions'];
9294
}
9395

Model/Config.php

-49
Original file line numberDiff line numberDiff line change
@@ -103,55 +103,6 @@ public function getJwtConfig(
103103
return $trimmedValue;
104104
}
105105

106-
/**
107-
* Get the endpoint URL.
108-
*
109-
* @param string $scopeType
110-
* @param string|null $scopeCode
111-
* @return string
112-
* @throws NoSuchEntityException
113-
*/
114-
public function getEndpoint(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): string
115-
{
116-
$jwt = $this->getJwt($scopeType, $scopeCode);
117-
118-
return $jwt === null ? '' : (string) $jwt->aud;
119-
}
120-
121-
/**
122-
* Get the Merchant ID.
123-
*
124-
* @param string $scopeType
125-
* @param string|null $scopeCode
126-
* @return string
127-
* @throws NoSuchEntityException
128-
*/
129-
public function getMerchantId(string $scopeType = ScopeInterface::SCOPE_STORE, string $scopeCode = null): string
130-
{
131-
$jwt = $this->getJwt($scopeType, $scopeCode);
132-
133-
return $jwt === null ? '' : (string) $jwt->merchantId;
134-
}
135-
136-
/**
137-
* Get the Authorization Token.
138-
*
139-
* @param string $scopeType
140-
* @param string|null $scope
141-
* @return string
142-
* @throws NoSuchEntityException
143-
*/
144-
public function getAuthToken(string $scopeType = ScopeInterface::SCOPE_STORE, string $scope = null): string
145-
{
146-
$jwt = $this->getJwt($scopeType, $scope);
147-
148-
if ($jwt === null) {
149-
return '';
150-
}
151-
152-
return base64_encode($jwt->username . ':' . $jwt->password);
153-
}
154-
155106
/**
156107
* Check whether debug mode is enabled.
157108
*

0 commit comments

Comments
 (0)